asked a question early but didn't layout my code very well, and the whole question got a bit muddled, then as I changed my code but still have the same issue, the question still remains, however I decided to re-ask the question with my code laid out much neater so you can see the important bits.
Here's the link to the initial question:
Cannot get variable from Child back to Parent in JAVA (Options Window)
Basically I have a variety of classes. Three of which are:
Menu()
HUD()
Options()
My main class is Menu() and from Menu(), HUD() is opened via a button. Menu is not causing me any issues, however, HUD() and Options() are.
Options() is opened up from inside HUD() and in there are 5 buttons groups, containing 14 options between them. When the user selects each option for the button group, he then clicks Apply, and the values (string values) of the Radio Button Selected for each group, should be assigned to given variables on HUD(). However, when clicking on Apply, it clears all the variables instead, or that's what it appears to be doing.
Apply Button in the Option() class:
private void cmdApplyActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
hud.setTime(btnTxtTime);
hud.setTemp(btnTxtTemp);
hud.setSurface(btnTxtSurface);
hud.setWeather(btnTxtWeather);
hud.setRadiation(btnTxtRadiation);
dispose();
}
This is a section of the Option() Class.
public class Options extends javax.swing.JFrame {
public String btnTxtTime;
public String btnTxtTemp;
public String btnTxtSurface;
public String btnTxtWeather;
public String btnTxtRadiation;
public static boolean ApplyClicked;
/**
* Creates new form Profile
*/
private HUD hud;
public Options(HUD hud) {
initComponents();
this.hud = hud;
}
This is a method in Option() class:
public String getTime() {
if ("Day".equals(grpTimeOfDay.getSelection())) {
btnTxtTime = "Day";
return this.btnTxtTime;
}
if ("Night".equals(grpTimeOfDay.getSelection())) {
btnTxtTime = "Night";
return this.btnTxtTime;
}
return null;
}
This is how Options() is openned from within HUD():
private void cmdOptionsActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Options o = new Options(hud);
this.getLocation(p);
o.setLocation((int) p.getX() + 100, (int) p.getY() + 100);
o.setVisible(true);
}
This is the start of my HUD() Class:
public abstract class HUD extends javax.swing.JFrame implements Runnable {
private Options o;
private HUD hud;
public HUD(Options o) {
initComponents();
this.o = o;
and this is the method from HUD() which gets the value of the JButtons from Options():
public void setTime(String strTime) {
strTime = o.getTime();
txtTime.setText(strTime);
}