428
register.setText(""+ result);
inputField.setText("");
}
}
static classClearHandler implementsActionListener
{
public voidactionPerformed(ActionEvent event)
{
result = 0.0;
register.setText("0.0");
inputField.setText("");
}
}
public static void main(String[] args)
{
operation = newNumericHandler();
clearOperation = newClearHandler();
result = 0.0;
resultLabel = newJLabel("Result:");
register = newJLabel("0.0", JLabel.RIGHT);
entryLabel = newJLabel("Enter #:");
inputField = newJTextField("", 10 );
add = newJButton("+");
subtract = newJButton("-");
clear = newJButton("Clear");
add.addActionListener(operation);
subtract.addActionListener(operation);
clear.addActionListener(clearOperation);
calcFrame = newJFrame();
calcFrame.setSize( 300 , 200 );