Results 1 to 3 of 3
- 01-20-2011, 07:48 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 2
- Rep Power
- 0
[EDIT:code tags added] Exception on a simple size converter
Hello everyone.
I'm relatively new to java and i'm studying it at school at the moment. As the thread name implies, i'm trying to create a small size converter, but there's a problem with the item listener assigned to the choice menu. After selecting another option it should update the string to the new value, but the string keeps a null value.What am i doing wrong? am i forgetting something around? i really can't see where's the error..
EDIT: sorry, didn't know that :o first time on a forum like this.
Well, i don't know where the error is, but it's probably inside the ConvertListener, so i'll just tag that one.
System.out lines are for debugging purposes :)Java Code:import java.awt.*; import java.awt.event.*; import java.lang.*; class ConvertListener implements ActionListener,ItemListener{ private TextField t_in; private TextField t_out; private String s; private double value; private float v; public ConvertListener(TextField t_in, TextField t_out){ this.t_in=t_in; this.t_out=t_out; } public void itemStateChanged(ItemEvent e){ Object x=e.getItem(); s=x.toString(); System.out.println(s); } public void actionPerformed(ActionEvent e){ String tb=e.getActionCommand(); System.out.println("s---->"s); System.out.println(tb); if(tb.equals("Cancel")){ t_in.setText(""); t_out.setText(""); } else if(tb.equals("Convert")){ System.out.println("Inside Convert"); value=Double.parseDouble(t_in.getText()); if(s.equals("Meters")){ System.out.println("Inside Meters"); value=value; } else if(s.equals("Decimeters")){ System.out.println("Inside Decimeters"); value=value/10; } else if(s.equals("Centimeters")){ System.out.println("Inside Centimeters"); value=value/100; } else if(s.equals("Millimeters")){ System.out.println("Inside Millimeters"); value=value/1000; } else { System.out.println("Always get here"); } t_out.setText(Double.toString(value)); } } }
Thanks in advance for any helpLast edited by Dado; 01-20-2011 at 08:23 PM. Reason: added code tags
- 01-20-2011, 08:13 PM #2
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
Code tags
I made the mistake of attaching my code to my question, but its not a good thing to do. You need to use the CODE tag. When writing the message, copy and paste the code in then select it and click in the Wrap code (#) button, this quotes the code nicely in the main thread.I don't think people will look at your code otherwise.
- 01-20-2011, 08:45 PM #3
Member
- Join Date
- Jan 2011
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Simple Swing throws Exception in thread "AWT-EventQueue-0"
By sultanofswing in forum AWT / SwingReplies: 3Last Post: 10-29-2010, 09:20 PM -
I need some help with converter GUI
By linux1man in forum AWT / SwingReplies: 5Last Post: 07-29-2009, 11:57 PM -
Simple Unit Converter help
By Black.Ice. in forum New To JavaReplies: 5Last Post: 06-24-2009, 08:57 PM -
Setting frame size to the size of an image
By Yoruichi in forum AWT / SwingReplies: 5Last Post: 04-22-2009, 04:37 PM -
Simple JSP page got exception by using cookies
By jurka in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 09-02-2008, 07:43 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks