JPanel pLeft = new JPanel();
pLeft.setLayout(new GridLayout(5,1,3,3));
bM = new JButton(" ");
bM.setEnabled(false);
pLeft.add(bM);
/*************************Java计算器 功能键定义***************************/
bOther = new JButton("MC");
bOther.addActionListener(this);
bOther.setForeground(Color.red);
bOther.setMargin(new Insets(3,2,3,2));
pLeft.add(bOther);
bOther = new JButton("MR");
bOther.addActionListener(this);
bOther.setForeground(Color.red);
bOther.setMargin(new Insets(3,2,3,2));
pLeft.add(bOther);
bOther = new JButton("MS");
bOther.addActionListener(this);
bOther.setForeground(Color.red);
bOther.setMargin(new Insets(3,2,3,2));
pLeft.add(bOther);
bOther = new JButton("M+");
bOther.addActionListener(this);
bOther.setForeground(Color.red);
bOther.setMargin(new Insets(3,2,3,2));
pLeft.add(bOther);
pBottom.add(pLeft,BorderLayout.WEST);
JPanel pRight = new JPanel();
pRight.setLayout(new BorderLayout());
JPanel pUp = new JPanel();
pUp.setLayout(new GridLayout(1,3,3,0));
bOther = new JButton("BackSpace");
bOther.addActionListener(this);
bOther.setForeground(Color.red);
bOther.setMargin(new Insets(3,0,3,5));
pUp.add(bOther);
bOther = new JButton("CE");
bOther.addActionListener(this);
bOther.setForeground(Color.red);
pUp.add(bOther);
bOther = new JButton("C");
bOther.addActionListener(this);
bOther.setForeground(Color.red);
pUp.add(bOther);
/***************************Java计算器 数字键盘区定义**************************/
JPanel pDown = new JPanel();
pDown.setLayout(new GridLayout(4,5,3,2));
bNumber = new JButton("7");
bNumber.setForeground(Color.blue);
bNumber.addActionListener(this);
bNumber.setMargin(new Insets(3,3,3,3));
pDown.add(bNumber);
bNumber = new JButton("8");
bNumber.setForeground(Color.blue);
bNumber.addActionListener(this);
bNumber.setMargin(new Insets(3,3,3,3));
pDown.add(bNumber);
bNumber = new JButton("9");
bNumber.setForeground(Color.blue);
bNumber.addActionListener(this);
bNumber.setMargin(new Insets(3,3,3,3));
pDown.add(bNumber);
bOperator = new JButton("/");
bOperator.setForeground(Color.red);
bOperator.addActionListener(this);
bOperator.setMargin(new Insets(3,0,3,0));
pDown.add(bOperator);
bOperator = new JButton("sqrt");
bOperator.addActionListener(this);
bOperator.setForeground(Color.red);
bOperator.setMargin(new Insets(3,0,3,0));
pDown.add(bOperator);
bNumber = new JButton("4");
bNumber.setForeground(Color.blue);
bNumber.addActionListener(this);
bNumber.setMargin(new Insets(3,3,3,3));
bNumber.setHorizontalTextPosition(JButton.LEFT);
pDown.add(bNumber);
bNumber = new JButton("5");
bNumber.setForeground(Color.blue);
bNumber.addActionListener(this);
bNumber.setMargin(new Insets(3,3,3,3));
pDown.add(bNumber);
bNumber = new JButton("6");
bNumber.setForeground(Color.blue);
bNumber.addActionListener(this);
bNumber.setMargin(new Insets(3,3,3,3));
pDown.add(bNumber);
bOperator = new JButton("*");
bOperator.setForeground(Color.red);
bOperator.addActionListener(this);
bOperator.setMargin(new Insets(3,3,3,3));
pDown.add(bOperator);
bOperator = new JButton("%");
bOperator.setForeground(Color.blue);
bOperator.addActionListener(this);
bOperator.setMargin(new Insets(3,3,3,3));
pDown.add(bOperator);
bNumber = new JButton("1");
bNumber.setForeground(Color.blue);
bNumber.addActionListener(this);
bNumber.setMargin(new Insets(3,3,3,3));
pDown.add(bNumber);
bNumber = new JButton("2");
bNumber.setForeground(Color.blue);
推荐阅读
- flutter控件覆盖,flutter嵌套
- 小米k50怎么降级鸿蒙系统的简单介绍
- 新生电商如何发展,电商如何快速发展
- 江苏专业网站搭建费用低,专业建设网站的公司
- linux性能指标命令 linux常用性能命令
- ChatGPT免费破解最新版,chatcraft pro 破解版
- 包含代理软件的词条
- 公众号文章最后的阅读量,公众号文章最后的阅读量怎么算
- php数据传递js php传数据给ajax的实例