Jump to content

How to JFrame?


Recommended Posts

Posted

Hi guys, I was trying to make a menu where users select what scenarios to include from my script and was told to use JFrame. I've watched some tutorials on it but I can't figure out how to include it in my script. Any help to get out there? :-)

 

This is what I have so far, btw, and it clearly doesn't work xD

 

public class SlayerBot extends (Script && JFrame) {

     private Frame() {

        //Code

     }

}

Posted (edited)

Gui class:

public class Gui extends JFrame { 
    public Gui() { //constructor
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 
        //stick your Gui code in here for the jframe. You can use windowbuilder plugin for eclipse to design it a bit simpler. 
    } 
}

Main class:

private Gui GUI;

@Override
public void onStart() {
    GUI = new Gui();
    GUI.setVisible(true);
}

merry christmas

apa

Edited by Apaec
Posted

Gui class:

public class Gui extends JFrame { 
    public Gui() { //constructor
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 
        //stick your Gui code in here for the jframe. You can use windowbuilder plugin for eclipse to design it a bit simpler. 
    } 
}

Main class:

private Gui GUI;

@Override
public void onStart() {
    GUI = new Gui();
    GUI.setVisible(true);
}

merry christmas

apa

 

It's Christmas in August!

  • Like 1
Posted (edited)

Hi guys, I was trying to make a menu where users select what scenarios to include from my script and was told to use JFrame. I've watched some tutorials on it but I can't figure out how to include it in my script. Any help to get out there? :-)

 

This is what I have so far, btw, and it clearly doesn't work xD

 

public class SlayerBot extends (Script && JFrame) {

     private Frame() {

        //Code

     }

}

 

code your gui in a seperate class (so that the gui class itself extends JFrame)

 

then you declare a new instance in your slayerbot class

 

the way Apaec had it written

Edited by RickyD
Posted

Alright, so I've figured out that making this using Window Builder is actually pretty simple. I just still can't figure out how to get the two classes to work together. I get the onStart-code calling the GUI but how do I make the GUI change variables in my main script? Or should I declare the variables in the GUI and then pass them to my SlayerBot-class? There are no "classes" in C so this concept is not familiar to me :-P

:-P

Posted (edited)

Alright, so I've figured out that making this using Window Builder is actually pretty simple. I just still can't figure out how to get the two classes to work together. I get the onStart-code calling the GUI but how do I make the GUI change variables in my main script? Or should I declare the variables in the GUI and then pass them to my SlayerBot-class? There are no "classes" in C so this concept is not familiar to me :-P

:-P

struct GUI
{
    int valueA;
    int valueB;
};  

int main() // Your script
{
struct GUI MyGUI;
// > Load GUI and set values here <

int valueA = MyGUI.valueA;
int valueB = MyGUI.valueB;

return 0;
}

Think of a class as a struct with more functionality (crude definition but might help you).

Edited by Botre

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...