forked from KevinKien/Chat-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerFrame.java
More file actions
108 lines (90 loc) · 4 KB
/
ServerFrame.java
File metadata and controls
108 lines (90 loc) · 4 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
package socket;
import javax.swing.JFileChooser;
import javax.swing.UIManager;
public class ServerFrame extends javax.swing.JFrame {
public SocketServer server;
public Thread serverThread;
public String filePath = "data.txt";
public JFileChooser fileChooser;
public ServerFrame() {
initComponents();
//jTextField3.setEditable(false);
//jTextField3.setBackground(Color.WHITE);
fileChooser = new JFileChooser();
jTextArea1.setEditable(false);
}
//public boolean isWin32(){
// return System.getProperty("os.name").startsWith("Windows");
//}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("jServer");
jButton1.setText("Start Server");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jTextArea1.setColumns(20);
jTextArea1.setFont(new java.awt.Font("Consolas", 0, 12)); // NOI18N
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(243, 243, 243)
.addComponent(jButton1))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 597, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton1)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
server = new SocketServer(this);
jButton1.setEnabled(true);
//jButton2.setEnabled(true);
}//GEN-LAST:event_jButton1ActionPerformed
public void RetryStart(int port){
if(server != null){ server.stop(); }
server = new SocketServer(this, port);
}
public static void main(String args[]) {
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception ex){
System.out.println("Look & Feel Exception");
}
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new ServerFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JScrollPane jScrollPane1;
public javax.swing.JTextArea jTextArea1;
// End of variables declaration//GEN-END:variables
}