This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2021/5/17

what do I do to get my gui to pop up?

1
2
divinity divinity

2021/5/17

#
this is what i have tried and i havent been able to get it to pop up
  public static void main(String[]args){
            
         }
          public void run(){
            JFrame frame = new JFrame("Test Frame");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            
            frame.setVisible(true);
             
        }
        
danpost danpost

2021/5/17

#
Where are you calling the run method from -- or, are you even calling it?
divinity divinity

2021/5/17

#
hi danpost I had it but had it outside of the main method. the thing when I had it and the code above in the main method, was getting a set of errors and still getting the error, hence the reason why i remove it from the main method and just put the codes in the main method.
public static void main(String[]args){
           
             public.run();
            JFrame frame = new JFrame("Test Frame");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
            
            
         }
         
you see the errors that I am getting, so I am confused it is to be in the main method and another thing when I took it out of the main methods all the errors are gone so i am doing something wrong they
danpost danpost

2021/5/17

#
Try removing line 3.
divinity divinity

2021/5/17

#
hi danpost I removed line 3 and it still not running, ah mean popup
danpost danpost

2021/5/17

#
divinity wrote...
I removed line 3 and it still not running, ah mean popup
I tested it and the frame appeared for me. It was mostly just the title bar with the 3 buttons (hide/show, minimize/maximize and close). The content frame was just a thin black line as there was zero content. At any rate, the code, lines 4 thru 7, works.
divinity divinity

2021/5/19

#
i got it to run but it is running a blank frame. when i right click and press run it running but when i press the run button it is not running.
danpost danpost

2021/5/19

#
divinity wrote...
i got it to run but it is running a blank frame. when i right click and press run it running but when i press the run button it is not running.
What IDE are you using? What are you wanting to have in your "blank frame"?
divinity divinity

2021/5/20

#
am using netbeans. i was designing a subway menu
divinity divinity

2021/5/20

#
I am trying something else and i am getting a set of errors.
public class Subway_Menu extends javax.swing.JPanel {

   
    public static void main(String[]args) throws InterruptedException, InvocationTargetException{
        
        try{
            
            SwingUtilities.invokeAndWait(new Runnable(){
             public void run(){
              JFrame frame = new JFrame("Test Frame");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setVisible(true);
            
              )};   [code]public Subway_Menu() {
        initComponents();
    }
}Catch(Exception e){ } the error that am getting is illegal start of an expression and the try is not recognizing the catch even thou it is there
danpost danpost

2021/5/21

#
You have a constructor to the class stuck in there where it doesn't belong and the try-catch codes are not within a declared method block.
divinity divinity

2021/5/21

#
i remove the constructor and i literally gotten a set of errors
divinity divinity

2021/5/21

#
   
        try {

          SwingUtilities.invokeAndWait(new Runnable() { this line of code here the error here is telling to implement all abstract methid (but what will that do)

            JFrame frame = new JFrame("Test Frame");the error on this line is: identifier expected

                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ther error here is the same above, identified expected ( what does it mean)

                frame.setVisible(true);          the same with this line of code, same above error         

                
            });
                
            
    } catch (Exception e) {
    }
       
danpost danpost

2021/5/21

#
danpost wrote...
the try-catch codes are not within a declared method block.
??? I am not sure what I was seeing. ??? Put code back in main method. (Sorry)
danpost danpost

2021/5/21

#
Try this:
public static void main(String[] args) throws InterruptedException, InvocationTargetException
{
    try
    {
        SwingUtilities.invokeAndWait(new Runnable()
        {
            public void run()
            {
                JFrame frame = new JFrame("Test Frame");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);
            }
        });
    } catch (Exception e) {}
}
I think your bracketing was off.
There are more replies on the next page.
1
2