Results 1 to 7 of 7
Thread: tempreture program need help
- 01-27-2012, 07:49 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 8
- Rep Power
- 0
tempreture program need help
i m getting errors in this code kndly help me
import java.awt.*;
class temp extends Frame
{
Button b1,b2;
Label l1,l2;
TextField t1,t2;
public temp (String t)
{
super(t);
b2=new Button("CONVERT");
b2=new Button("CANCEL");
l2=new Label("TEMPRETURE IN C");
l1=new Label("TEMPRETURE IN F");
t1=new TextField("20");
t2=new TextField("20");
setLayout (new FlowLayout());
add(l1);
add(t1);
add(l2);
add(t2);
add(b1);
add(b2);
t2.setEditable(false);
setSize(500,500);
setVisible (true);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
float a=float.parseFloat(t1.getText());
float b;
b=(9/5*(a+32));
t2.setEditable(true);
t2.setText (String.valueOf(b));
t2.setEditable(false);
show();
}
if(e.getSource()==b2)
{
System.exit (0);
} } }Last edited by mdhmdh100; 01-28-2012 at 08:57 AM.
- 01-27-2012, 07:57 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,608
- Rep Power
- 5
Re: tempreture program need help
What errors? Compile time? Runtime? Post them in their entirety, and please wrap your code in the code tags.i m getting errors in this code kndly help me
- 01-28-2012, 08:55 AM #3
Member
- Join Date
- Jan 2012
- Posts
- 8
- Rep Power
- 0
- 01-28-2012, 09:03 AM #4
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 162
- Rep Power
- 2
Re: tempreture program need help
Thank you gentles..,
it is run time error..,
client and server get connected, then only making problems..,
- 01-28-2012, 11:43 AM #5
Member
- Join Date
- Jan 2012
- Posts
- 8
- Rep Power
- 0
Re: tempreture program need help
i m using JDK1.3 for this program
- 01-28-2012, 12:47 PM #6
Re: tempreture program need help
1) if you want to use addActionListener(this) the class temp must declare and implements the ActionListener. Remember that the ActionListener is in the package java.awt.event.ActionListener and using import java.awt.* the classes in java.awt.event will not be imported!
2) float is a primitive type and has not methods, so you can't use float.parseFloat() but Float.parseFloat() will work.
3) b1 is not initialized, so using add(b1) will throw a NullPointerException. b2 is initialized twice.
4) why is there a call to show()? it seems to be obsolete.Last edited by j2me64; 01-28-2012 at 12:51 PM.
- 01-28-2012, 03:05 PM #7
Member
- Join Date
- Jan 2012
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
How to code a program to send messages to a chat program?
By josh2992 in forum New To JavaReplies: 2Last Post: 04-02-2011, 12:57 PM -
How would I open a program from a single button of another program. Help...
By decgaid06 in forum New To JavaReplies: 13Last Post: 03-22-2011, 06:49 AM -
changing my program to array working program
By Chewart in forum New To JavaReplies: 39Last Post: 11-18-2009, 06:53 PM -
How to execute an External Program through Java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:40 PM -
How to execute an External Program through Java program
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:33 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks