-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServerConfiguration.java
84 lines (73 loc) · 3.08 KB
/
ServerConfiguration.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
/*
* Author Of Code : Priyanshu Lanjewar
* Registration Number : 1941012603
* Branch / Sec / Sem : CSE - F - 3rd Sem
* Institute : Institute of Technical Education and Research
* University : Siksha O Anusandhana Deemed To Be University.
* Class Description :
Class Provides GUI to Configure server's port and Location.
*/
import javax.swing.*;
import java.awt.*;
public class ServerConfiguration extends JFrame{
private JPanel serverConfigPanel;
private JTextField location_txt;
private JButton clickToChooseLocationButton;
private JSpinner portNo;
private JButton saveButton;
private JButton cancelButton;
private JTextField address;
JFileChooser chooser;
String choosertitle;
String location;
public ServerConfiguration(){
add(serverConfigPanel);
setSize(500,250);
setResizable(false);
ImageIcon icn = new ImageIcon(this.getClass().getResource("serverConf.png"));
setIconImage(icn.getImage());
setTitle("Remote File Content Display System");
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
clickToChooseLocationButton.addActionListener(e -> {
chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File("."));
chooser.setDialogTitle(choosertitle);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
Color c = Color.DARK_GRAY;
if (chooser.showOpenDialog(ServerConfiguration.this) == JFileChooser.APPROVE_OPTION) {
location= chooser.getSelectedFile().toString();
location_txt.setDisabledTextColor(c);
location_txt.setText(location);
}
else {
location_txt.setText("Not Chosen Any Directory !!");
location_txt.setDisabledTextColor(Color.RED);
}
});
cancelButton.addActionListener(e -> SwingUtilities.invokeLater(() -> {
ServerConfiguration.this.setVisible(false);
Server f = new Server();
f.setVisible(true);
}));
saveButton.addActionListener(e -> SwingUtilities.invokeLater(() -> {
if(location==null || location_txt.toString().equals("Not Chosen Any Directory !!")){
JOptionPane.showMessageDialog(this,"Please Select Valid Location of Directory !","Error : Invalid Address",JOptionPane.ERROR_MESSAGE,null);
} else {
ServerConfiguration.this.setVisible(false);
Server f = new Server(address.getText(),portNo.getValue().toString(), location);
f.setVisible(true);
}
}));
}
private void createUIComponents() {
serverConfigPanel = new JPanel();
SpinnerModel sm = new SpinnerNumberModel(8331,1000,9999,1);
portNo = new JSpinner(sm);
address = new JTextField();
address.setHorizontalAlignment(JTextField.RIGHT);
location_txt = new JTextField();
clickToChooseLocationButton = new JButton();
}
}