Added static field to ChatApp and set it to the current application in the start()
This commit is contained in:
parent
7ba20a9f62
commit
edf5c65da2
@ -62,6 +62,7 @@ public class Client {
|
||||
sendMsgToServer(Protocol.clientLogin + "$" + systemName);
|
||||
this.chatApp = new ChatApp(new ClientModel(systemName, this));
|
||||
this.chatGUi = new GUI(this.chatApp);
|
||||
chatGUi.setName(systemName);
|
||||
clientPinger = new ClientPinger(this, this.socket);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@ -220,8 +221,10 @@ public class Client {
|
||||
cP.start();
|
||||
client.userInputListener(); //this one blocks.
|
||||
//Start the GUI
|
||||
Thread guiThread = new Thread(client.chatGUi);
|
||||
GUI gui = new GUI(client.chatApp);
|
||||
Thread guiThread = new Thread(gui);
|
||||
guiThread.start();
|
||||
LOGGER.info("7");
|
||||
} catch (UnknownHostException e) {
|
||||
System.out.println("Invalid host IP");
|
||||
} catch (IOException e) {
|
||||
@ -240,14 +243,17 @@ public class Client {
|
||||
Thread cP = new Thread(client.clientPinger);
|
||||
cP.start();
|
||||
client.userInputListener(); //this one blocks.
|
||||
|
||||
LOGGER.info("7.1");
|
||||
Thread guiThread = new Thread(client.chatGUi);
|
||||
LOGGER.info("8");
|
||||
guiThread.start();
|
||||
LOGGER.info("9");
|
||||
} catch (UnknownHostException e) {
|
||||
System.out.println("Invalid host IP");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
LOGGER.info("10");
|
||||
}
|
||||
|
||||
public Socket getSocket() {
|
||||
|
||||
@ -1,8 +1,13 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.Client;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class ClientModel {
|
||||
public static final Logger LOGGER = LogManager.getLogger(ClientModel.class);
|
||||
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||
|
||||
private String username;
|
||||
private Client client;
|
||||
|
||||
@ -1,14 +1,25 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatApp;
|
||||
import javafx.application.Application;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class GUI implements Runnable{
|
||||
public static final Logger LOGGER = LogManager.getLogger(GUI.class);
|
||||
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||
|
||||
ChatApp chatApp;
|
||||
private String name;
|
||||
public GUI (ChatApp chatApp) {
|
||||
this.chatApp = chatApp;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* When an object implementing interface {@code Runnable} is used to create a thread, starting the
|
||||
* thread causes the object's {@code run} method to be called in that separately executing
|
||||
@ -18,8 +29,12 @@ public class GUI implements Runnable{
|
||||
*
|
||||
* @see Thread#run()
|
||||
*/
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
LOGGER.info("here");
|
||||
//String name =
|
||||
Application.launch(this.chatApp.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.Client;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
|
||||
import java.net.URL;
|
||||
import java.util.Objects;
|
||||
@ -8,19 +10,40 @@ import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class ChatApp extends Application {
|
||||
ClientModel clientModel;
|
||||
public static final Logger LOGGER = LogManager.getLogger(ChatApp.class);
|
||||
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||
|
||||
private static ClientModel clientModel;
|
||||
private ChatController chatController;
|
||||
|
||||
public ChatApp() {
|
||||
super();
|
||||
LOGGER.info("Empty ChatApp constructor got called: ");
|
||||
|
||||
}
|
||||
|
||||
public ChatApp(ClientModel clientModel) {
|
||||
this.clientModel = clientModel;
|
||||
this.chatController = new ChatController(clientModel);
|
||||
}
|
||||
|
||||
public void setChatController(
|
||||
ChatController chatController) {
|
||||
this.chatController = chatController;
|
||||
}
|
||||
|
||||
public static void setClientModel(ClientModel clientM) {
|
||||
clientModel = clientM;
|
||||
}
|
||||
|
||||
public static ClientModel getClientModel() {
|
||||
return clientModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* The main entry point for all JavaFX applications. The start method is called after the init
|
||||
* method has returned, and after the system is ready for the application to begin running.
|
||||
@ -36,8 +59,11 @@ public class ChatApp extends Application {
|
||||
*/
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
LOGGER.info("made it here");
|
||||
this.setClientModel(clientModel);
|
||||
URL resource = ChatApp.class.getResource(
|
||||
"splitPaneChatView.fxml");
|
||||
LOGGER.info("1");
|
||||
if (resource == null) {
|
||||
System.out.println("File wasnt found");
|
||||
}
|
||||
@ -46,16 +72,23 @@ public class ChatApp extends Application {
|
||||
Parent root = FXMLLoader.load(
|
||||
Objects.requireNonNull(ChatApp.class.getResource(
|
||||
"splitPaneChatView.fxml")));
|
||||
LOGGER.info("2");
|
||||
// TODO bin chatController.getChatPaneRoot() border to root border for rezising
|
||||
Scene scene = new Scene(root);
|
||||
LOGGER.info("3");
|
||||
scene.setRoot(root);
|
||||
LOGGER.info("4");
|
||||
primaryStage.setScene(scene);
|
||||
LOGGER.info("5");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
primaryStage.setResizable(true);
|
||||
LOGGER.info("6");
|
||||
primaryStage.setTitle("Chat");
|
||||
LOGGER.info("7");
|
||||
primaryStage.show();
|
||||
LOGGER.info("8");
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ public class ChatController implements Initializable {
|
||||
*/
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
|
||||
setClient(ChatApp.getClientModel());
|
||||
vBoxChatMessages.getChildren().addListener(new ListChangeListener<Node>() {
|
||||
@Override
|
||||
public void onChanged(Change<? extends Node> c) {
|
||||
|
||||
Reference in New Issue
Block a user