added needed javafx modules to build since I'm getting the following message at runtime:
"JavaFX runtime components are missing, and are required to run this application"
This commit is contained in:
parent
0270202c3f
commit
f7324f2300
@ -7,7 +7,8 @@ plugins {
|
|||||||
|
|
||||||
javafx {
|
javafx {
|
||||||
version = "11.0.2"
|
version = "11.0.2"
|
||||||
modules = ['javafx.controls', 'javafx.fxml', 'javafx.base']
|
modules = ['javafx.controls', 'javafx.fxml', 'javafx.base', 'javafx.scene', 'javafx.collections', 'javafx.beans', 'javafx.event', '' +
|
||||||
|
'javafx.stage']
|
||||||
}
|
}
|
||||||
|
|
||||||
group 'ch.unibas.dmi.dbis'
|
group 'ch.unibas.dmi.dbis'
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client;
|
package ch.unibas.dmi.dbis.cs108.multiplayer.client;
|
||||||
|
|
||||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||||
|
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
|
||||||
|
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.GUI;
|
||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatApp;
|
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatApp;
|
||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.ClientPinger;
|
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.ClientPinger;
|
||||||
|
|
||||||
@ -19,6 +21,7 @@ import org.apache.logging.log4j.Logger;
|
|||||||
|
|
||||||
|
|
||||||
public class Client {
|
public class Client {
|
||||||
|
|
||||||
public static final Logger LOGGER = LogManager.getLogger(Client.class);
|
public static final Logger LOGGER = LogManager.getLogger(Client.class);
|
||||||
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||||
|
|
||||||
@ -27,8 +30,8 @@ public class Client {
|
|||||||
private BufferedWriter out;
|
private BufferedWriter out;
|
||||||
public ClientPinger clientPinger;
|
public ClientPinger clientPinger;
|
||||||
|
|
||||||
private BufferedWriter toChatGui;
|
|
||||||
private ChatApp chatApp;
|
private ChatApp chatApp;
|
||||||
|
private GUI chatGUi;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the position of the client, gets refreshed everytime the client gets a vote request.
|
* Saves the position of the client, gets refreshed everytime the client gets a vote request.
|
||||||
@ -50,16 +53,20 @@ public class Client {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
systemName = "U.N. Owen";
|
systemName = "U.N. Owen";
|
||||||
}
|
}
|
||||||
if (systemName == null) systemName = "U.N. Owen";
|
if (systemName == null) {
|
||||||
|
systemName = "U.N. Owen";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
systemName = username;
|
systemName = username;
|
||||||
}
|
}
|
||||||
sendMsgToServer(Protocol.clientLogin + "$" + systemName);
|
sendMsgToServer(Protocol.clientLogin + "$" + systemName);
|
||||||
|
this.chatApp = new ChatApp(new ClientModel(systemName, this));
|
||||||
|
this.chatGUi = new GUI(this.chatApp);
|
||||||
clientPinger = new ClientPinger(this, this.socket);
|
clientPinger = new ClientPinger(this, this.socket);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,28 +102,26 @@ public class Client {
|
|||||||
*/
|
*/
|
||||||
public void positionSetter(String msg) {
|
public void positionSetter(String msg) {
|
||||||
|
|
||||||
LOGGER.info("Im in thread:" + Thread.currentThread());
|
LOGGER.info("Im in thread:" + Thread.currentThread());
|
||||||
int msgIndex = msg.indexOf('$');
|
int msgIndex = msg.indexOf('$');
|
||||||
String pos = msg.substring(0, msgIndex);
|
String pos = msg.substring(0, msgIndex);
|
||||||
try {
|
try {
|
||||||
position = Integer.parseInt(pos);
|
position = Integer.parseInt(pos);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
LOGGER.warn("Position got scrabbled on the way here");
|
LOGGER.warn("Position got scrabbled on the way here");
|
||||||
}
|
}
|
||||||
String justMsg = msg.substring(msgIndex + 1);
|
String justMsg = msg.substring(msgIndex + 1);
|
||||||
|
|
||||||
System.out.println(justMsg);
|
System.out.println(justMsg);
|
||||||
System.out.println("Please enter your vote");
|
System.out.println("Please enter your vote");
|
||||||
|
|
||||||
|
//LOGGER.debug("just checked next line");
|
||||||
//LOGGER.debug("just checked next line");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a thread which listens for incoming chat messages / other messages that the user
|
* Starts a thread which listens for incoming chat messages / other messages that the user has to
|
||||||
* has to see
|
* see
|
||||||
*/
|
*/
|
||||||
public void chatListener() {
|
public void chatListener() {
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@ -131,7 +136,10 @@ public class Client {
|
|||||||
if (chatMsg != null) {
|
if (chatMsg != null) {
|
||||||
//LOGGER.debug("chatMSG recieved from Server: " + chatMsg);
|
//LOGGER.debug("chatMSG recieved from Server: " + chatMsg);
|
||||||
parse(chatMsg);
|
parse(chatMsg);
|
||||||
} else { System.out.println("chatMsg is null"); throw new IOException();}
|
} else {
|
||||||
|
System.out.println("chatMsg is null");
|
||||||
|
throw new IOException();
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
//e.printStackTrace();
|
//e.printStackTrace();
|
||||||
LOGGER.warn("Exception while trying to read message: " + e.getMessage());
|
LOGGER.warn("Exception while trying to read message: " + e.getMessage());
|
||||||
@ -165,6 +173,7 @@ public class Client {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* parses a received message according to the client protocol.
|
* parses a received message according to the client protocol.
|
||||||
|
*
|
||||||
* @param msg the message to be parsed.
|
* @param msg the message to be parsed.
|
||||||
*/
|
*/
|
||||||
public void parse(String msg) {
|
public void parse(String msg) {
|
||||||
@ -210,6 +219,9 @@ public class Client {
|
|||||||
Thread cP = new Thread(client.clientPinger);
|
Thread cP = new Thread(client.clientPinger);
|
||||||
cP.start();
|
cP.start();
|
||||||
client.userInputListener(); //this one blocks.
|
client.userInputListener(); //this one blocks.
|
||||||
|
//Start the GUI
|
||||||
|
Thread guiThread = new Thread(client.chatGUi);
|
||||||
|
guiThread.start();
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
System.out.println("Invalid host IP");
|
System.out.println("Invalid host IP");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -228,6 +240,9 @@ public class Client {
|
|||||||
Thread cP = new Thread(client.clientPinger);
|
Thread cP = new Thread(client.clientPinger);
|
||||||
cP.start();
|
cP.start();
|
||||||
client.userInputListener(); //this one blocks.
|
client.userInputListener(); //this one blocks.
|
||||||
|
|
||||||
|
Thread guiThread = new Thread(client.chatGUi);
|
||||||
|
guiThread.start();
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
System.out.println("Invalid host IP");
|
System.out.println("Invalid host IP");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -248,5 +263,6 @@ public class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sendToChat(String substring) {
|
public void sendToChat(String substring) {
|
||||||
|
chatApp.getChatController().addChatMsgToView(substring);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,11 @@ public class ClientModel {
|
|||||||
private Client client;
|
private Client client;
|
||||||
private String incomingChatMsg;
|
private String incomingChatMsg;
|
||||||
|
|
||||||
|
public ClientModel(String username, Client client) {
|
||||||
|
this.username = username;
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
//private Number;
|
//private Number;
|
||||||
|
|
||||||
public Client getClient() {
|
public Client getClient() {
|
||||||
|
|||||||
@ -0,0 +1,25 @@
|
|||||||
|
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui;
|
||||||
|
|
||||||
|
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatApp;
|
||||||
|
import javafx.application.Application;
|
||||||
|
|
||||||
|
public class GUI implements Runnable{
|
||||||
|
|
||||||
|
ChatApp chatApp;
|
||||||
|
public GUI (ChatApp chatApp) {
|
||||||
|
this.chatApp = chatApp;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
* thread.
|
||||||
|
* <p>
|
||||||
|
* The general contract of the method {@code run} is that it may take any action whatsoever.
|
||||||
|
*
|
||||||
|
* @see Thread#run()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Application.launch(this.chatApp.getClass());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,14 +1,20 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat;
|
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat;
|
||||||
|
|
||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
|
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
public class ChatApp extends Application {
|
public class ChatApp extends Application {
|
||||||
ClientModel clientModel;
|
ClientModel clientModel;
|
||||||
ChatController chatController;
|
private ChatController chatController;
|
||||||
|
|
||||||
|
|
||||||
public ChatApp(ClientModel clientModel) {
|
public ChatApp(ClientModel clientModel) {
|
||||||
this.clientModel = clientModel;
|
this.clientModel = clientModel;
|
||||||
@ -31,8 +37,8 @@ public class ChatApp extends Application {
|
|||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws Exception {
|
public void start(Stage primaryStage) throws Exception {
|
||||||
|
|
||||||
ChatApp chatApp = new ChatApp(new ClientModel());
|
//ChatApp chatApp = new ChatApp(new ClientModel());
|
||||||
AnchorPane root = new AnchorPane(chatController.getChatPaneRoot());
|
Parent root = FXMLLoader.load(getClass().getResource("splitPaneChatView.fxml"));
|
||||||
// TODO bin chatController.getChatPaneRoot() border to root border for rezising
|
// TODO bin chatController.getChatPaneRoot() border to root border for rezising
|
||||||
Scene scene = new Scene(root);
|
Scene scene = new Scene(root);
|
||||||
primaryStage.setResizable(true);
|
primaryStage.setResizable(true);
|
||||||
@ -42,4 +48,12 @@ public class ChatApp extends Application {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChatController getChatController() {
|
||||||
|
return chatController;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
|
|||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
|
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.beans.property.BooleanProperty;
|
import javafx.beans.property.BooleanProperty;
|
||||||
import javafx.beans.property.SimpleBooleanProperty;
|
import javafx.beans.property.SimpleBooleanProperty;
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
@ -69,11 +70,10 @@ public class ChatController implements Initializable {
|
|||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
|
|
||||||
|
|
||||||
vBoxChatMessages.getChildren().addListener(new ListChangeListener<Node>() {
|
vBoxChatMessages.getChildren().addListener(new ListChangeListener<Node>() {
|
||||||
@Override
|
@Override
|
||||||
public void onChanged(Change<? extends Node> c) {
|
public void onChanged(Change<? extends Node> c) {
|
||||||
vBoxChatMessages.setMaxHeight(vBoxChatMessages.getMaxHeight()*2);
|
vBoxChatMessages.setMaxHeight(vBoxChatMessages.getMaxHeight() * 2);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -92,7 +92,6 @@ public class ChatController implements Initializable {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize what heppens when the sen button is pressed
|
* Initialize what heppens when the sen button is pressed
|
||||||
*/
|
*/
|
||||||
@ -132,7 +131,7 @@ public class ChatController implements Initializable {
|
|||||||
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue,
|
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue,
|
||||||
Boolean newValue) {
|
Boolean newValue) {
|
||||||
//is true if {@code whisperTargetSelectedField} has content
|
//is true if {@code whisperTargetSelectedField} has content
|
||||||
if(!newValue) {
|
if (!newValue) {
|
||||||
cmd = whisper + "$";
|
cmd = whisper + "$";
|
||||||
} else {
|
} else {
|
||||||
cmd = chatToLobby + "$";
|
cmd = chatToLobby + "$";
|
||||||
@ -167,10 +166,21 @@ public class ChatController implements Initializable {
|
|||||||
return chatPaneRoot;
|
return chatPaneRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The client calls this method to foreward a chat message to the chat gui
|
||||||
|
*
|
||||||
|
* @param msg the message to be displayed
|
||||||
|
*/
|
||||||
public void addChatMsgToView(String msg) {
|
public void addChatMsgToView(String msg) {
|
||||||
Label l = new Label(msg);
|
Label l = new Label(msg);
|
||||||
l.setBackground(Background.fill(Color.LIGHTSKYBLUE));
|
l.setBackground(Background.fill(Color.LIGHTSKYBLUE));
|
||||||
l.setTextFill(Color.BLACK);
|
l.setTextFill(Color.BLACK);
|
||||||
vBoxChatMessages.getChildren().add(l);
|
Platform.runLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
vBoxChatMessages.getChildren().add(l);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user