📄 button.java
字号:
import java.awt.*;
import java.awt.event.*;
public class button implements ActionListener {
Frame f;
Button b1, b2, b3;
Panel p;
public static void main(String[] args) {
button er = new button();
er.go();
}
public void go() {
f = new Frame();
b1 = new Button();
p = new Panel();
b1.setBackground(Color.red);
b1.setActionCommand("red");
b1.addActionListener(this);
p.add(b1);
b2 = new Button();
b2.setActionCommand("yellow");
b2.setBackground(Color.yellow);
b2.addActionListener(this);
p.add(b2);
b3 = new Button();
b3.setBackground(Color.green);
b3.setActionCommand("green");
b3.addActionListener(this);
p.add(b3);
f.add(p, BorderLayout.SOUTH);
f.pack();
f.setVisible(true);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
private void addWindowListener(WindowAdapter windowAdapter) {
// TODO Auto-generated method stub
}
public void actionPerformed(ActionEvent e) {
if( e.getActionCommand().equals("red")){
f.setBackground(Color.red);
}
if( e.getActionCommand().equals("yellow")){
f.setBackground(Color.yellow);
}
if( e.getActionCommand().equals("green")){
f.setBackground(Color.green);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -