-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumkey.java
More file actions
40 lines (36 loc) · 1.03 KB
/
Copy pathNumkey.java
File metadata and controls
40 lines (36 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package Calcurator;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
public class Numkey extends AbstractAction{
private static final long serialVersionUID = 1L; // eclipseでwarning出たので付け足した
private Calc thisCalc;
Numkey(String key, Calc thisCalc){
putValue(Action.NAME, key);
this.thisCalc = thisCalc;
}
public void actionPerformed(ActionEvent e) {
if(!thisCalc.error_flag) {
String input = (String)getValue(Action.NAME);
if(thisCalc.equals_flag) {
thisCalc.initialize();
}
if(!thisCalc.num_flag || thisCalc.field.getText().equals("0")) {
if(input.equals(".")) {
thisCalc.field.setText("0."); // 0.~にする
} else {
thisCalc.field.setText(input);
}
thisCalc.num_flag = true;
} else {
if(input.equals(".")) {
if(!thisCalc.field.getText().contains(".")) {
thisCalc.field.setText(thisCalc.field.getText() + ".");
}
} else {
thisCalc.field.setText(thisCalc.field.getText() + input);
}
}
}
}
}