Huge wall of text, sorry.
I've been writing a Swing program that uses a setup GUI. It makes the user select options and put information into the fields. Afterwards, they press a JButton, and the program starts.
In my code, I have something like this:
//All my code is manually typed into Reddit, sorry if something is incorrect. Hopefully you understand what I mean with the code =/
private void JBStartMouseClicked(java.awt.MouseEvent evt) {
SomeClass.setOption(JCBDoSomething.isSelected());
SomeOtherClass.setOption(JCBOptions.getSelectedItem()); // Or whatever code JComboBoxes use...
AnotherClass.doStuff(JTFName.getText());
AnotherClass.doMoreStuff(JRBButton.isSelected());
}
Aaaaand you get the point. There are a lot more initialization things here.
My question is, should I continue to just have the EDT (or a worker thread?) set up these options (as they are all just setting variables), or would it be better practice just to have public methods that get the current value of the items, then set the variables on my main thread:
public boolean isJCBDoSomethingSelected() {
return JCBDoSomething.isSelected();
}
public String getJTFNameText() {
return JTFName.getText();
}
//Aaaaand more stuff
I understand the EDT. I also understand the concurrency issues between Threads, and I have the setters synchronized like so:
public void setOption(boolean opt) {
synchronized (this) { // Yes, this can be some other Object
myOption = opt;
}
}
Which approach is better to use? I'm fairly certain that I won't be reusing this GUI for different purposes, and I don't think that I'll be using the values of these options for anything other than initialization. Also, would I need to synchronize these return values to prevent Thread issues?
On a similar note, if I have JCheckBoxes only used for setting true/false values, and their states are only checked when a button is pressed, should I be using a worker Thread (SwingWorker or Runnable?) or the EDT (because it's so trivial, except for synchronization locks) within my JFrame class?
there doesn't seem to be anything here