?? tenbuttonframe.java
字號:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class TenButtonFrame extends JFrame implements ActionListener
{
JButton [] button=new JButton[10];
JButton greenButton;
boolean s1,s2,s3;
Container contentPane;
public TenButtonFrame(String title)
{
setTitle(title);
setSize(400,200);
contentPane =getContentPane();
contentPane.setLayout(new FlowLayout());
for(int i=0;i<10;i++)
{
button[i]=new JButton(i+"");
button[i].addActionListener(this);
contentPane.add(button[i]);
}
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent evt)
{
if(evt.getSource()==button[7])
{
s1=true;
}
else
{
contentPane.setBackground(Color.RED);
}
if(evt.getSource()==button[3])
{
s2=true;
s1=s2=true;
}
else
{
contentPane.setBackground(Color.RED);
}
if(evt.getSource()==button[5])
{
s1=true;
s2=true;
s3=true;
}
else
{
contentPane.setBackground(Color.RED);
}
}
public static void main(String[]args)
{
TenButtonFrame frame = new TenButtonFrame("Ten Button Frame");
frame.setVisible(true);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -