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]

> new JFrame("Applet");<blinks />
Whats that mean?
STARZa at 2007-7-12 10:40:57 >

String s = String.valueOf(double);
> Whats that mean?Applet?
No GUI.
STARZa at 2007-7-12 10:40:57 >

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".
C:\ALEC.java:17: '.class' expected var = String.valueOf(double);^1 errorProcess completed.null
STARZa at 2007-7-12 10:40:57 >

> String.valueOf(double);That's the prototype. To make a double into a string:double var = ...;String s = String.valueOf(var);
Opps I meant String to Double.
STARZa at 2007-7-12 10:40:57 >

> Opps I meant String to Double.Have a look at the java.lang.Double class then.
double dd = Double.parseDouble(str);
jverda at 2007-7-12 10:40:57 >

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 >

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.
> What would be the code.> > String var=tf1.getText();> > to take this and make it to a double.See reply #11.
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.
Does it make me a barbarian to just do:double d = 1;String blah = "+" + d;Whats with all the valueOfs?
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!
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 >

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...
> Does it make me a barbarian to just do:> double d = 1;> String blah = "+" + d;> > Whats with all the valueOfs?Et tu, TuringPest?; )
Performed/PreformedI misspell that so much, I wrote a macro!
> Performed/Preformed> > I misspell that so much, I wrote a macro!Lol it worked thanks guys! :)
STARZa at 2007-7-21 21:24:34 >

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 >

> 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 >

I did,Thats the hole point of this topic.
STARZa at 2007-7-21 21:24:35 >

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 >

> 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 >

> I did,Thats the hole point of this topic.But isn't variable var (as in var += 100) a String? Should be a double.
Am I the only one who has no fucking idea what he/she is trying to do?
>>Now it realy works heres the code.WhewI think he finally got it ^^