-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowUserSettings.java
More file actions
208 lines (190 loc) · 6.23 KB
/
WindowUserSettings.java
File metadata and controls
208 lines (190 loc) · 6.23 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
package traintransfer;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.JLabel;
import java.awt.Font;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JTree;
import java.awt.Component;
import javax.swing.Box;
import javax.swing.JFileChooser;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JCheckBox;
public class WindowUserSettings extends JDialog {
/**
*
*/
private static final long serialVersionUID = 2780013945687516655L;
private final JPanel contentPanel = new JPanel();
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
JCheckBox chckbxNewCheckBox;
/**
* Launch the application.
*/
public String getStPath() {
return textField.getText();
}
public String getSchedulePath() {
return textField_1.getText();
}
public String getSameStPath() {
return textField_2.getText();
}
private File chooseFile() {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setBounds(0, 0, 0, 0);
fileChooser.setCurrentDirectory(new File("."));
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setMultiSelectionEnabled(false);
fileChooser.setFileFilter(new FileNameExtensionFilter("file(.*txt, .*csv)","txt","csv"));
if(fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
return file;
}
return null;
}
public static void main(String[] args) {
try {
WindowUserSettings dialog = new WindowUserSettings();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the dialog.
* @throws IOException
*/
private void loadFilePath() {
File dataPaths=new File("./dataPaths.txt");
if(!dataPaths.exists()) return;
BufferedReader br;
try {
br=new BufferedReader(new FileReader(dataPaths));
textField.setText(br.readLine());
textField_1.setText(br.readLine());
textField_2.setText(br.readLine());
br.close();
}catch(IOException ex) {
WindowErrMsg wem=new WindowErrMsg();
wem.textArea.setText("dataPaths文件IO异常!!!");
wem.setVisible(true);
}
}
public void writeFilePath(String StPath,String SchPath,String sameStPath) throws IOException {
BufferedWriter bw;
bw=new BufferedWriter(new FileWriter("./dataPaths.txt"));
bw.write(StPath);
bw.newLine();
bw.write(SchPath);
bw.newLine();
bw.write(sameStPath);
bw.close();
}
protected void exit() {
System.exit(0);
}
public WindowUserSettings() {
setTitle("\u8BBE\u7F6E");
setBounds(100, 100, 450, 293);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(null);
{
JLabel lblNewLabel = new JLabel("\u8BBE\u7F6E\u8F66\u7AD9\u4FE1\u606F\u6587\u4EF6\u8DEF\u5F84");
lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 16));
lblNewLabel.setBounds(10, 10, 294, 19);
contentPanel.add(lblNewLabel);
}
{
JLabel lblNewLabel = new JLabel("\u8BBE\u7F6E\u5217\u8F66\u65F6\u523B\u8868\u4FE1\u606F\u6587\u4EF6\u8DEF\u5F84");
lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 16));
lblNewLabel.setBounds(10, 72, 294, 19);
contentPanel.add(lblNewLabel);
}
{
JLabel lblNewLabel = new JLabel("\u8BBE\u7F6E\u540C\u57CE\u8F66\u7AD9\u6587\u4EF6\u8DEF\u5F84");
lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 16));
lblNewLabel.setBounds(10, 138, 294, 19);
contentPanel.add(lblNewLabel);
}
textField = new JTextField();
textField.setBounds(10, 28, 339, 33);
contentPanel.add(textField);
textField.setColumns(10);
JButton btnNewButton = new JButton("\u6D4F\u89C8");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
textField.setText(chooseFile().getAbsolutePath());
}catch(NullPointerException ex) {}
}
});
btnNewButton.setBounds(350, 28, 76, 33);
contentPanel.add(btnNewButton);
textField_1 = new JTextField();
textField_1.setColumns(10);
textField_1.setBounds(10, 95, 339, 33);
contentPanel.add(textField_1);
JButton btnNewButton_1 = new JButton("\u6D4F\u89C8");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
textField_1.setText(chooseFile().getAbsolutePath());
}catch(NullPointerException ex) {}
}
});
btnNewButton_1.setBounds(350, 95, 76, 33);
contentPanel.add(btnNewButton_1);
textField_2 = new JTextField();
textField_2.setColumns(10);
textField_2.setBounds(10, 158, 339, 33);
contentPanel.add(textField_2);
JButton btnNewButton_2 = new JButton("\u6D4F\u89C8");
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
textField_2.setText(chooseFile().getAbsolutePath());
}catch(NullPointerException ex) {}
}
});
btnNewButton_2.setBounds(350, 158, 76, 33);
contentPanel.add(btnNewButton_2);
chckbxNewCheckBox = new JCheckBox("\u5C06\u67E5\u8BE2\u8BB0\u5F55\u4FDD\u5B58\u5728\u7A0B\u5E8F\u76EE\u5F55\u4E0B");
chckbxNewCheckBox.setBounds(10, 197, 416, 23);
contentPanel.add(chckbxNewCheckBox);
{
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton cancelButton = new JButton("OK");
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
}
});
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton);
}
}
loadFilePath();
}
}