私は自分の掃海艇を現在開発中です。スイングはモデルビューコントローラの設計パターンに従います。 MVCでは、モデルに変更があるたびにを学習しましたが、コントローラーはその変更をビューでもトリガーします。しかし、この例では、setTitle
とsetInfo
の変更を反映させる方法をトレースできません。モデルビューコントローラで、なぜモデルを変更するのですが、ビューの変更をトリガしませんか?
ここで、ダイアログボックスのタイトルを設定すると、実際のコンテンツ(モデル)が変更されていますが、出力(ビュー)に対応する変更はありません。
//InfoDisplayer is inner class of class MenuActionListener
class InfoDisplayer extends JDialog {
JLabel info;
BorderLayout infoBorderLayout = new BorderLayout();
public InfoDisplayer(JFrame ownerFrame) {
super(ownerFrame,true);
info = new JLabel();
setFocusable(false);
setSize(300,400);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setLayout(infoBorderLayout);
add(info,BorderLayout.SOUTH);
setVisible(true);
}
void setInfo(JLabel info) {
this.info = info;
}
public void setTitle(String title) {
super.setTitle(title);
}
}
if ((event.getActionCommand()).equals("HowToPlay")) {
InfoDisplayer instructionsDisplay = new InfoDisplayer(gUIManagerFrame);
//gUIManagerFrame is an object of its outer class,MenuActionListener
instructionsDisplay.setTitle("INSTRUCTIONS");
instructionsDisplay.setInfo(new JLabel("<html><h1><B>INSTRUCTIONS</B></h1></html>"));
} else {// if about is clicked!!
InfoDisplayer aboutDisplay = new InfoDisplayer(gUIManagerFrame);
aboutDisplay.setTitle("MineSweeper v0.1");
aboutDisplay.setInfo(new JLabel("<html><h1><B>MineSweeperv1.0</B></h1> </html>"));
}
MVCについては何ですか? –
2つの承認のどちらもうまくいきませんでした。古いJLabelを削除して新しいJLabelを追加しますか?第一\t \t \t \t \t:「無効SETINFO(JLabelの情報){ \t \t \t \t \t \tのremove(これ。情報); \t \t \t \t \t \t this.info.setText(info.toString()); \t \t \t \t add(this.info、BorderLayout.SOUTH); \t \t \t \t \t} "2: " \t \t \t \t \t空隙SETINFO(JLabelの情報){ \t \t \t \t \t \t削除(this.info)。 \t \t \t \t \t \t this.info = info; \t \t \t \t \t add(info、BorderLayout.SOUTH); 更新の\t \t \t \t \t}」 –
1オーバー置き換える; MVCの詳細は[こちら](http://stackoverflow.com/a/8401255/230513)申し訳ありません – trashgod