3
私は私のUIカント設定値
public class MyFrame extends JFrame{
JTextArea textArea;
public MyFrame(){
setSize(100,100);
textArea = new JTextArea(50,50);
Container content = getContentPane();
content.add(textArea);
}
public static void main(String[] args){
JFrame frame = new MyFrame();
frame.show();
UpdateText u = new UpdateText();
u.settext("Helloworld");
}
}
ため、このクラスを持っていると私はtextArea
のテキストを設定します。この他のクラスを持っているが、ウィッヒに私は別のににtextAreaをアクセスもするMyFrameと拡張しましたクラス。
public class UpdateText extends MyFrame{
public void settext(String msg){
textArea.setText(msg);
}
}
次に、UpdateTextをインスタンス化し、settext関数を呼び出します。テキストはGUIではうまくいきません。 助けてください
TextAreaはどのようにUpdateTextクラスに渡されますか?あなたはそれらが同じtextAreaインスタンスであると確信していますか? – evanwong
が私のために働いています... – ControlAltDel
@evanwong UpdateTextはMyFrameを拡張して、textArea –