File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Help with swing? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Help with swing?" Watch "Help with swing?" New topic

Help with swing?

ajay smith

Joined: Feb 02, 2013
Posts: 11
Literally just starting swing. From this code, I keep getting an error saying "cannot find ShowGridLayout", but the method is right there. HELP PLEASE!?

Java code:
Joe Areeda
Ranch Hand

Joined: Apr 15, 2011
Posts: 331

The problem is that main is a static member so it doesn't have a "this" pointer to call regular member functions.

You probably want instantiate swingtempate and call it from the object eg:

In order to show the JFrame you will need to create an object.

Since this is the beginning Java: remember a Class defines the structure but only static members and static fields are available. An object is an instantiation of a class so all the public and private members are available (as appropriate).


It's not what your program can do, it's what your users do with the program.
Abhishk Singh
Ranch Hand

Joined: Aug 19, 2010
Posts: 45

The issue here is not swing. In Java we initiate instances of a class using the "new" keyword as in the following:
<NameOfClass> referenceNameOfVariable=new <NameOfClass>()

and call the methods of the class on this referenceVariable:
referenceNameOfVariable.methodName(comma separated list of method arguments)

In the code excerpt shared by you, on line no 21 , the statement written is:
ShowGridLayout frame = new ShowGridLayout();

Here, the name of class used is: ShowGridLayout . As this is not a class but a method name only so the compiler is giving error saying "cannot find ShowGridLayout".
Use the name of your class(which is swingtempate) in the above statement
I agree. Here's the link:
subject: Help with swing?
It's not a secret anymore!