Jump to content

GUI help


HunterRS

Recommended Posts

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

While this is very common, you WILL get laughed if you do this in any sort of formal setting (School assignment, work, etc).

 

The proper way would be to implement an Interface that serves as a callback for when the gui is done.

 

:^)

 

 

p.s. my java knowlage is extremely basic as you can understand.

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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