I want to add an Image to the JFrame, the add( ) method is generating an error which says “cannot find symbol: method add(JLabel)” … How can I fix that?
** I still haven’t called the ImageLoading( ) method from the main method.
import javax.swing.*;
public class NetworkingGame {
NetworkingGame(){
JFrame jfrm = new JFrame("Angry Painters");
jfrm.setSize(800, 480);
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jfrm.setVisible(true);
}
public void ImageLoading(){
ImageIcon i = new ImageIcon("angry-painters.jpg");
JLabel jl = new JLabel(i);
add(jl); //The error is in this line
}
public static void main(String[] args) throws Exception{
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run(){
new NetworkingGame();
}
});
}
}
Visibility of
JFrame jfrmis limited by constructor ofNetworkingGame. Soaddmethod does not exist inNetworkingGame. Make yourJFramemember ofNetworkingGame.