-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputDialogFrame.java
63 lines (51 loc) · 1.86 KB
/
InputDialogFrame.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
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
//this class generates input dialog boxes with custume parmerters inputed as array list of strings
//returns array list of inputs
public class InputDialogFrame extends JDialog {
private static ArrayList<String> inputData;
private ArrayList<JTextField> JTextFields;
//constructor
public InputDialogFrame(ArrayList<String> data,JButton cmdSubmit, JLabel messege){
this.setTitle("Input box");
this.setResizable(false);
JPanel p = new JPanel();
p.setLayout(new GridBagLayout()); //grid box -> message, input lables and jtexts as rows, and submit button in last row.
GridBagConstraints gbc = new GridBagConstraints();
JTextFields = new ArrayList<JTextField>(0);
inputData = new ArrayList<String>(0);
int yAxis=0;
gbc.gridx = 0;
gbc.gridy = 0;
p.add(messege, gbc);
for(; yAxis<data.size(); yAxis++) {
gbc.gridx = 0;
gbc.gridy = yAxis+1;
p.add(new JLabel(data.get(yAxis)), gbc);
JTextFields.add(new JTextField(16));
gbc.gridx = 1;
gbc.gridy = yAxis+1;
p.add(JTextFields.get(yAxis), gbc);
}
gbc.gridx = 1;
gbc.gridy = yAxis+1;
p.add(cmdSubmit, gbc);
this.add(p);
this.pack();
this.setLocationRelativeTo(null);
this.setVisible(true);
}//end of constructor
//jtexts to array list of strings
public void textToStrings() {
while(!JTextFields.isEmpty())
inputData.add(JTextFields.remove(0).getText());
}
//getter
public ArrayList<String> getInputData(){return inputData;}
}//end of class