私のコード;
package com.test;
import java.awt.EventQueue;
public class TestGU {
private JFrame frame;
private JLabel la;
/**
* Launch the application.
*/
public void mainM() {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
TestGU window = new TestGU();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public void redefine(String text){
la.setText(text);
frame.repaint();
}
/**
* Create the application.
*/
public TestGU() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
la = new JLabel("New label");
frame.getContentPane().add(null);
}
}
以下に示すメイン メソッド (別のクラス) からラベルのテキストを変更しようとしています。
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
TestGU g = new TestGU();
g.mainM();
g.redefine("New Value");
}
}
1.) メイン メソッドが実行されると、ラベルに "New Value" というテキストが含まれているはずでしたが、まだテキストが含まれていますNew label
。何も変わっていません。どうすれば修正できますか?