Jump to content

implementing GUI in main class


Recommended Posts

Posted (edited)

remove 

 
        public static void main(String[] args) {
                        GUI window = new GUI();
                        window.frame.setVisible(true);
        }

in the main class create a simple instance of the gui

GUI window = new GUI();

then in the onstart you make it visible

window.frame.setVisible(true);

and incase you are waiting for gui to end before you continue with the script. 

 

in the onloop add a simple isVisible()  boolean check

Edited by josedpay
  • Like 1
Posted (edited)

no error at all

the script doesnt start when i click start, even the paint doesnt show up

unless i undo what ive added sad.png

ok so keep this in the onStart

 GUI window = new GUI();

Your gui class extend JFrame so use it. What you did was created a new jFrame instance instead of using the classes JFrame. So delete

frame = new JFrame();
private JFrame frame;

you will get a few error with "frame." simply remove it and it should be good.

 

finally at the end of gui constructor the last line should be 

Gui() {
//stuff
setVisible(true);
}

no need for setVisible in the onstart since its in the constructor 

Edited by josedpay
Posted

ok so keep this in the onStart

 GUI window = new GUI();

Your gui class extend JFrame so use it. What you did was created a new jFrame instance instead of using the classes JFrame. So delete

frame = new JFrame();
private JFrame frame;

you will get a few error with "frame." simply remove it and it should be good.

 

finally at the end of gui constructor the last line should be 

Gui() {
//stuff
setVisible(true);
}

no need for setVisible in the onstart since its in the constructor 

 

still doesnt work :(

and the script doesnt startup

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...