Java Reference
In-Depth Information
The definition of the method actionPerformed is:
public void actionPerformed(ActionEvent e)
{
String resultStr;
//Step 1
String str
= String.valueOf(e.getActionCommand()); //Steps 1 and 2
char ch = str.charAt(0);
//Steps 1 and 3
switch (ch)
//Step 4
{
case '0':
//Step 4a
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (firstInput)
{
numStr1 = numStr1 + ch;
displayText.setText(numStr1);
}
else
{
numStr2 = numStr2 + ch;
displayText.setText(numStr2);
}
break ;
case '+':
//Step 4b
case '-':
case '*':
case '/':
op = ch;
firstInput = false ;
break ;
case '=':
//Step 4c
resultStr = evaluate();
displayText.setText(resultStr);
numStr1 = resultStr;
numStr2 = "";
firstInput = false ;
break ;
 
Search WWH ::




Custom Search