问题:为什么下面的代码执行出来的结果是这样?而不是第二zhang的图片?似乎这两句代码没有用Stringtemp=textArea.getText();//这句获取textArea对象里面的内容textArea.setText("按钮...
问题:为什么下面的代码执行出来的结果是这样?而不是第二zhang的图片?似乎这两句代码没有用
String temp=textArea.getText(); //这句获取textArea对象里面的内容
textArea.setText("按钮第"+n+"次被按下\n"+temp); //为什么按了确定之后不是连续出现
代码如下:
//命名内部类作为事件监听器;
package test;
import java.awt.*;
import java.awt.event.*;//事件处理机制
class ButtonClickTest4 extends Frame{ //继承类Frame
private Button button=new Button("确定");
private TextArea textArea=new TextArea();
private static int n=1;
public ButtonClickTest4(){
button.addActionListener(new MyActionListener()); //命名内部类作为事件监听器;
add(button,BorderLayout.NORTH);
add(textArea,BorderLayout.CENTER);
setBounds(20,20,200,200);
setVisible (true);
}
private class MyActionListener implements ActionListener{ //命名内部类
public void actionPerformed (ActionEvent e){
String temp=textArea.getText();
textArea.setText("按钮第"+n+"次被按下\n"+temp);
n++;
}
}
}
public class Test7_10{
public static void main(String[] args){
new ButtonClickTest();
}
}
展开