-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTempConverter.java
More file actions
57 lines (44 loc) · 1.15 KB
/
TempConverter.java
File metadata and controls
57 lines (44 loc) · 1.15 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
52
53
54
55
56
57
package Testing;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TempConverter extends JFrame implements ActionListener{
JTextField ct = new JTextField(10);
JLabel cl = new JLabel("Celsius");
JLabel fl = new JLabel("Farenheit :- ");
JLabel frl = new JLabel();
JButton co = new JButton("CONVERT");
JButton re = new JButton("RESET");
Panel p = new Panel();
TempConverter() {
setVisible(true);
setTitle("Temp Converter");
setBounds(100,100,220,200);
setLayout(new FlowLayout());
add(cl);
add(ct);
add(fl);
add(frl);
p.add(co);
p.add(re);
add(p);
co.addActionListener(this);
re.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==co) {
String str = ct.getText();
double cel = Double.parseDouble(str);
double result = (cel*9/5)+32;
String strResult = Double.toString(result);
frl.setText(strResult);
}
else if(e.getSource()==re) {
frl.setText(null);
ct.setText(null);
}
}
public static void main(String []args) {
TempConverter t = new TempConverter();
}
}