-
Notifications
You must be signed in to change notification settings - Fork 0
/
SocketButton.java
104 lines (90 loc) · 3.54 KB
/
SocketButton.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class SocketButton {
private JFrame frame;
private JPanel panel;
private JButton showDialogButton;
private JButton showDialogButton2;
private JButton showDialogButton3;
private JButton showDialogButton4;
private JButton showDialogButton5;
private SocketFunction sockettest;
public void run() throws Exception {
_initialize();
displayJFrame();
}
public void _initialize() throws Exception {
panel = new JPanel();
frame = new JFrame("Socket Communication");
showDialogButton = new JButton("Connection - fixed IP");
showDialogButton2 = new JButton("Connection - custom IP");
showDialogButton3 = new JButton("Send - Hi");
showDialogButton4 = new JButton("Send - Type");
showDialogButton5 = new JButton("Read");
sockettest = new SocketFunction();
// put the button on the panel
panel.add(showDialogButton);
panel.add(showDialogButton2);
panel.add(showDialogButton3);
panel.add(showDialogButton4);
panel.add(showDialogButton5);
// set up the jframe, then display it
frame.add(panel);
frame.setPreferredSize(new Dimension(350, 120));
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public void displayJFrame() {
showDialogButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
sockettest.SocketConnection("127.0.0.1", 1025);
} catch (Exception e1) {
System.out.println("Unexpected exception: " + e1.getMessage());
}
}
});
showDialogButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
sockettest.SocketConnection();
} catch (Exception e1) {
System.out.println("Unexpected exception: " + e1.getMessage());
}
}
});
showDialogButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
sockettest.SocketSending("Hi");
} catch (Exception e1) {
System.out.println("Unexpected exception: " + e1.getMessage());
}
}
});
showDialogButton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
String kbdtype = JOptionPane.showInputDialog(null);
sockettest.SocketSendingbyKbd(kbdtype);
} catch (
Exception e1) {
System.out.println("Unexpected exception: " + e1.getMessage());
}
}
});
showDialogButton5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
sockettest.SocketReading();
} catch (Exception e1) {
System.out.println("Unexpected exception: " + e1.getMessage());
}
}
});
}
}