Results 1 to 7 of 7
  1. #1
    mdhmdh100 is offline Member
    Join Date
    Jan 2012
    Posts
    8
    Rep Power
    0

    Default 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.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default Re: tempreture program need help

    i m getting errors in this code kndly help me
    What errors? Compile time? Runtime? Post them in their entirety, and please wrap your code in the code tags.

  3. #3
    mdhmdh100 is offline Member
    Join Date
    Jan 2012
    Posts
    8
    Rep Power
    0

    Default Re: tempreture program need help

    Quote Originally Posted by doWhile View Post
    What errors? Compile time? Runtime? Post them in their entirety, and please wrap your code in the code tags.
    compile time errors

  4. #4
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    236
    Rep Power
    3

    Default Re: tempreture program need help

    Thank you gentles..,
    it is run time error..,
    client and server get connected, then only making problems..,

  5. #5
    mdhmdh100 is offline Member
    Join Date
    Jan 2012
    Posts
    8
    Rep Power
    0

    Default Re: tempreture program need help

    i m using JDK1.3 for this program

  6. #6
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default 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.

  7. #7
    mdhmdh100 is offline Member
    Join Date
    Jan 2012
    Posts
    8
    Rep Power
    0

    Default Re: tempreture program need help

    Quote Originally Posted by j2me64 View Post
    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.
    thats great thanx a lot

Similar Threads

  1. Replies: 2
    Last Post: 04-02-2011, 12:57 PM
  2. Replies: 13
    Last Post: 03-22-2011, 06:49 AM
  3. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 06:53 PM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •