I often use JFrames, and because they are applications, they obviously need a
public static void main(String[] args)
method. They also need the line in main()
myJFrame g = new myJFrame();
In eclipse, I get a warning on variable g: “The local variable g is never read”, but if I omit that line, the program won’t run. Why do I need that line, and if g is essential, why is there a warning on it?
The warning means that you declare a local variable/pointer (called g in this case) but never actually utilize it anywhere in your code. With the warning the program should run fine, but you have a extra “pointer” to your JFrame that’s never used.
If you want to access your JFrame from the method were you called
myJFrame g = new myJFrame();you should keep it that way.Otherwise
new myJFrame();will suffice.