How do you make a double to a string

I have a GUI program and I need to take whats in the text box and +,-,*,/ it an I need it to be a varable to do this so how can I.

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

publicclass ALEC{

publicstaticvoid main(String args[])

{

JFrame f1=new JFrame("Applet");

JTextField tf1=new JTextField(10);

JButton b1=new JButton("Click Here");

JLabel l1=new JLabel(" ");

JPanel p1=new JPanel();

b1.addActionListener(new ActionListener(){

publicvoid actionPreformed(ActionEvent ae){

String var=tf1.getText();

Double var2=Double.parseDouble(var);

l1.setText(var2);

}

});

f1.setSize(300,300);

p1.add(tf1);

p1.add(b1);

p1.add(l1);

f1.add(p1);

f1.setVisible(true);

}

}

[1689 byte] By [STARZa] at [2007-11-27 5:17:59]
# 1
> new JFrame("Applet");<blinks />
Hippolytea at 2007-7-12 10:40:57 > top of Java-index,Java Essentials,New To Java...
# 2
Whats that mean?
STARZa at 2007-7-12 10:40:57 > top of Java-index,Java Essentials,New To Java...
# 3
String s = String.valueOf(double);
prometheuzza at 2007-7-12 10:40:57 > top of Java-index,Java Essentials,New To Java...
# 4
> Whats that mean?Applet?
Hippolytea at 2007-7-12 10:40:57 > top of Java-index,Java Essentials,New To Java...
# 5
No GUI.
STARZa at 2007-7-12 10:40:57 > top of Java-index,Java Essentials,New To Java...
# 6
I think we're posting past each other. I was just making a joke abouta JFrame titled "Applet". That's like calling your dog "p-u-s-s-y".
Hippolytea at 2007-7-12 10:40:57 > top of Java-index,Java Essentials,New To Java...
# 7
C:\ALEC.java:17: '.class' expected var = String.valueOf(double);^1 errorProcess completed.null
STARZa at 2007-7-12 10:40:57 > top of Java-index,Java Essentials,New To Java...
# 8
> String.valueOf(double);That's the prototype. To make a double into a string:double var = ...;String s = String.valueOf(var);
Hippolytea at 2007-7-12 10:40:57 > top of Java-index,Java Essentials,New To Java...
# 9
Opps I meant String to Double.
STARZa at 2007-7-12 10:40:57 > top of Java-index,Java Essentials,New To Java...
# 10
> Opps I meant String to Double.Have a look at the java.lang.Double class then.
prometheuzza at 2007-7-12 10:40:57 > top of Java-index,Java Essentials,New To Java...
# 11
double dd = Double.parseDouble(str);
jverda at 2007-7-12 10:40:57 > top of Java-index,Java Essentials,New To Java...
# 12
What would be the code.String var=tf1.getText();to take this and make it to a double.
STARZa at 2007-7-12 10:40:57 > top of Java-index,Java Essentials,New To Java...
# 13
String to double:double var = Double.parseDouble(str);String to java.lang.Double:Double obj = Double.valueOf(str);Prefer the primitive double because it's simpler, unless you have a reason to use java.lang.Double.
Hippolytea at 2007-7-12 10:40:57 > top of Java-index,Java Essentials,New To Java...
# 14
> What would be the code.> > String var=tf1.getText();> > to take this and make it to a double.See reply #11.
prometheuzza at 2007-7-12 10:40:57 > top of Java-index,Java Essentials,New To Java...
# 15
How do I hope all this Double arcana? I look it up in the API! http://java.sun.com/javase/6/docs/api/java/lang/Double.htmlThere, now you know as much as the rest of us.
Hippolytea at 2007-7-21 21:24:34 > top of Java-index,Java Essentials,New To Java...
# 16
Does it make me a barbarian to just do:double d = 1;String blah = "+" + d;Whats with all the valueOfs?
TuringPesta at 2007-7-21 21:24:34 > top of Java-index,Java Essentials,New To Java...
# 17

Hmmm... I just reminded myself of a rather handy word:

Arcana

1. Plural form of arcanum.

2. Specialized knowledge that is mysterious to the uninitiated.

3. A secret essence or remedy; an elixir.

I'm going to use that three times today, and the word will be mine!

Hippolytea at 2007-7-21 21:24:34 > top of Java-index,Java Essentials,New To Java...
# 18

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.lang.Double.*;

