【+】
JButton btnNewButton_12 = new JButton("+");
btnNewButton_12.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
a = s.length();
s = s + "+";
textField.setText(s);
x = Double.parseDouble(s.substring(0, a));
c = '+';
}
});
【-】
JButton btnNewButton_13 = new JButton("-");
btnNewButton_13.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
a = s.length();
s = s + "-";
textField.setText(s);
x = Double.parseDouble(s.substring(0, a));
c = '-';
}
});
【x】
JButton btnNewButton_14 = new JButton("x");
btnNewButton_14.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
a = s.length();
s = s + "x";
textField.setText(s);
x = Double.parseDouble(s.substring(0, a));
c = 'x';
}
});
【/】
JButton button = new JButton("/");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
a = s.length();
s = s + "/";
x = Double.parseDouble(s.substring(0, a));
textField.setText(s);
c = '/';
}
});
【=】
JButton btnNewButton = new JButton(" = ");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
b = s.length();
y = Double.parseDouble(s.substring(a + 1, b));
if (p[0] == c) {
double m = x + y;
String ss = String.valueOf(m);
textField_1.setText("=" + ss);
}
if (p[1] == c) {
double m = x - y;
String ss = String.valueOf(m);
textField_1.setText("=" + ss);
}
if (p[2] == c) {
double m = x * y;
String ss = String.valueOf(m);
textField_1.setText("=" + ss);
}
if (p[3] == c) {
double m = x / y;
String ss = String.valueOf(m);
textField_1.setText("=" + ss);
}
}
});
【clear】
JButton btnNewButton_11 = new JButton("clear");
btnNewButton_11.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
y = x = (double) 0;
c = ' ';
s = "";
textField.setText(s);
textField_1.setText(s);
}
});
【delete】
JButton btnNewButton_10 = new JButton("d");
btnNewButton_10.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
s = s.substring(0, s.length() - 1);
textField.setText(s);
}
});