SRL Archive - Java Help and Tutorials

im confussed


Awkwardsaw

2010-02-23 21:52:48

i know it seems silly, but how do you use tostring()? the way im using it doesnt seem to work. :(

i get some "cannot find symbol" error with tostring()

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
int in1 = Integer.parseInt(jTextField1.getText());
int in2 = Integer.parseInt(jTextField2.getText());
int in3 = in1 + in2;
jLabel1.setText(tostring(in3));//error here: cannot find symbol tostring
}

google hasnt helped me =\

Method

2010-02-23 21:54:57

http://java.sun.com/javase/6/docs/api/java/lang/Object.html#toString%28%29

That should explain toString for you. Basically, it's what is called when you convert an object to a String, for example when you print it out. System.out.println(object.toString()); should give you the same result as System.out.println(object);.

You probably want to do something like jLabel1.setText(String.valueOf(in3));.

Awkwardsaw

2010-02-23 21:57:03

From: Method
http://java.sun.com/javase/6/docs/api/java/lang/Object.html#toString%28%29

That should explain toString for you. Basically, it's what is called when you convert an object to a String, for example when you print it out. System.out.println(object.toString()); should give you the same result as System.out.println(object);.

You probably want to do something like jLabel1.setText(String.valueOf(in3));.


thanks you :)

for some reason i can never find my answers on java.sun, although i know they're there :o

noidea

2010-02-23 22:06:14

also. its Object.toString();
so like

Object lol = new Object();//I think. I havent used Object like this before o_O (Just setting it up)
lol = 44444;
System.out.println(lol.toString());

I think that works

LolL

2010-02-25 23:19:47

Let me just state a very, very important characteristic of Java that caused your problem and might cause you more: it is case-sensitive. Therefore, toString is not the same as tostring, nor is Object the same as object. This might be a bit tricky since Pascal is case-insensitive, but all present or major programming languages are case-sensitive so you gotta get that habit going. :)

By the way, you might want to name your variables and methods more properly or that code is going to confuse the hell out of you later on. :P

Baked0420

2010-02-25 23:26:07

By the way, you might want to name your variables and methods more properly or that code is going to confuse the hell out of you later on. :P

yea it was different at first when I first started learning java and c++ to have it case-sensitive since pascal's not that way.

(EDIT:misread a post)

Method

2010-02-25 23:46:10

From: Baked0420
yea it was different at first when I first started learning java and c++ to have it case-sensitive since pascal's not that way. And LolL you said pascal is case-sensitive, but I think you meant not.


He said 'case-insensitive', not case sensitive.

mormonman

2010-02-25 23:54:21

Go read some stuff about OOP. It will help you mucho.