Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By Fubarable

Thread: converter

  1. #1
    fasooly1992 is offline Member
    Join Date
    Dec 2012
    Rep Power

    Default converter

    Hi Iam new to java currently i am studying at college and my instructor want a project i found a converter program and want to add to it but it seems
    that i have a problem and i cant figure out how to fix it

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    public class FahrenheitPanel extends JPanel
    private JLabel inputLabel, outputLabel, resultLabel;
    private JTextField fahrenheit;
    private JTextField celsius;
    private JLabel inputLabel1, outputLabel1, resultLabel1;

    // Constructor: Sets up the main GUI components.
    public FahrenheitPanel()
    inputLabel = new JLabel ("Enter Fahrenheit temperature:");
    outputLabel = new JLabel ("Temperature in Celsius: ");
    resultLabel = new JLabel ("---");
    inputLabel1 = new JLabel ("Enter celsius temperature:");
    outputLabel1 = new JLabel ("Temperature in farhenhiet:");
    resultLabel1 = new JLabel ("---");

    fahrenheit = new JTextField (5);
    fahrenheit.addActionListener (new TempListener());
    celsius = new JTextField (5);
    celsius.addActionListener (new TempListener1()); here I have my problem cant find symbol for TempListener

    add (inputLabel);
    add (fahrenheit);
    add (outputLabel);
    add (resultLabel);

    add (inputLabel1);
    add (celsius);
    add (outputLabel1);
    add (resultLabel1);

    setPreferredSize (new Dimension(300, 75));
    setBackground (;

    //************************************************** ***************
    // Represents an action listener for the temperature input field.
    //************************************************** ***************
    private class TempListener implements ActionListener
    // Performs the conversion when the enter key is pressed in
    // the text field.
    public void actionPerformed (ActionEvent event)
    int fahrenheitTemp, celsiusTemp;

    String text = fahrenheit.getText();

    fahrenheitTemp = Integer.parseInt (text);

    celsiusTemp = (fahrenheitTemp-32) * 5/9;

    resultLabel.setText (Integer.toString (celsiusTemp));

    private class TempListener1 implements ActionListener
    // Performs the conversion when the enter key is pressed in
    // the text field.
    public void actionperformed (ActionEvent event)

    int celsiusTemp, fahrenhietTemp;

    String text = celsius.getText();

    celsiusTemp = Integer.parseInt (text);

    fahrenheitTemp = (celsiusTemp1+32) * 9/5;

    resultLabel1.setText (Integer.toString (fahrenheit));

    ps i want to add more to it like more things to convert so please if anybody can help
    Last edited by fasooly1992; 12-25-2012 at 04:57 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

    Default Re: converter

    May I suggest that rather than trying to fix "found" code (or worse, asking others to fix found code for you), that you instead write the code yourself from the ground up. Yes, this will give you an immeasurable improved understanding of Java and of your program.
    DarrylBurke likes this.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: converter

    Whenever I read 'Fahrenheit/Celcius conversion' I always think 'integer division'; but that's just me ...

    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Converter Class
    By FOX427 in forum New To Java
    Replies: 3
    Last Post: 05-28-2012, 03:49 AM
  2. I need some help with converter GUI
    By linux1man in forum AWT / Swing
    Replies: 5
    Last Post: 07-29-2009, 11:57 PM
  3. usb to serial converter
    By freezy in forum Advanced Java
    Replies: 2
    Last Post: 03-18-2009, 10:48 AM
  4. sound converter WAV to AU
    By Unome in forum Java Applets
    Replies: 5
    Last Post: 03-14-2009, 10:25 AM
  5. YaHP Converter 1.2.12
    By levent in forum Java Software
    Replies: 0
    Last Post: 06-12-2007, 08:49 AM

Posting Permissions

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