我即将制作一个程序,如果你单击一个按钮就会显示一些文字...但我不知道如何在设置字符串后更改字符串。这是我现在的代码。
//Text Area to "Copy"
String output = "";
JTextArea TArea = new JTextArea(output);
TArea.setBounds(200, 72, 177, 296);
panel.add(TArea);
//When press the button "Generate"
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
String output = "Hello World";
TArea.setBounds(200, 72, 177, 296);
}
});
希望你能帮助我:)。
答案 0 :(得分:1)
但我知道如何在设置字符串
后更改字符串
textArea.setText(...);
将重置文本
textArea.append(...);
将文本添加到文本区域的末尾。
其他想法:
我建议您阅读Swing Tutorial了解使用Swing的基础知识。
不要使用setBounds(..)。 Swing旨在与布局管理器一起使用。本教程中有大量使用布局管理器的示例。
变量名称不应以大写字母开头。遵循Java惯例,不要自己编写。任何教程或教科书都将遵循惯例。