4 Replies - 739 Views - Last Post: 10 April 2012 - 11:36 AM Rate Topic: -----

#1 zero172  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-April 12

I am lost in what this assignment is asking me to do.

Posted 10 April 2012 - 08:17 AM

You will rewrite the temperature conversion program from the previous week. Your GUI application must inherit from the JFrame class. The GUI and event handling setup should be done in the constructor. Do not use any of the GUI editing capabilities of Eclipse for this assignment. The temperature conversion application should have a label and JTextField in which the user inputs a value which must appear in the upper part of the frame. There should be a set of three radio buttons which indicate the input scale of the value to be converted.

There should also be a set of three radio buttons which indicate the output scale to be converted to. The three input scale buttons must appear vertically aligned (i.e., use a JPanel) on the left side of the display, and the three output scale buttons must appear vertically aligned (i.e., use another JPanel) and appear on the right side of the display. Event handling should be set up so that selection of any input or output radio button causes an event which triggers the event handling code to determine which of nine possible conversions is needed. You can display the result in an output text field or in a Jlabel which appears in the bottom part of the display.

Your program should accurately convert from Fahrenheit, Celsius, Kelvin to Fahrenheit, Celsius, Kelvin. NOTE: Only the selected conversion is displayed in the output area!!! When the conversion selection changes, the output area should change to show only the new result. The output should display three digits after the decimal point. HINT: Use the ItemListener interface and use the isSelected method on the radio buttons to learn which buttons are turned on!

This is my code from last week:







	 import java.awt.*;  

	import java.awt.event.*;  

	 import javax.swing.*;  

	 import java.text.DecimalFormat;  

	    

	 @SuppressWarnings("serial")  

	 public class  Temp1 extends JFrame  

	 implements ActionListener {  

	 private JButton button1, button2, button3, button4, button5, button6;  

	 @SuppressWarnings("unused")  

	 private JPanel panel;  

	 @SuppressWarnings("unused")  

	 private JFrame frame;  

	 @SuppressWarnings("unused")  

	 private JTextField Text;  

	 @SuppressWarnings("unused")  

	 private JLabel label;  

	 private JTextField infield = new JTextField(10);  

	 private JTextField outfield = new JTextField(10);  

	 private JLabel inlabel = new JLabel("Enter Input Value Here:");  

	 private JLabel outlabel = new JLabel("Converted Temperature Output:");  

	    

	 DecimalFormat three = new DecimalFormat("0.000");  

	

	 public static void main(String[] args) {  

	     Temp1 frame = new Temp1();  

	     frame.createFrame();  

	     frame.createButton1();  

	     frame.createButton2();  

	     frame.createButton3();  

	     frame.createButton4();  

	     frame.createButton5();  

	     frame.createButton6();  

	     frame.addLabels();  

	     }  

    

	 public void createFrame() {  

	    Container window = getContentPane();  

	     window.setLayout(new FlowLayout() );   

	     setSize(600, 400);    

	     setVisible(true);   

	     setTitle("Temperature Converter Application");   

	     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   

	     panel = new JPanel(new GridLayout());  

	     add(new JLabel("Temperature Conversions:"+ " C: Celsius"+ " F: Farhrenheit"+ " K: Kelvin"));   

	     }  

	

	 public void createButton1() {  

	 

	     button1 = new JButton("F-to-C");  

	     add(button1);  

	     button1.addActionListener((ActionListener) this); 

	     }  

	   

	 public void createButton2() {  

	  

	    button2 = new JButton("C-to-F");  

	    add(button2);   

	     button2.addActionListener((ActionListener) this);  

	    }  

	   

	 public void createButton3() {  

 

	    button3 = new JButton("K-to-C");  

	     add(button3);   

	     button3.addActionListener((ActionListener) this); 

	    }  

	

	 public void createButton4() {  

	  

	     button4 = new JButton("C-to-K");  

	     add(button4);   

	     button4.addActionListener((ActionListener) this);  

	     }  

	

	 public void createButton5() {  

	  

	     button5 = new JButton("K-to-F");  

	     add(button5);   

	     button5.addActionListener((ActionListener) this);  

	     }  

	

	 public void createButton6() {  

	  

	    button6 = new JButton("F-to-K");  

	     add(button6);  

	     button6.addActionListener((ActionListener) this);  

	     }  

	

	 public void addLabels() {  

	     add(inlabel);  

	     add(infield);  

	     add(outlabel);  

	     add(outfield);  

	     outfield.setEditable(false);  

	     }  

	    

	 public void actionPerformed(ActionEvent i) {   

	     int temp;  

	     double newtemp = 0;  

	    String inputString;  

	     inputString = infield.getText();  

	     temp = Integer.parseInt(inputString);  

	        

	     if(i.getSource() == button1) {  

	         newtemp = (5.0/9.0) * (temp - 32); 

	     }  

	     else if(i.getSource() == button2) {  

	         newtemp = ((9.0/5.0) * temp) + 32;  

	     }  

	    else if(i.getSource() == button3) {  

	         newtemp = temp - 273;  

	    }  

	    else if(i.getSource() == button4) {  

	         newtemp = temp + 273; 

	    }  

	     else if(i.getSource() == button5) {  

	         newtemp = ((temp - 273) * (9.0/5.0)) + 32; 

	     }  

	     else {  

	         newtemp = (5.0/9.0) * (temp - 32) + 273;  

	     }  

	     outfield.setText(" "+ three.format(newtemp));  

	     }  

	    }


