This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Help with swing?" Watch "Help with swing?" New topic
Author

Help with swing?

ajay smith
Greenhorn

Joined: Feb 02, 2013
Posts: 9
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: 307
    
    2

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).

Joe


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: 43
Hi,

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Help with swing?
 
Similar Threads
Help with actionlisteners on a button.
JTextArea Problems
JButton Problem ?
Problem wth ActionListener Interface
The INSERT INTO statement contains the following unknown field name: 'OPANo'.