-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyDecimals.java
More file actions
292 lines (211 loc) · 11 KB
/
yDecimals.java
File metadata and controls
292 lines (211 loc) · 11 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.*;
/////////////////////////////////////////////////////////////////////////////////////////
//FUTURE IMPLEMENTATION TO PROJECT. ALLOW USERS TO ENTER DIFFERENT TYPES OF COORDINATES//
/////////////////////////////////////////////////////////////////////////////////////////
// Other possibilites:
// have a GUI showing fire history within a 100km radius the user inputted
// Find the forest types to get more accurate fire spread speeds
// Make a simulation, using forest types, precipitation, wind, sun/clouds, temperature..
// allowing the user to adjust accordingly and produce their own wild fire
public class yDecimals extends JFrame implements ItemListener, ActionListener {
JFrame frame;
JPanel panel, panel1, panel2, panel3, panelDecimals, panelMinutes;
JCheckBox decimals, minutes;
private JFrame testFrame = new JFrame("Test Frame");
private JButton button = new JButton("Click Me");
// private JPanel panel = new JPanel(new GridLayout(1, 1));
public yDecimals() {
// Layout Manager = Defines the natural layout for components within a container
// FlowLayout = places components in a row, sized at their preferred size.
// If the horizontal space in the container is too small,
// the FlowLayout class uses the next available row.
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
// new FlowLayout(FlowLayout.LEADING,0,0)); = left
// new FlowLayout(FlowLayout.TRAILING,0,0)); = right
// new FlowLayout(FlowLayout.CENTER,10,10)); = space between each button
JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(250, 250));
// panel.setPreferredSize(new Dimension(100,250)); = skinnier gray box // buttons are more vertical
panel.setBackground(Color.lightGray);
panel.setLayout(new FlowLayout());
// panel.add(new JButton("1"));
// panel.add(new JButton("2"));
// panel.add(new JButton("3"));
// panel.add(new JButton("4"));
// panel.add(new JButton("5"));
// panel.add(new JButton("6"));
// panel.add(new JButton("7"));
// panel.add(new JButton("8"));
// panel.add(new JButton("9"));
// frame.add(panel);
// frame.setVisible(true);
// }
// build everything in the global position
// public static void test() {
ButtonGroup coordsGroup;
JCheckBox decimals, minutes;
JPanel panel1 = new JPanel();
panel1.setPreferredSize(new Dimension(250, 250));
panel1.setBackground(Color.lightGray);
panel1.setLayout(new FlowLayout());
panel1.add(new JLabel("T1: Are your coordinates in decimals or degrees/minutes/seconds?"));
panel1.add(new JLabel("T2: Are your coordinates in decimals or degrees/minutes/seconds?"));
// Create 2 check boxes for the different size of the pizza. Adding ItemListeners so can tell when selected
decimals = new JCheckBox("Decimals", false);
decimals.addItemListener(this);
minutes = new JCheckBox("Degrees, Minutes, Seconds", false);
minutes.addItemListener(this);
// add each to a buttongroup so that only one size can be selected for a single pizza
coordsGroup = new ButtonGroup();
coordsGroup.add(decimals);
coordsGroup.add(minutes);
JPanel panelTwo = new JPanel();
panelTwo.setPreferredSize(new Dimension(250, 100));
panelTwo.setBackground(Color.lightGray);
panelTwo.setLayout(new FlowLayout());
panelTwo.add(decimals);
panelTwo.add(minutes);
// I dont think the panels need to be set Visible unless only want to make
// visible once a selection is made...
// panel1.setVisible(true);
// panelTwo.setVisible(true);
// JFrame frame = new JFrame();
// frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// frame.setSize(500, 500);
// frame.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
frame.add(panel1);
frame.add(panelTwo);
// JPanel3 will hold the space for panelDecimals and panelMinutes
JPanel panel3 = new JPanel();
panel3.setPreferredSize(new Dimension(250, 250));
panel3.setBackground(Color.lightGray);
panel3.setLayout(new FlowLayout());
frame.add(panel3);
// make an @override
// if decimals is selected... set.visible(true) for panelDecimals
// if minutes is selected... set.visible(true) for panelMinutes
// or follow pizza application and make two global text boxes that are adjusted
// based on the e.getsource() == decimals
//panelMinutes and panelDecimals each get their own layout//enter button
panelMinutes = new JPanel();
JTextField degreesLong = new JTextField("Degrees: ");
JTextField minsLong = new JTextField("Minutes: ");
JTextField secondsLong = new JTextField("Seconds: ");
JTextField degreesLat = new JTextField("Degrees: ");
JTextField minsLat = new JTextField("Minutes: ");
JTextField secondsLat = new JTextField("Seconds: ");
JButton enterButtonMinutes = new JButton("Locate");
enterButtonMinutes.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Longitude
String degreesLongText = degreesLong.getText();
String minsLongText = minsLong.getText();
String secondsLongText = secondsLong.getText();
// Latitude
String degreesLatText = degreesLat.getText();
String minsLatText = minsLat.getText();
String secondsLatText = secondsLat.getText();
try {
int degreesLongNum = Integer.parseInt(degreesLongText);
int minsLongNum = Integer.parseInt(minsLongText);
double secondsLongNum = Double.parseDouble(secondsLongText);
int degreesLatNum = Integer.parseInt(degreesLatText);
int minsLatNum = Integer.parseInt(minsLatText);
double secondsLatNum = Double.parseDouble(secondsLatText);
// Handle the numeric value (e.g., display it or perform further actions)
System.out.println("Longitude: ");
System.out.println("User entered Degrees: " + degreesLongNum);
System.out.println("User entered Minutes: " + minsLongNum);
System.out.println("User entered Seconds: " + secondsLongNum);
System.out.println("Latitude: ");
System.out.println("User entered Degrees: " + degreesLatNum);
System.out.println("User entered Minutes: " + minsLatNum);
System.out.println("User entered Seconds: " + secondsLatNum);
} catch (NumberFormatException ex) {
// Handle invalid input (non-numeric characters)
JOptionPane.showMessageDialog(null, "Please enter a valid integers " +
"for degrees and minutes. Double or Integer for seconds.");
}
}
});
panelDecimals = new JPanel();
JTextField decimalsLong = new JTextField("Longitude: ");
JTextField decimalsLat = new JTextField("Latitude: ");
JButton enterButtonDecimals = new JButton("Locate");
enterButtonDecimals.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String decimalsLongText = decimalsLong.getText();
String decimalsLatText = decimalsLat.getText();
try {
double decimalsLongNum = Double.parseDouble(decimalsLongText);
double decimalsLatNum = Double.parseDouble(decimalsLatText);
// Handle the numeric value (e.g., display it or perform further actions)
System.out.println("User entered Longitude: " + decimalsLongNum + " Latitude: " + decimalsLatNum);
} catch (NumberFormatException ex) {
// Handle invalid input (non-numeric characters)
JOptionPane.showMessageDialog(null, "Please enter a valid integer or double.");
}
}
});
frame.add(enterButtonDecimals);
frame.add(enterButtonMinutes);
frame.setVisible(true);
double age = Double.parseDouble(JOptionPane.showInputDialog("Enter your coordinates"));
JOptionPane.showMessageDialog(null, "You are in danger");
// }
}
public static void main(String args[]) { new yDecimals(); }
@Override
public void itemStateChanged(ItemEvent e) {
if(e.getSource() == decimals) {
// panel3 = new JPanel();
// panel3.setPreferredSize(new Dimension(250, 250));
// panel3.setBackground(Color.lightGray);
// panel3.setLayout(new FlowLayout());
// JPanel panelDecimals = new JPanel();
// make it
//Itll be the global JTextField is updated and we put the update
// AKA panelDecimals into this....
// panelDecimals.setVisible(true);
// panel3.add(panelDecimals);
System.out.println("decimal");
panel3 = panelDecimals;
frame.add(panel3);
} else if(e.getSource() == minutes) {
// panel3 = new JPanel();
// panel3.setPreferredSize(new Dimension(250, 250));
// panel3.setBackground(Color.lightGray);
// panel3.setLayout(new FlowLayout());
// panel3.add(panelMinutes);
System.out.println("Minutes");
panel3 = panelMinutes;
frame.add(panel3);
} else {
System.out.println("Nothing");
panel.add(button);
testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
testFrame.add(panel); // Add the panel to the frame
testFrame.pack();
testFrame.setLocation(400, 300);
testFrame.setVisible(true);
}
}
@Override
public void actionPerformed(ActionEvent e) {
if(!e.getActionCommand().isBlank()) {
e.getActionCommand().stripLeading().stripTrailing();
} else {
JOptionPane.showMessageDialog(null, "Invalid entry");
}
}
}