private JTextField resultTextField;
resultTextField.setText(" "); ...
private class InputListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Stack<Integer> operandStack = new Stack<Integer>();
Stack<Character> operatorStack = new Stack<Character>();
String input = inputTextField.getText();
StringTokenizer strToken = new StringTokenizer(input, " ", false);
while (strToken.hasMoreTokens())
{
String i = strToken.nextToken();
int operand;
char operator;
try
{
operand = Integer.parseInt(i);
operandStack.push(operand);
}
catch (NumberFormatException nfe)
{
operator = i.charAt(0);
operatorStack.push(operator);
}
}
int result = sum (operandStack, operatorStack);
resultTextField.setText(result);
The last line that reads: "resultTextField.setText(result);" in the code provided, I'm trying to convert the 'result' variable to a String but having no success. The compile error message I get is:
PrefixExpression.java:96: error: method setText in class JTextComponent cannot be applied to given types; resultTextField.setText(result); ^ required: String found: int reason: actual argument int cannot be converted to String by method invocation conversion.
I've tried several methods already provided in answers to other 'convert int to String' questions in here, but none of them work. How do I convert 'result' to a String? Thanks for your help.