Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

toString() method

 
Henas Cirtak
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK... I'm seriously stuck. I can't seem to figure out how to convert an int to a String. I'm using the toString() method but can't seem to get it to work. What am I doing wrong???


import java.applet.*;
import java.awt.event.*;
import java.awt.*;

public class DoubleInteger extends Applet implements ActionListener
{
TextField info = new TextField(20);
Label answer = new Label("The Answer");
Button pressMe = new Button("Press Me");
int dInfo;
int doubleInfo;
String finalAnswer;


public void init()
{
add(info);
add(pressMe);
pressMe.addActionListener(this);
add(answer);
invalidate();
validate();

}

public void actionPerformed(ActionEvent e)
{
String x = info.getText();



int anInt = Integer.parseInt(x);
int theAnswer = anInt * 2;
System.out.println(theAnswer);

finalAnswer = theAnswer.toString();
answer.setText(finalAnswer);


}
}
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String.valueOf(anInt);
 
Henas Cirtak
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You Rock!! Thank you!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic