Jump to content

GUI help


Recommended Posts

Posted

how do I make sure that the user have selected an item? cuz if i just do sleep it may not work some times...

 

Within GUI (textbox as an example)

if (textBox.getText().isEmpty()) {
    JOptionPane.showMessageDialog(null, "You must fill out this text box first!");
    return;
}

The return; will stop execution of the method. I personally have a boolean in my main class, guiWait, which I then set from true to false when the GUI has applied the settings. I do something like this:

GUI g = new GUI();
public static boolean guiWait = true;
onStart() {
g.setVisible(true);
while (guiWait) { sleep(400); }
}

//GUI

//Button actionPerformed
if (conditionsMet) {
    ArbitraryScriptClass.guiWait = false;
}
else {
    JOptionPane.showMessageDialog(null, "You must select a preset or define a monster first!");
}
  • Like 1
Posted

to have the GUI settings saved to your main class, you should put an action listener on your start button. Google how to do this , or in window builder right click the component and go action>actionPerformed

then just statically send your GUI variables to your desired location before putting a setVisible(false) in the action listener for the start button.

Not a neat way of doing it but does the job just fine and is pretty basic

apa

Posted

to have the GUI settings saved to your main class, you should put an action listener on your start button. Google how to do this , or in window builder right click the component and go action>actionPerformed

then just statically send your GUI variables to your desired location before putting a setVisible(false) in the action listener for the start button.

Not a neat way of doing it but does the job just fine and is pretty basic

apa

Why would you make the gui invisible rather than closing it? Doesn't make sense.

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