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

Start a new topic
Add Reply




MultiQuote

| 


