?? trafficframe.java
字號:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class trafficFrame extends SimpleFrame{
public trafficFrame(int width,int height) {
super(width,height);
setTitle("紅綠燈");
ColorPanel panel=new ColorPanel();
Container contentPane=getContentPane();
contentPane.add(panel);
}
public static void main(String[] args){
trafficFrame frame=new trafficFrame(400,300);
frame.setVisible(true);
}
}
class ColorPanel extends JPanel{
public ColorPanel(){
redButton= new JButton("紅燈");
greenButton=new JButton("綠燈");
yellowButton=new JButton("黃燈");
add(redButton);
add(greenButton);
add(yellowButton);
redButton.addActionListener(new ColorActionListener());
yellowButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
setyellow();
}
});
greenButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
setgreen();
}
});
}
private void setyellow(){
backgroundColor=backgroundColor.brighter();
backgroundColor=new Color(255,255,0);
setBackground(backgroundColor);
}
private void setgreen(){
backgroundColor=backgroundColor.darker();
backgroundColor=new Color(0,255,0);
setBackground(backgroundColor);
}
private class ColorActionListener implements ActionListener{
public void actionPerformed(ActionEvent event){
setColor();
}
}
private void setColor(){
backgroundColor=new Color(255,0,0);
setBackground(backgroundColor);
}
private Color backgroundColor;
private JButton redButton;
private JButton greenButton;
private JButton yellowButton;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -