+
、-
または操作が発生したときに操作文字列を戻して、*
操作として保存し、押したときに移動できるようにすることは可能=
ですか、それとも単に不可能ですか?
コードパート 1:
public void actionPerformed(ActionEvent calculate)
{
JButton operand = (JButton) calculate.getSource();
String flip = operand.getLabel();
String operation = "";
System.out.println(operation);
String value1 = (box1.getText());
String value2 = (box2.getText());
box1.setText(box1.getText() + operand.getLabel());
if (flip.equals("C"))
{
box2.setText("");
box1.setText("");
}
if (flip.equals("!"))
{
int intValueNeg = Integer.parseInt(value1);
int negateIntValue = intValueNeg * (-1);
String negativeInt = Integer.toString(negateIntValue);
box1.setText(negativeInt);
}
if (flip.equals("+"))
{
box2.setText(value1);
box1.setText("");
operation = operand.getLabel();
}
if (flip.equals("-"))
{
box2.setText(value1);
box1.setText("");
operation = operand.getLabel();
}
if (flip.equals("*"))
{
box2.setText(value1);
box1.setText("");
operation = operand.getLabel();
}
if (flip.equals("=") && operation.equals("+"))
{
int intValue1 = Integer.parseInt(value1);
int intValue2 = Integer.parseInt(value2);
int totalValue = intValue1 + intValue2;
String totalResult = Integer.toString(totalValue);
box1.setText(totalResult);
box2.setText("0");
}
if (flip.equals("=") && operation.equals("-"))
{
int intValue1 = Integer.parseInt(value1);
int intValue2 = Integer.parseInt(value2);
int totalValue = intValue2 - intValue1;
String totalResult = Integer.toString(totalValue);
box1.setText(totalResult);
box2.setText("0");
}
if (flip.equals("=") && operation.equals("*"))
{
int intValue1 = Integer.parseInt(value1);
int intValue2 = Integer.parseInt(value2);
int totalValue = intValue1 * intValue2;
String totalResult = Integer.toString(totalValue);
box1.setText(totalResult);
box2.setText("0");
}
}
}
コードパート 2:
box2 = new JTextField (10);
b.add(box2);
Blackbelt.add(a, BorderLayout.NORTH);
Blackbelt.add(c, BorderLayout.CENTER);
Blackbelt.add(b, BorderLayout.SOUTH);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);