public class ALEC{

public static void main(String args[])

{

JFrame f1=new JFrame("Applet");

final JTextField tf1=new JTextField(10);

JButton b1=new JButton("Click Here");

final JLabel l1=new JLabel(" ");

JPanel p1=new JPanel();

b1.addActionListener(new ActionListener(){

public void actionPreformed(ActionEvent ae){

String var=tf1.getText();

Double var2=Double.parseDouble(var);

l1.setText(var);

}

});

f1.setSize(300,300);

p1.add(tf1);

p1.add(b1);

p1.add(l1);

f1.add(p1);

f1.setVisible(true);

}

}

--Configuration: <Default>--

C:\ALEC.java:15: <anonymous ALEC$1> is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener

b1.addActionListener(new ActionListener(){

^

1 error

Process completed.

STARZa at 2007-7-21 21:24:34 > top of Java-index,Java Essentials,New To Java...
# 19
I think the use of "" + d predates the introduction of many of the valueOf methods.I like my code to be mean what it says. Appending with an empty string, well...
Hippolytea at 2007-7-21 21:24:34 > top of Java-index,Java Essentials,New To Java...
# 20
> Does it make me a barbarian to just do:> double d = 1;> String blah = "+" + d;> > Whats with all the valueOfs?Et tu, TuringPest?; )
prometheuzza at 2007-7-21 21:24:34 > top of Java-index,Java Essentials,New To Java...
# 21
Performed/PreformedI misspell that so much, I wrote a macro!
Hippolytea at 2007-7-21 21:24:34 > top of Java-index,Java Essentials,New To Java...
# 22
> Performed/Preformed> > I misspell that so much, I wrote a macro!Lol it worked thanks guys! :)
STARZa at 2007-7-21 21:24:34 > top of Java-index,Java Essentials,New To Java...
# 23
How do I add 200 to the var.If I type in 100 i get 100 100 instead of 200 var+=100;
STARZa at 2007-7-21 21:24:34 > top of Java-index,Java Essentials,New To Java...
# 24
> How do I add 200 to the var.> > If I type in 100 i get > 100 100 > instead of 200 > > var+=100;You're concatenating Strings. You need to convert those Strings to ints or doubles or something.
jverda at 2007-7-21 21:24:34 > top of Java-index,Java Essentials,New To Java...
# 25
or something indeed.
TuringPesta at 2007-7-21 21:24:35 > top of Java-index,Java Essentials,New To Java...
# 26
I did,Thats the hole point of this topic.
STARZa at 2007-7-21 21:24:35 > top of Java-index,Java Essentials,New To Java...
# 27

Now it realy works heres the code.

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.lang.Double.*;

public class ALEC{

public static void main(String args[])

{

JFrame f1=new JFrame("Applet");

final JTextField tf1=new JTextField(10);

JButton b1=new JButton("Click Here");

final JLabel l1=new JLabel(" ");

JPanel p1=new JPanel();

b1.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent ae){

String var=tf1.getText();

Double var2=Double.parseDouble(var);

var2+=100;

String s = String.valueOf(var2);

l1.setText(s);

}

});

f1.setSize(300,300);

p1.add(tf1);

p1.add(b1);

p1.add(l1);

f1.add(p1);

f1.setVisible(true);

}

}

STARZa at 2007-7-21 21:24:35 > top of Java-index,Java Essentials,New To Java...
# 28

> I did,Thats the hole point of this topic.

String str1 = "100";

String str2 = "100;

int int1 = Integer.valueOf(str1);

int int2 = Integer.valueOf(str2);

System.out.println(str1 + str2); // 100100

System.out.println(int1 + int2); // 200

jverda at 2007-7-21 21:24:35 > top of Java-index,Java Essentials,New To Java...
# 29
> I did,Thats the hole point of this topic.But isn't variable var (as in var += 100) a String? Should be a double.
Hippolytea at 2007-7-21 21:24:35 > top of Java-index,Java Essentials,New To Java...
# 30
Am I the only one who has no fucking idea what he/she is trying to do?
floundera at 2007-7-21 21:24:40 > top of Java-index,Java Essentials,New To Java...
# 31
>>Now it realy works heres the code.WhewI think he finally got it ^^
lethalwirea at 2007-7-21 21:24:40 > top of Java-index,Java Essentials,New To Java...