School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,132 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,930 people online right now. Registration is fast and FREE... Join Now!



Doesn't work, take a look plz?

Doesn't work, take a look plz? Rate Topic: -----

#1 ShadowReborn  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 2
  • Joined: 27-May 09


Dream Kudos: 0

Post icon  Posted 02 June 2009 - 05:33 AM

Humm, im a newbie and need some help. I just added some more new stuff into my actionPerformed method, I think it should work but it doesn't work somehow... can someone tell me where i did wrong please? thank you

this is just a converter that has buttons where u press to convert cm into inches etc.

The part that doesn't work is that, after i press convert button, it gives me a lot of erros, this is what it shows after i input my number into the first box .... it doesn't convert it into anything , does nothing
and give me these after i press the buttons

Exception in thread "AWT-EventQueue-1" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:468)
at java.lang.Integer.parseInt(Integer.java:497)
at Final.actionPerformed(Final.java:94)
at java.awt.Button.processActionEvent(Button.java:392)
at java.awt.Button.processEvent(Button.java:360)
at java.awt.Component.dispatchEventImpl(Component.java:4501)
at java.awt.Component.dispatchEvent(Component.java:4331)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)


Here's the code i have
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Final extends Applet implements ActionListener {
	
	Button c1,c2,c3,c4;
	TextField i1,i2,i3,i4,o1,o2,o3,o4;
	int a,b,c,d;
	long e,f,g,h;
	
	
	public void init() {
		setLayout(null);
		
		c1 = new Button("Convert");
		c2 = new Button("Convert");
		c3 = new Button("Convert");
		c4 = new Button("Convert");
		
		i1 = new TextField(10);
		i2 = new TextField(10);
		i3 = new TextField(10);
		i4 = new TextField(10);
		
		o1 = new TextField(10);
		o2 = new TextField(10);
		o3 = new TextField(10);
		o4 = new TextField(10);
		
		o1.setEditable(false);
		o2.setEditable(false);
		o3.setEditable(false);
		o4.setEditable(false);
		
		c1.setBounds(200,40,50,25);
		c2.setBounds(200,80,50,25);
		c3.setBounds(200,120,50,25);
		c4.setBounds(200,160,50,25);
		
		i1.setBounds(20,40,50,25);
		i2.setBounds(20,80,50,25);
		i3.setBounds(20,120,50,25);
		i4.setBounds(20,160,50,25);
		
		o1.setBounds(100,40,50,25);
		o2.setBounds(100,80,50,25);
		o3.setBounds(100,120,50,25);
		o4.setBounds(100,160,50,25);
		
		c1.addActionListener(this);
		c2.addActionListener(this);
		c3.addActionListener(this);
		c4.addActionListener(this);
		
		add(c1);
		add(c2);
		add(c3);
		add(c4);
		
		add(i1);
		add(i2);
		add(i3);
		add(i4);
		
		add(o1);
		add(o2);
		add(o3);
		add(o4);
	}

	public void paint(Graphics g) {
		g.drawString("Converter",300,20);
		g.drawString("Centimeters to Inches",20,40);
		g.drawString("Inches to Centimeters",20,80);
		g.drawString("Inches to Feet",20,120);
		g.drawString("Feet to Inches",20,160);
	}
	
		public void actionPerformed(ActionEvent event){
		int a = Integer.parseInt( i1.getText() );
		int b = Integer.parseInt( i2.getText() );
		int c = Integer.parseInt( i3.getText() );
		int d = Integer.parseInt( i4.getText() );
		
		e = a*3.9;
		f = b/3.9;
		g = c*12;
		h = d/12;
		
		o1.setText(""+e+"In");
		o2.setText(""+f+"Cm");
		o3.setText(""+g+"Ft");
		o4.setText(""+h+"In");
								}
}


This post has been edited by ShadowReborn: 02 June 2009 - 05:38 AM

Was This Post Helpful? 0
  • +
  • -


#2 PsychoCoder  Icon User is offline

  • apt-get install DIC.bin
  • Icon
  • View blog
  • Group: Admins
  • Posts: 16,211
  • Joined: 26-July 07


Dream Kudos: 12400

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

Posted 02 June 2009 - 05:34 AM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#3 masteryee  Icon User is offline

  • D.I.C Regular
  • PipPipPip
  • Group: Members
  • Posts: 271
  • Joined: 16-May 09


Dream Kudos: 0

Posted 02 June 2009 - 08:07 AM

Looks like one of your parseInt calls is failing because you're leaving one of the textboxes blank. You either need to add your code to a try/catch block to handle the exception, or put it in an if statement that checks to make sure all the textboxes have a value in them before you convert them to an integer. If one of the boxes is empty, you may want to consider displaying a warning message to the user, something like "Please enter an integer in all textboxes before continuing".
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month