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 why use static method in creating gui Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "why use static method in creating gui" Watch "why use static method in creating gui" New topic

why use static method in creating gui

amit sharma
Ranch Hand

Joined: Jul 19, 2006
Posts: 129
I am to new to swing.When i search tutorial for swing i see that most of them create gui in static method .What is the purpose of it .When i make gui in static method i am not able to add listener for it.Can anyone please tell me what is the preferred way of developing desktop application using swing.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

I assume you are talking about something like this:

The reason that createAndShowGUI() is static is because it's being called from a static method, main(String[] args). You can not call non-static methods from a static method, so createAndShowGUI() has to be static.

GenRocket - Experts at Building Test Data
I agree. Here's the link:
subject: why use static method in creating gui
It's not a secret anymore!