forked from HoangTran0410/CaroOnline_SocketJava
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RunClient.java
145 lines (134 loc) · 4.43 KB
/
RunClient.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package client;
import client.controller.SocketHandler;
import client.view.helper.LookAndFeel;
import client.view.scene.ChangePassword;
import client.view.scene.ConnectServer;
import client.view.scene.InGame;
import client.view.scene.Login;
import client.view.scene.MainMenu;
import client.view.scene.Profile;
import client.view.scene.Signup;
/**
*
* @author Hoang Tran < hoang at 99.hoangtran@gmail.com >
*/
public class RunClient {
public enum SceneName {
CONNECTSERVER,
LOGIN,
SIGNUP,
MAINMENU,
CHANGEPASSWORD,
INGAME,
PROFILE
}
// scenes
public static ConnectServer connectServerScene;
public static Login loginScene;
public static Signup signupScene;
public static MainMenu mainMenuScene;
public static ChangePassword changePasswordScene;
public static InGame inGameScene;
public static Profile profileScene;
// controller
public static SocketHandler socketHandler;
public RunClient() {
socketHandler = new SocketHandler();
initScene();
openScene(SceneName.CONNECTSERVER);
}
public void initScene() {
connectServerScene = new ConnectServer();
loginScene = new Login();
signupScene = new Signup();
mainMenuScene = new MainMenu();
changePasswordScene = new ChangePassword();
inGameScene = new InGame();
profileScene = new Profile();
}
public static void openScene(SceneName sceneName) {
if (null != sceneName) {
switch (sceneName) {
case CONNECTSERVER:
// tạo lại scene để tạo lại state mặc định
// nếu chỉ setVisible(true) thì cũng open được scene cũ, nhưng state thì không phải mặc định
connectServerScene = new ConnectServer();
connectServerScene.setVisible(true);
break;
case LOGIN:
loginScene = new Login();
loginScene.setVisible(true);
break;
case SIGNUP:
signupScene = new Signup();
signupScene.setVisible(true);
break;
case MAINMENU:
mainMenuScene = new MainMenu();
mainMenuScene.setVisible(true);
break;
case CHANGEPASSWORD:
changePasswordScene = new ChangePassword();
changePasswordScene.setVisible(true);
break;
case INGAME:
inGameScene = new InGame();
inGameScene.setVisible(true);
break;
case PROFILE:
profileScene = new Profile();
profileScene.setVisible(true);
break;
default:
break;
}
}
}
public static void closeScene(SceneName sceneName) {
if (null != sceneName) {
switch (sceneName) {
case CONNECTSERVER:
connectServerScene.dispose();
break;
case LOGIN:
loginScene.dispose();
break;
case SIGNUP:
signupScene.dispose();
break;
case MAINMENU:
mainMenuScene.dispose();
break;
case CHANGEPASSWORD:
changePasswordScene.dispose();
break;
case INGAME:
inGameScene.dispose();
break;
case PROFILE:
profileScene.dispose();
break;
default:
break;
}
}
}
public static void closeAllScene() {
connectServerScene.dispose();
loginScene.dispose();
signupScene.dispose();
mainMenuScene.dispose();
changePasswordScene.dispose();
inGameScene.dispose();
profileScene.dispose();
}
public static void main(String[] args) {
LookAndFeel.setNimbusLookAndFeel();
new RunClient();
}
}