MOD EDIT: Added code tags. When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 10 April 2012 - 11:35 AM


Is This A Good Question/Topic? 0
  • +

Replies To: I am lost in what this assignment is asking me to do.

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5480
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: I am lost in what this assignment is asking me to do.

Posted 10 April 2012 - 08:35 AM

View Postzero172, on 10 April 2012 - 09:17 AM, said:

I am lost in what this assignment is asking me to do.

You will rewrite the temperature conversion program from the previous week. Your GUI application must inherit from the JFrame class. The GUI and event handling setup should be done in the constructor. Do not use any of the GUI editing capabilities of Eclipse for this assignment. The temperature conversion application should have a label and JTextField in which the user inputs a value which must appear in the upper part of the frame. There should be a set of three radio buttons which indicate the input scale of the value to be converted.

There should also be a set of three radio buttons which indicate the output scale to be converted to. The three input scale buttons must appear vertically aligned (i.e., use a JPanel) on the left side of the display, and the three output scale buttons must appear vertically aligned (i.e., use another JPanel) and appear on the right side of the display. Event handling should be set up so that selection of any input or output radio button causes an event which triggers the event handling code to determine which of nine possible conversions is needed. You can display the result in an output text field or in a Jlabel which appears in the bottom part of the display.

Your program should accurately convert from Fahrenheit, Celsius, Kelvin to Fahrenheit, Celsius, Kelvin. NOTE: Only the selected conversion is displayed in the output area!!! When the conversion selection changes, the output area should change to show only the new result. The output should display three digits after the decimal point. HINT: Use the ItemListener interface and use the isSelected method on the radio buttons to learn which buttons are turned on!


Those are really clear instructions. I've seen a lot worse for homework assignments. Its very precise about where everything should be laid out etc. What part of it do you not understand?
Was This Post Helpful? 0
  • +
  • -

#3 zero172  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-April 12

Re: I am lost in what this assignment is asking me to do.

Posted 10 April 2012 - 08:47 AM

I am lost on how to rewrite the code
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5480
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: I am lost in what this assignment is asking me to do.

Posted 10 April 2012 - 08:58 AM

90% or more of the problems we see here on homework assignments is because students don't stop and plan nor block out their code into logical segments.
Read this article to get started on the right foot:
This is the 'Help me with my homework' article you wanted.
Was This Post Helpful? 1
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: I am lost in what this assignment is asking me to do.

Posted 10 April 2012 - 11:36 AM

You might start by knowing what language you're programing in. This code is JAVA not Javascript, where you posted. Two totally different animals.

Moved to Java.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1