This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with swing?

 
ajay smith
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 331
2
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Abhishk Singh
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic