-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShopping.java
More file actions
124 lines (99 loc) · 3.21 KB
/
Shopping.java
File metadata and controls
124 lines (99 loc) · 3.21 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
package server;
import java.io.IOException;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
public class Shopping extends Application {
private MainController maincontroller = new MainController();
private TextField port;
private Label status;
@Override
public void start(Stage primaryStage) {
initController();
Button launchbtn = new Button();
launchbtn.setText("启动");
launchbtn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
LaunchServer();
}
});
Button stopbtn = new Button();
stopbtn.setText("停止");
stopbtn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
closeSocket();
}
});
GridPane grid = new GridPane();
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25, 25, 25, 25));
Text scenetitle = new Text("设置参数");
grid.add(scenetitle, 0, 0, 2, 1);
Label labelport = new Label("端口:");
grid.add(labelport, 0, 1);
TextField portfield = new TextField();
port = portfield;
grid.add(portfield, 1, 1);
Label notification = new Label();
status = notification;
grid.add(notification, 0, 2, 2, 1);
grid.add(launchbtn, 0, 3);
grid.add(stopbtn, 1, 3);
Scene scene = new Scene(grid, 300, 250);
primaryStage.setTitle("康康的购物单");
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>(){
@Override
public void handle(WindowEvent event) {
closeSocket();
}
});
primaryStage.setScene(scene);
primaryStage.show();
}
private void initController() {
maincontroller = new MainController();
maincontroller.bindAccess("", new IndexAccess());
maincontroller.bindAccess("index", new IndexAccess());
maincontroller.bindAccess("edit", new EditPageAccess());
maincontroller.bindAccess("save", new SaveAccess());
maincontroller.bindAccess("delete", new DeleteAccess());
maincontroller.setUICallback(this);
}
protected void closeSocket() {
if(maincontroller != null){
maincontroller.closeSocket();
status.setText("停止成功");
}
}
protected void LaunchServer() {
if(!maincontroller.isRunning()){
try {
maincontroller.startListen(Integer.valueOf(port.getText()));
status.setText("启动成功");
} catch (NumberFormatException e) {
status.setText("端口必须是数字 7000~8000");
e.printStackTrace();
} catch (IOException e) {
status.setText("端口打开失败,换个端口");
e.printStackTrace();
}
}else{
status.setText("服务器已经启动");
}
}
public static void main(String[] args) {
launch(args);
}
}