1

STARTED - 3:00PM

UPDATE 1 - 5:36PM

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);
}

However whenever I click Apply, the options set in Options() are not then set in the TextFields that display them in HUD() like they should be :/

  • Adam, I've seen all three versions of your question and I have to say (without any intent of being rude), you need to get to the point soon. ideally your first sentence should state the question. It's still not very clear what you are trying to do but if it is what I think it is then do a search on events and eventlisteners, your hud can have an eventlistener that listens for events fired when options are changed – vikki Feb 23 '13 at 04:45
  • Not meaning to be rude either but I've explained the point in each one. I dont understand how else I can explain what I require ... I've reiterated it in 3 different ways :/ – Adam Ray Bicknell Feb 23 '13 at 04:54
  • Though what you mention sounds like what I need! So frustrated with this its untrue, I just dont understand method properly, have stated I'm a newbie to Java, but keep getting told the same thing which does not work – Adam Ray Bicknell Feb 23 '13 at 04:56

2 Answers2

0

It's difficult to navigate through your very lengthy code sample, however take a look at your cmdApplyActionPerformed() method. You are creating a new HUD() and setting values in it... and then doing absolutely nothing with it.

If you are trying to use the "Apply" button to modify an existing HUD object, your class needs to have a reference to it somewhere. If the HUD is the parent class which creates the Options, try having the Options store a reference to the parent in its constructor. Then, when you perform changes like this in the Options, you can perform them on the parent rather than on a new variable which has no effect.

private HUD parent;

/**
 * Creates new form Profile
 */
public Options(HUD parent) {
    initComponents();
    this.parent = parent;
}

Then, in your event handler, you can have ...

parent.setTime(btnTxtTime);
parent.setTemp(btnTxtTemp);
parent.setSurface(btnTxtSurface);
parent.setWeather(btnTxtWeather);
parent.setRadiation(btnTxtRadiation);
dispose();
asteri
  • 11,402
  • 13
  • 60
  • 84
  • Got all this set up, had to go through and create private Menu, private options in some as changing created errors, done this now, all loads and such but still doesnt change the variables on HUD :/ – Adam Ray Bicknell Feb 22 '13 at 17:26
0

From what I understand, HUD is your 'main window' and the users gets to this option frame from that window.

But when you apply, you're setting the properties on a new HUD, not the one you had before.

To fix this, you need a handle to your main window in your config window, so that you can set the properties on it.

in your hud:

ConfigFrame config = new ConfigFrame();
config.setHUD(this);
config.setVisible(true);

In your config

private HUD hud;

public void setHUD(HUD hud){
   this.hud = hud;
}

then just leave out the HUD hud = new hud();

Joeri Hendrickx
  • 16,947
  • 4
  • 41
  • 53
  • HUD() isn't my main class, thats my Menu() that brings the user to HUD(), but I completely see what you mean and had thought about this a number of times, but could work out what to search for, will try and implement this now and will get back to you! – Adam Ray Bicknell Feb 22 '13 at 15:49