-
Notifications
You must be signed in to change notification settings - Fork 0
/
kiloConverter.java
127 lines (86 loc) · 2.73 KB
/
kiloConverter.java
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//Hunter O'Folan
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class kiloConverter extends JFrame
{
private JPanel panel;
private JLabel messageLabel;
private JTextField kiloTextField;
private JButton calcButton;
private JButton setColorCyan;
private JButton setColorGreen;
private JLabel image;
private final int width = 400;
private final int height = 100;
public kiloConverter()
{
setTitle("KiloConverter");
setSize(width,height);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buildPanel();
add(panel);
setVisible(true);
}
private void buildPanel()
{
messageLabel = new JLabel("Enter a distance in Kilometers");
kiloTextField = new JTextField(10);
setColorCyan = new JButton("Cyanize");
setColorGreen = new JButton("makeGreen");
calcButton = new JButton("Calcumalate");
ImageIcon image1 = new ImageIcon("10d.jpg");
image = new JLabel(image1);
calcButton.setForeground(Color.BLUE);
calcButton.addActionListener(new calcButtonListener());
setColorCyanListener listener = new setColorCyanListener();
setColorCyan.addActionListener(listener);
setColorGreenListener listenerG = new setColorGreenListener();
setColorGreen.addActionListener(listenerG);
calcButton.setIcon(image1);
panel = new JPanel();
panel.setLayout(new GridLayout(3,3));
panel.setBackground(Color.RED);
panel.add(messageLabel);
panel.add(kiloTextField);
panel.add(calcButton);
panel.add(setColorCyan);
panel.add(setColorGreen);
panel.add(image);
}
private class setColorCyanListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
panel.setBackground(Color.CYAN);
}
}
private class setColorGreenListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String actionCommand = e.getActionCommand();
panel.setBackground(Color.GREEN);
setColorCyan.setForeground(Color.PINK);
if (actionCommand.equals("makeGreen"));
System.out.print("you like green");
}
}
private class calcButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
final double conversion = .6214;
String input;
double miles;
input = kiloTextField.getText();
miles = Double.parseDouble(input)*conversion;
JOptionPane.showMessageDialog(null,input+" kilometers is "+miles+" miles");
}
}
//main
public static void main(String[] args)
{
new kiloConverter();
}
}