Jump to content

GUI Help


Deceiver

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

 

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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