Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDimensionsInputDialog.java
More file actions
Latest commit
43 lines (39 loc) · 1.94 KB
/
Copy pathDimensionsInputDialog.java
File metadata and controls
43 lines (39 loc) · 1.94 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
importjavax.swing.JOptionPane;
importjava.awt.Component;
importjava.util.Arrays;
publicclassDimensionsInputDialog
{
staticint[] showDialog(Componentparent){
returnshowDialog(parent, "Please imput dimensions"+UsefulStrings.getLineSeparator()+"Input should be of the form # of cells in the X coordinate,# of cells in the Y coordinate.", "30,30");
}
staticint[] showDialogWithMessage(Componentparent, Stringmessage){
returnshowDialog(parent, message, "30,30");
}
staticint[] showDialog(Componentparent, StringdefaultValue){
returnshowDialogWithDefault(parent, defaultValue);
}
staticint[] showDialogWithDefault(Componentparent, StringdefaultValue){
returnshowDialog(parent, "Please imput dimensions"+UsefulStrings.getLineSeparator()+"Input should be of the form # of cells in the X coordinate,# of cells in the Y coordinate.", defaultValue);
}
staticint[] showDialog(Componentparent, Stringmessage, StringdefaultValue){
Stringd = JOptionPane.showInputDialog(message, defaultValue);
if(d==null) returnnull;
String[] dimensions = d.split(",");
int[] rVal = null;
try{
rVal = newint[]{newInteger(dimensions[0]),newInteger(dimensions[1])};
}catch(NumberFormatExceptionnfe){
System.err.println(Arrays.toString(dimensions)+" is not a valid input");
rVal = DimensionsInputDialog.showDialog(parent, message, defaultValue);
}
if(rVal.length!=2){
System.err.println(Arrays.toString(dimensions)+" is not the right length");
rVal = DimensionsInputDialog.showDialog(parent, message, defaultValue);
}
if(!(rVal[0]>0&&rVal[1]>0)){
System.err.println(Arrays.toString(dimensions)+" is out of bounds (too small)");
rVal = DimensionsInputDialog.showDialog(parent, message, defaultValue);
}
returnrVal;
}
}