|
|
|
@ -11,6 +11,7 @@ public class Computer extends JFrame{
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
Computer t = new Computer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Computer() {
|
|
|
|
|
this.setTitle("计算器");
|
|
|
|
|
Container c = getContentPane();
|
|
|
|
@ -37,6 +38,7 @@ public class Computer extends JFrame{
|
|
|
|
|
aJButtons[13]=new JButton("/");
|
|
|
|
|
aJButtons[14]=new JButton("=");
|
|
|
|
|
aJButtons[15]=new JButton(".");
|
|
|
|
|
|
|
|
|
|
aj.add(aJButtons[7]);
|
|
|
|
|
aj.add(aJButtons[8]);
|
|
|
|
|
aj.add(aJButtons[9]);
|
|
|
|
@ -56,6 +58,7 @@ public class Computer extends JFrame{
|
|
|
|
|
c.add(aj, BorderLayout.CENTER);
|
|
|
|
|
setSize(400, 400);
|
|
|
|
|
setVisible(true);
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < 10; i++) {
|
|
|
|
|
final String o = aJButtons[i].getActionCommand();
|
|
|
|
|
aJButtons[i].addActionListener(new ActionListener() {
|
|
|
|
@ -115,18 +118,22 @@ public class Computer extends JFrame{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if(flag == 1) {
|
|
|
|
|
//加法
|
|
|
|
|
b = Double.parseDouble(sz[0]) + Double.parseDouble(sz[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if(flag == 2) {
|
|
|
|
|
//减法
|
|
|
|
|
b = Double.parseDouble(sz[0]) - Double.parseDouble(sz[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if(flag == 3) {
|
|
|
|
|
//乘法
|
|
|
|
|
b = Double.parseDouble(sz[0]) * Double.parseDouble(sz[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if(flag == 4) {
|
|
|
|
|
//除法
|
|
|
|
|
b = Double.parseDouble(sz[0]) / Double.parseDouble(sz[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|