-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemperature_GUI.java
More file actions
51 lines (49 loc) · 1.44 KB
/
Temperature_GUI.java
File metadata and controls
51 lines (49 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* This gui converts Celsius to Fahrenheit.
*
* @author (Dr. P. Patankar)
* @version (5/1/2017)
*/
public class Temperature_GUI extends JFrame
{
private JLabel celsiusLabel;
private JLabel fahrenheitLabel;
private JButton convertButton;
private JTextField tempTextField;
private JTextField ftextField;
private JPanel p;
public Temperature_GUI()
{
String str = JOptionPane.showInputDialog(null, "Enter some text : ");
System.out.println(str);
JOptionPane.showMessageDialog(null,str + "Thank you!");
setLayout(new FlowLayout());
tempTextField = new JTextField(5);
celsiusLabel = new JLabel("Celsius");
fahrenheitLabel = new JLabel("Fahrenheit");
ftextField = new JTextField(5);
convertButton = new JButton("Convert");
p = new JPanel();
p.add(celsiusLabel);
p.add(tempTextField);
p.add(fahrenheitLabel);
p.add(ftextField);
p.add(convertButton);
setTitle("Celsius Converter");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(p);
convertButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent evt)
{
int tempFahr = (int)(Double.parseDouble(tempTextField.getText())*1.8)+32;
ftextField.setText("" + tempFahr);
}
});
pack();
setVisible(true);
}
}