JAVA按钮设置了不显示

package lab13;
import java.awt.*;
import java.awt.Button;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;

public class ActionEventFrame extends Frame implements ActionListener {
Button bt1,bt2,bt3;
public void ActionListener() {
Panel a=new Panel();
bt1=new Button("红色");
bt2=new Button("绿色");
bt3=new Button("蓝色");
a.add(bt1);
a.add(bt2);
a.add(bt3);
this.add(a,"North");
bt1.addActionListener(this);
bt2.addActionListener(this);
bt3.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
String btnLabel=e.getActionCommand();
if (btnLabel.equals("红色")){
setBackground(Color.red);
}else if (btnLabel.equals("绿色")){
setBackground(Color.green);
}else if (btnLabel.equals("蓝色")){
setBackground(Color.blue);
}
}
public static void main(String[] args) {
ActionEventFrame b=new ActionEventFrame();
b.setTitle("ActionEvent事件处理");
b.setSize(300, 200);
b.setVisible(true);
b.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent arg0) {
System.exit(0);
}
});
}
}
//大佬帮忙看看,感觉没出错,就是运行不出来

出错的地方

public void ActionListener(){ //..这是一个普通的方法
    
}

修改成下面的代码

public ActionEventFrame() { //这就是窗口的构造方法了, 
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-05-28
现在暂时是没有的,建议百度查询。
相似回答