• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

toString() method

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);


}
}
 
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String.valueOf(anInt);
 
Henas Cirtak
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You Rock!! Thank you!!!
 
Do you pee on your compost? Does this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic