ActionEvent e;



public void start(){

do{


but1.addActionListener(new ButtonHandler());

    but2.addActionListener(new ButtonHandler());


    if(e.getActionCommand() == "验证风速值"){
    
    
     String Line1 = text1.getText();。。中的
    if(e.getActionCommand() == "验证风速值"){
e只是在上面申明了ActionEvent e;并没有初始化,所以在这里使用的时候就会出现空指针错误,你想点击按钮"验证风速值"时执行,但是AppletPanel已经自动执行了你的start()语句。

解决方案 »

  1.   

    可以重载start方法,给它加上参数,部分写成如下,start在actionPerformed方法中执行, public class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { e.getActionCommand(); //getActionCommand是ActionEvent类的方法
    start(e);
    } } //ActionEvent e; public void start(ActionEvent e) {
      

  2.   

    你的按钮也没有加上任何监听器 but4 = new Button("打印最终结果");
    add(but4);
    setSize(100, 200);
    setVisible(true);

    Component[] cs=this.getComponents();
    for(int i=0;i<cs.length;i++){
    if(cs[i] instanceof Button){
    ((Button)cs[i]).addActionListener(new ButtonHandler());
    }
    }
      

  3.   

    kypfos(政治面貌:一世清白)
    可以知道你的联系方式吗?