📄 counterframe.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CounterFrame{
Frame f = new Frame("counter");
TextField tf1 = new TextField(20);
Panel p = new Panel();
Button[] b = new Button[21];
String[] s = {"退格","CE","C","/",
"7","8","9","*",
"4","5","6","-",
"1","2","3","+",
"0","+/-",".","="};
public CounterFrame(){
tf1.setForeground(Color.black);
tf1.setFont(new Font("Arial Black",1,20));
for(int i=1;i<21;i++){
b[i] = new Button(s[i-1]);
b[i].setFont(new Font("仿宋",1,15));
}
p.setLayout(new GridLayout(5,4,3,3));
p.setBackground(Color.LIGHT_GRAY);
for(int i=1;i<21;i++){
p.add(b[i]);
b[i].setBackground(new Color(20,130,180));
b[i].setForeground(Color.yellow);
}
for(int i=1;i<4;i++){
b[i].setBackground(new Color(120,180,170));
b[i].setForeground(Color.blue);
}
for(int i=1;i<=4;i++){
b[i*4].setBackground(new Color(120,180,170));
b[i*4].setForeground(Color.red);
}
b[20].setBackground(Color.red);
f.setLayout(new BorderLayout(3,3));
f.add(tf1,"North");
f.add(p,"Center");
f.setSize(300,200);
f.setLocation(300,300);
f.setBackground(Color.LIGHT_GRAY);
f.setResizable(false);
f.setVisible(true);
}
public static void main(String args[]){
new CounterFrame();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -