I have two queries.
Why don't Swing methods work in a static method ?
Why creating an instance of the application's frame class help ?
Campbell Ritchie wrote:Swing methods are intended to run on an object. If you have two JButtons, how would a static method know which button has been pressed? So, as is normal with object design, most members of Swing components are instance members.
Oh good point. Thanks alot.
On a second note,
GraphUI2 object can be created without declaring beforehand because the object is created in the same class itself ?
By the way: the correct Swing way to create an app is by starting the EDT thread: details here.
But I am a little confused over this.
is the creation of an instance of a class. And
contains all the details like setSize etc.
Am I right ?
Creating the instance of a class in this manner is not needed in this context right ?
I have a previous exercise in which I created instances of a class in this manner, that's why I am confused with the code also creates a class as well, but without variables ?
It doesn't have to be assigned to a variable. In this case, it is simply discarded, since all code of interest is in that constructor. In other cases, the value may be used as a parameter to a method, as in:Here too the 'new JLabel' isn't assigned to a variable reference.