📄 exp7.java
字号:
import java.awt.*;
import java.awt.event.*;
public class Exp7 extends Frame{
static Panel pan=new Panel();//创建一个面板对象
static Label lab=new Label("0.0",Label.RIGHT);
//创建一个标签对象,文字右对齐
static Button b[]=new Button[10];
static Button b_point,b_add,b_subtract,b_multiply,b_divide,b_equal;
public static void main(String args[]) {
Exp7 frm=new Exp7( );
int i;
for(i=0;i<10;i++)
b[i]=new Button(""+i);
b_point=new Button(".");
b_add=new Button("+");
b_subtract=new Button("-");
b_multiply=new Button("*");
b_divide=new Button("/");
b_equal=new Button("=");
frm.setTitle("计算器");
frm.setLayout(null);//取消框架窗口的页面设置
frm.setSize(180,200);
frm.setResizable(false);//设置框架窗口的大小为不可改变
frm.setBackground(Color.YELLOW);
GridLayout grid=new GridLayout(4,4,6,6);//创建4行4列的页面配置
pan.setLayout(grid);//将面板pan的布局策略设为网格布局方式
pan.setBounds(20,60,150,120);
lab.setBounds(20,35,150,20);
lab.setBackground(Color.GRAY);//设置标签的颜色
pan.add(b[7]);pan.add(b[8]);pan.add(b[9]);pan.add(b_divide);
pan.add(b[4]);pan.add(b[5]);pan.add(b[6]);pan.add(b_multiply);
pan.add(b[1]);pan.add(b[2]);pan.add(b[3]);pan.add(b_subtract);
pan.add(b[0]);pan.add(b_point);pan.add(b_equal);pan.add(b_add);
frm.add(lab);
frm.add(pan);
frm.addWindowListener(new WindowClose());
frm.setVisible(true);
}
static class WindowClose extends WindowAdapter{
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -