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
文本,在至極我延長MyFrame進入電影textarea的另一類。
public class UpdateText extends MyFrame{
public void settext(String msg){
textArea.setText(msg);
}
}
然後我實例化UpdateText並調用函數settext。但文字似乎並沒有在GUI中顯示。 請幫忙
textArea如何傳遞給UpdateText類?你確定它們是相同的textArea實例嗎? – evanwong 2012-04-09 17:35:47
適用於我... – ControlAltDel 2012-04-09 17:35:56
@evanwong UpdateText擴展了MyFrame,所以它可以有textArea – 2012-04-09 17:40:29