Results 1 to 6 of 6
  1. #1
    ras_oscar is offline Member
    Join Date
    Jun 2013
    Posts
    60
    Rep Power
    0

    Default 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 line createAndShowGUI is flagged as an unfound symbol.

    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?

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default 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,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    TrolleY is offline Member
    Join Date
    Sep 2013
    Posts
    5
    Rep Power
    0

    Default 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);
    }
    }
    but in my opinion better make own class which will extend JFrame

  4. #4
    ras_oscar is offline Member
    Join Date
    Jun 2013
    Posts
    60
    Rep Power
    0

    Default 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); 
                     
                     
            }
        }); 
    }
    There are no compiler flags, but when I run it in debugger, the line counter steps from the line that begins javax.swing.SwingUtilities.....
    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.

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default 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,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  6. #6
    ras_oscar is offline Member
    Join Date
    Jun 2013
    Posts
    60
    Rep Power
    0

    Default Re: trying to show application's gui

    Itworkeditworkeditworkeditworkeditworked!!! Jiggled the code around, looked at the online examples and prayed to the java gods. Now to figure out what all these statements mean!!!

Similar Threads

  1. Replies: 0
    Last Post: 04-08-2013, 10:48 PM
  2. Replies: 3
    Last Post: 05-27-2010, 11:54 AM
  3. Replies: 3
    Last Post: 12-04-2009, 01:10 PM
  4. Replies: 1
    Last Post: 08-05-2009, 03:43 AM
  5. netbeans 6.0 not show commpunent or show blank page
    By fahimaamir in forum NetBeans
    Replies: 1
    Last Post: 01-26-2008, 07:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •