java计算器代码

时间:2016-07-11 01:53:45
【文件属性】:

文件名称:java计算器代码

文件大小:6KB

文件格式:RAR

更新时间:2016-07-11 01:53:45

java

container=getContentPane(); layout=new GridBagLayout(); container.setLayout(layout); constraints=new GridBagConstraints(); start=true; result=0; lastCommand = "="; displayField=new JTextField(20); displayField.setHorizontalAlignment(JTextField.RIGHT); constraints.gridx=0; constraints.gridy=0; constraints.gridwidth=4; constraints.gridheight=1; constraints.fill=GridBagConstraints.BOTH; constraints.weightx=100; constraints.weighty=100; layout.setConstraints(displayField,constraints); container.add(displayField); ActionListener insert = new InsertAction(); ActionListener command = new CommandAction(); addButton("Backspace",0,1,2,1,insert); addButton("CE",2,1,1,1,insert); addButton("C",3,1,1,1,insert); addButton("7",0,2,1,1,insert); addButton("8",1,2,1,1,insert); addButton("9",2,2,1,1,insert); addButton("/",3,2,1,1,command); addButton("4",0,3,1,1,insert); addButton("5",1,3,1,1,insert); addButton("6",2,3,1,1,insert); addButton("*",3,3,1,1,command); addButton("1",0,4,1,1,insert); addButton("2",1,4,1,1,insert); addButton("3",2,4,1,1,insert); addButton("-",3,4,1,1,command); addButton("0",0,5,1,1,insert); addButton("+/-",1,5,1,1,insert);//只显示"-"号,"+"没有实用价值 addButton(".",2,5,1,1,insert); addButton("+",3,5,1,1,command); addButton("=",0,6,4,1,command); setSize(300,300); setVisible(true);


【文件预览】:
计算器
----.project(385B)
----bin()
--------Calculator$CommandAction.class(1KB)
--------Calculator.class(4KB)
--------Calculator$InsertAction.class(2KB)
----.settings()
--------org.eclipse.jdt.core.prefs(598B)
----src()
--------Calculator.java(5KB)
----.classpath(301B)

网友评论

  • 感谢分享,对我有用……