📄 count.java
字号:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Count extends JFrame
{
int i=0;
String topButtons [] = new String[]{"BackSpace"," CE "," C "};
String leftButtons [] = new String[]{"MC","MR","MS","M+"};
String centerButtons[] = new String[]{"7","8","9","/","sqrt","4","5","6","*","%","1","2","3","-","1/x","0","+/-",".","+","="};
JTextField text;
public Count(){
super("计算器");
//TOP
text = new JTextField(33);
JPanel ptop = new JPanel();
ptop.add(text);
add("North",ptop);
//Center
JPanel p = new JPanel();
JPanel pmain = new JPanel();
pmain.setLayout(new BorderLayout(5,5));
p.add(pmain);
//上面
JPanel pmain_top = new JPanel();
pmain_top.setLayout(new FlowLayout(FlowLayout.RIGHT));
for(i=0;i<topButtons.length;i++){
JButton b = new JButton(topButtons[i]);
pmain_top.add(b);
}
//左边
JPanel pmain_left= new JPanel();
pmain_left.setLayout(new GridLayout(0,1,5,5));
for(i=0;i<leftButtons.length;i++){
JButton b = new JButton(leftButtons[i]);
pmain_left.add(b);
}
//中间
JPanel pmain_center = new JPanel();
pmain_center.setLayout(new GridLayout(4,5,5,5));
for(i=0;i<centerButtons.length;i++){
JButton b = new JButton(centerButtons[i]);
pmain_center.add(b);
}
pmain.add("North",pmain_top);
pmain.add("West",pmain_left);
pmain.add("Center",pmain_center);
add("Center",p);
setSize(400,500);
pack();
setVisible(true);
}
public static void main(String args[]){
new Count();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -