-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientWindow.java
More file actions
90 lines (78 loc) · 2.07 KB
/
ClientWindow.java
File metadata and controls
90 lines (78 loc) · 2.07 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
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JSpinner;
import javax.swing.JComboBox;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JTextPane;
import javax.swing.JTextField;
public class ClientWindow {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ClientWindow window = new ClientWindow();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
Client client;
private JTextField textField;
public ClientWindow() {
initialize();
client = new Client();
client.connectToServer();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
client.closeClient();
}
@Override
public void windowClosed(WindowEvent arg0) {
client.closeClient();
}
});
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frame.getContentPane().add(panel, BorderLayout.CENTER);
JComboBox comboBox = new JComboBox(Station.names);
panel.add(comboBox);
JButton btnNewButton = new JButton("Select");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String text = comboBox.getSelectedItem().toString();
client.SendStopInStationToServer(text);
int rand=(int)(Math.random()*15);
textField.setText("the bus arrives in "+rand+" minutes" );
textField.setVisible(true);
}
});
textField = new JTextField();
panel.add(textField);
textField.setColumns(10);
panel.add(btnNewButton);
textField.setVisible(true);
}
}