Jump to content

GUI Help


Recommended Posts

Posted (edited)

Hey everyone, I was wondering if some of you could help me out with something that is probably easy.


I have basic knowledge of Java, and GUI making, etc Swing, JavaFX through Eclipse's window builder and such.


Now, probably about 99% of the scripts have a GUI with options and such, what I'm wondering is how would I would incorporate actions; E.G, I have a start button on my GUI, after all the  settings are to my liking, I'd click start to obviously start the script.


I realize the actionhandler method(s) are used there, etc. But would I need to make the GUI class within the, say, TestMiner.java (The main file of the script extending the Script class of the API). Would that allow me to start the script when the handler is called when the Start button is clicked?


Or if someone could provide small snippet(s) to this, that would be great. Or, if you need a better explanation, I'd be happy to provide another one.


Edited by Deceiver
Posted (edited)

I go like this:

boolean GUI_COMPLETE = false;
exampleGUI gui = new exampleGUI();

@Override
	public void onStart() {
		gui.setVisible(true);

	}

@Override
	public int onLoop() throws InterruptedException {
		if (GUI_COMPLETE) {
			//normal script loop;
		}
		return 50; // The amount of time in milliseconds before the loop
						// starts
						// over
	}

public class exampleGUI extends JFrame {
//gui code with an actionlistener on the start button which sets GUI_COMPLETE to true, and disposes the GUI.
}


	
Edited by jacksonadams861
  • Like 1
Posted

Probably neatest to have your entire GUI code in a seperate class. A simple way you can do it is using an actionlistener for your start button, reading the current options on the UI and assigning them to variables. Then directly statically (i know, ew, but ye) modifying the main classes set variables for that bot instance to reflect what was chosen in the UI. let me kno if i didnt answer ur question :)

  • Like 1
Posted

 

I go like this:

boolean GUI_COMPLETE = false;
exampleGUI gui = new exampleGUI();

@Override
	public void onStart() {
		gui.setVisible(true);

	}

@Override
	public int onLoop() throws InterruptedException {
		if (GUI_COMPLETE) {
			//normal script loop;
		}
		return 50; // The amount of time in milliseconds before the loop
						// starts
						// over
	}

public class exampleGUI extends JFrame {
//gui code with an actionlistener on the start button which sets GUI_COMPLETE to true, and disposes the GUI.
}


	

 

Thanks.

Probably neatest to have your entire GUI code in a seperate class. A simple way you can do it is using an actionlistener for your start button, reading the current options on the UI and assigning them to variables. Then directly statically (i know, ew, but ye) modifying the main classes set variables for that bot instance to reflect what was chosen in the UI. let me kno if i didnt answer ur question smile.png

 

Yeah, I'd prefer a separate class for it as well, and I'll look into that, thanks.

Posted

 

I go like this:

boolean GUI_COMPLETE = false;
exampleGUI gui = new exampleGUI();

@Override
	public void onStart() {
		gui.setVisible(true);

	}

@Override
	public int onLoop() throws InterruptedException {
		if (GUI_COMPLETE) {
			//normal script loop;
		}
		return 50; // The amount of time in milliseconds before the loop
						// starts
						// over
	}

public class exampleGUI extends JFrame {
//gui code with an actionlistener on the start button which sets GUI_COMPLETE to true, and disposes the GUI.
}


	

 

This isnt exactly the best option either, you don't "need" to instantiate the GUI like that at all really, you can just put new GUI(this), and from within the GUI's constructor set it to visible.

 

Should also be invoked, not just initialized in the onStart

  • Like 1

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