メインの Swing フレームには、次のメソッドがあります。
public void receiveCommand(String command) {
if (command.equals("enable")) {
Runnable enable = new Runnable() {
public void run() {
button1.setEnabled(true);
button1.revalidate();
button1.repaint();
}
};
SwingUtilities.invokeLater(enable);
}
基本的に、外部から receiveCommand() メソッドを呼び出してGUI を更新 (ボタンbutton1を有効化) しようとしています。
ただし、これは機能しません。つまり、button1はまだ無効になっています。ここで何が間違っていましたか?
EDIT : ここにbutton1の宣言があります:
private javax.swing.JButton button1;
button1.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
button1.setEnabled(false);
button1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
button1ActionPerformed(evt);
}
});
button1とreceiveCommandメソッドの両方がこのGameクラスにあります。
public class Game extends javax.swing.JFrame
メソッドは別のクラスから呼び出されます。
gameUI.receiveCommand("enable"); //gameUI is a Game object
EDIT 2:ご協力ありがとうございます!結局、それは間違った参照であることが判明したので、まだ可視に設定されていない間違ったフレームの GUI を更新しようとしただけです。愚かな私