Results 1 to 6 of 6
Thread: trying to show application's gui
- 09-22-2013, 05:26 PM #1
Member
- Join Date
- Jun 2013
- Posts
- 60
- Rep Power
- 0
trying to show application's gui
I am having difficulties in getting my application to show the GUI I have created.
The GUI lives in a class Beer_Main_Panel. The entire application lives within a single package
I have created a main function shown below, pared down to just the issue at hand
Java Code:import javax.swing.*; public class Beer { public static void main(String[] args) throws IOException { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }
The sample I swiped the invokeLater() call from showed the main() function and the swing components in the same class. My swing components live within a different class in the same package. Do I need to do something different to tell the compiler where the swing components live?
- 09-22-2013, 07:48 PM #2
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: trying to show application's gui
You didn't show enough of your code. Where and how is createAndShowGUI() defined?
Is it static? Is it in another class that needs to be instantiated?
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 09-22-2013, 07:54 PM #3
Member
- Join Date
- Sep 2013
- Posts
- 5
- Rep Power
- 0
Re: trying to show application's gui
I think u wanted to do sth like this:
Java Code:import javax.swing.*; public class Beer { public static void main(String[] args) throws IOException { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } public static void createAndShowGUI() { // TODO some stuff for examlpe JFrame frame = new JFrame(); frame.setVisible(true); } }
- 09-23-2013, 03:34 AM #4
Member
- Join Date
- Jun 2013
- Posts
- 60
- Rep Power
- 0
Re: trying to show application's gui
I had assumed createAndShowGUI was a Java function, since it is described in the Java docs.
Beer-Main_Panel extends JPanel and has a public constructor beer_main_panel() which calls the private function initComponents() so I plugged that in to the code in lieu of createAndShowGUI above to result in this:
Java Code:public static void main(String[] args) throws IOException { javax.swing.SwingUtilities.invokeLater(new Runnable() { @Override public void run() { beer_main_panel frame = new beer_main_panel(); frame.setVisible(true); } }); }
to the closing brace and then falls off the end of the main() function. Nothing is displayed. When I put a dummy statement just before the closing brace, it falls to that first, seemingly skipping right over the 4 lines from @Override... to frame....
I'm feeling a little dense at the moment. Probably missing something stupid.
- 09-23-2013, 03:46 AM #5
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: trying to show application's gui
As far as I know, createAndShowGUI is a static method which is used (and declared) in some of the examples in the Java Tutorials. You could certainly copy and paste it if you want.
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 09-25-2013, 04:44 AM #6
Member
- Join Date
- Jun 2013
- Posts
- 60
- Rep Power
- 0
Similar Threads
-
Enterprise Application Project problem to return object to web application
By Kkenjoy in forum New To JavaReplies: 0Last Post: 04-08-2013, 10:48 PM -
how to show web browser in mobile app or is it possible to show it in textArea
By Basit781 in forum CLDC and MIDPReplies: 3Last Post: 05-27-2010, 11:54 AM -
Help in converting Java application to desktop application in Netbeans
By realahmed8 in forum AWT / SwingReplies: 3Last Post: 12-04-2009, 01:10 PM -
Responding back to application's HTTP POST values with application/x-www-form-urlenc
By jeremy.wilson in forum New To JavaReplies: 1Last Post: 08-05-2009, 03:43 AM -
netbeans 6.0 not show commpunent or show blank page
By fahimaamir in forum NetBeansReplies: 1Last Post: 01-26-2008, 07:20 AM
Bookmarks