wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes toString() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "toString() method" Watch "toString() method" New topic
Author

toString() method

Henas Cirtak
Greenhorn

Joined: Oct 02, 2004
Posts: 10
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

Joined: Feb 02, 2002
Posts: 1211

String.valueOf(anInt);
Henas Cirtak
Greenhorn

Joined: Oct 02, 2004
Posts: 10
You Rock!! Thank you!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: toString() method