CSC 171 LAB #6

FALL 2001

 

GOAL:

1.        Become familiar with the JTextField input GUI component

2.        Become familiar with event based programming

 

TASKS:

 

·         Implement a JApplet that converts from Celsius to Fahrenheit and vice versa.

·         Demonstrate the program to your TA

 

 

BACKGROUND:

 

                This lab requires the use of integer methods and some the use of GUI components as well as the use of the action performed method of the JAVA abstract windowing toolkit (awt) event handlers. Review Figure 6.13 in D&D. Pay special attention to how the action listener is added to the JTextField. Also, consider how the actionPerformed method deals with input from the text field. You, of course, will need two JtextFields – one for Celsius and one for Fahrenheit.

 

STEPS:

 

1.        Read Chapter 6. Pay special attention to Example 6.13 – the fibonacci example.

2.        Implement an integer method celsius that returns the Celsius equivalent of a Fahrenheit temperature.

3.        Implement an integer method fahrenheit that returns the Fahrenheit equivalent of a Celsius temperature.

Using these two methods to write an applet that enables the user to enter either a Fahrenheit temperature and display the Celsius equivalent or enter a Celsius temperature and display the Fahrenheit equivalent.

4.        After writing the conversion methods, write the applet. Which should have two JtextFields for input, and two Labels for comment. Note that the JtextFields are used for both input and output. Look up the usage of the setText() method of the JTextField.

5.        This applet will require the two JTextField objects that have registered action events. When actionPerformed is invoked, the ActionEvent parameter has method getSource() to determine the GUI component with which the user interacted. Your actionPerformed metheod should contain an if/else structure of the form

if (e.getSource() == input1) {

            // process input1 interaction here

} else {

            //process input2 interaction here

}

// input1 and input2 are the two JTextField references

// the “e” in the Boolean clause of the if statement is the actionEvent

6.        Code and test the integrated method.

7.        Ok, you are done to get credit for all this work you need to get a piece of paper ready for your lab TA. This paper must have 2 things on it.

1.        Your name and lab section

2.        Your final version of the program with the pseudocode comments

8.        When you get the paper ready call your lab TA over and demo the program for her/him. Give the paper to your TA. This completes the hand in process. The deadline is one week – no late assignments accepted.

9.        The demo must run from your troi account – not the local machine.