[Java Programming] - 500 word essay

itstbn10
myFrame.java

import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class myFrame extends JFrame implements ActionListener { // Frame width and height. private final int FRAME_WIDTH = 460; private final int FRAME_HEIGHT = 200; // label objects. private JLabel heading; private JLabel prompt; private JLabel celcius; // button objects. private JButton myButton; // Text feild objects. private JTextField myTextField; public myFrame() { // setting up the frame. JFrame myFrm = new JFrame("Temperature Conventer"); // create object frame with title bar myFrm.setSize(FRAME_WIDTH, FRAME_HEIGHT); // sets the size of the frame myFrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // exit program when user clicks close button myFrm.setResizable(false); // makes frame not resizable. myFrm.getContentPane().setBackground(Color.GRAY); // sets background to gray. myFrm.setLocationRelativeTo(null); // makes the frame at center. // heading label heading = new JLabel("Enter Degrees in Fehrenheit to get it in Celcius"); heading.setFont(new Font("Arial", Font.BOLD, 20)); myFrm.add(heading); // prompt label prompt = new JLabel("Enter Fehrenheit:"); prompt.setFont(new Font("Arial", Font.BOLD, 18)); myFrm.add(prompt); // Text feild myTextField = new JTextField("Enter a degree in fehrenheit", 15); myFrm.add(myTextField); // button myButton = new JButton("Click here to continue"); myButton.setToolTipText("Begin Conversion!"); myButton.addActionListener(this); myFrm.add(myButton); // celcius label. celcius = new JLabel(""); Font myFont = new Font("Arial", Font.BOLD, 15); celcius.setFont(myFont); myFrm.add(celcius); // set layout to default and make the frame visible. FlowLayout myFlow = new FlowLayout(); myFrm.setLayout(myFlow); myFrm.setVisible(true); } // convert - This function will convert // degrees in fehrenheit to celcius. public int convert(int feh) { return (feh-32)* 5/9; } @Override public void actionPerformed(ActionEvent event) { String S = myTextField.getText(); int fehrenheit = Integer.parseInt(S); celcius.setText("Degrees Celcius " + convert(fehrenheit) + "*"); } }