1

開始 - 15:00

更新 1 - 午後 5 時 36 分

Option() クラスの適用ボタン:

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


}  

これは Option() クラスのセクションです。

    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;


}

これは Option() クラスのメソッドです。

    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;

}

HUD() 内から Options() を開く方法は次のとおりです。

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

これは私の HUD() クラスの始まりです:

    public abstract class HUD extends javax.swing.JFrame implements Runnable {


private Options o;
 private HUD hud;

public HUD(Options o) {


    initComponents();
    this.o = o;

これは、Options() から JButtons の値を取得する HUD() のメソッドです。

       public void setTime(String strTime) {

    strTime = o.getTime();
    txtTime.setText(strTime);
}

ただし、[適用] をクリックするたびに、Options() で設定されたオプションは、HUD() で表示される TextFields では設定されません:/

4

2 に答える 2

0

非常に長いコードサンプルをナビゲートするのは困難ですが、cmdApplyActionPerformed()メソッドを見てください。あなたはnew HUD()それに値を作成して設定しています...そしてそれで全く何もしていません。

[適用]ボタンを使用して既存のオブジェクトを変更しようとしている場合HUD、クラスはそのオブジェクトへの参照をどこかに持っている必要があります。HUDを作成する親クラスである場合は、コンストラクターに親への参照をストアに格納してOptionsみてください。Options次に、でこのような変更を実行するOptionsと、効果のない新しい変数ではなく、親に対して変更を実行できます。

private HUD parent;

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

次に、イベントハンドラーで、次のことができます...

parent.setTime(btnTxtTime);
parent.setTemp(btnTxtTemp);
parent.setSurface(btnTxtSurface);
parent.setWeather(btnTxtWeather);
parent.setRadiation(btnTxtRadiation);
dispose();
于 2013-02-22T15:40:58.987 に答える
0

私の理解では、HUD は「メイン ウィンドウ」であり、ユーザーはそのウィンドウからこのオプション フレームにアクセスします。

ただし、適用すると、以前の HUD ではなく、新しいHUD でプロパティを設定することになります。

これを修正するには、構成ウィンドウにメイン ウィンドウへのハンドルが必要です。これにより、プロパティを設定できるようになります。

あなたのhudで:

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

あなたの設定で

private HUD hud;

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

次に、単に除外しますHUD hud = new hud();

于 2013-02-22T15:42:00.450 に答える