Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a Java Expert!

Join 306,807 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,662 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?

ShadowReborn

2 Jun, 2009 - 05:33 AM
Post #1

New D.I.C Head
*

Joined: 27 May, 2009
Posts: 2

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
CODE

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: 2 Jun, 2009 - 05:38 AM

User is offlineProfile CardPM
+Quote Post


PsychoCoder

RE: Doesn't Work, Take A Look Plz?

2 Jun, 2009 - 05:34 AM
Post #2

I Code, Therefore I am
Group Icon

Joined: 26 Jul, 2007
Posts: 14,919



Thanked: 517 times
Dream Kudos: 11525
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

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

User is offlineProfile CardPM
+Quote Post

masteryee

RE: Doesn't Work, Take A Look Plz?

2 Jun, 2009 - 08:07 AM
Post #3

D.I.C Regular
***

Joined: 16 May, 2009
Posts: 269



Thanked: 38 times
My Contributions
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".
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/20/09 09:48PM

Live Java Help!

Be Social

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

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month