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:
Sebastian Lenzlinger 2022-04-16 17:06:27 +02:00
parent 0270202c3f
commit f7324f2300
6 changed files with 100 additions and 29 deletions

View File

@ -7,7 +7,8 @@ plugins {
javafx {
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'

View File

@ -1,6 +1,8 @@
package ch.unibas.dmi.dbis.cs108.multiplayer.client;
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.helpers.ClientPinger;
@ -19,6 +21,7 @@ import org.apache.logging.log4j.Logger;
public class Client {
public static final Logger LOGGER = LogManager.getLogger(Client.class);
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
@ -27,8 +30,8 @@ public class Client {
private BufferedWriter out;
public ClientPinger clientPinger;
private BufferedWriter toChatGui;
private ChatApp chatApp;
private GUI chatGUi;
/**
* 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) {
systemName = "U.N. Owen";
}
if (systemName == null) systemName = "U.N. Owen";
if (systemName == null) {
systemName = "U.N. Owen";
}
} else {
systemName = username;
}
sendMsgToServer(Protocol.clientLogin + "$" + systemName);
this.chatApp = new ChatApp(new ClientModel(systemName, this));
this.chatGUi = new GUI(this.chatApp);
clientPinger = new ClientPinger(this, this.socket);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
@ -108,15 +115,13 @@ public class Client {
System.out.println(justMsg);
System.out.println("Please enter your vote");
//LOGGER.debug("just checked next line");
}
/**
* Starts a thread which listens for incoming chat messages / other messages that the user
* has to see
* Starts a thread which listens for incoming chat messages / other messages that the user has to
* see
*/
public void chatListener() {
new Thread(new Runnable() {
@ -131,7 +136,10 @@ public class Client {
if (chatMsg != null) {
//LOGGER.debug("chatMSG recieved from Server: " + 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) {
//e.printStackTrace();
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.
*
* @param msg the message to be parsed.
*/
public void parse(String msg) {
@ -210,6 +219,9 @@ public class Client {
Thread cP = new Thread(client.clientPinger);
cP.start();
client.userInputListener(); //this one blocks.
//Start the GUI
Thread guiThread = new Thread(client.chatGUi);
guiThread.start();
} catch (UnknownHostException e) {
System.out.println("Invalid host IP");
} catch (IOException e) {
@ -228,6 +240,9 @@ public class Client {
Thread cP = new Thread(client.clientPinger);
cP.start();
client.userInputListener(); //this one blocks.
Thread guiThread = new Thread(client.chatGUi);
guiThread.start();
} catch (UnknownHostException e) {
System.out.println("Invalid host IP");
} catch (IOException e) {
@ -248,5 +263,6 @@ public class Client {
}
public void sendToChat(String substring) {
chatApp.getChatController().addChatMsgToView(substring);
}
}

View File

@ -8,6 +8,11 @@ public class ClientModel {
private Client client;
private String incomingChatMsg;
public ClientModel(String username, Client client) {
this.username = username;
this.client = client;
}
//private Number;
public Client getClient() {

View File

@ -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());
}
}

View File

@ -1,14 +1,20 @@
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat;
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.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
public class ChatApp extends Application {
ClientModel clientModel;
ChatController chatController;
private ChatController chatController;
public ChatApp(ClientModel clientModel) {
this.clientModel = clientModel;
@ -31,8 +37,8 @@ public class ChatApp extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
ChatApp chatApp = new ChatApp(new ClientModel());
AnchorPane root = new AnchorPane(chatController.getChatPaneRoot());
//ChatApp chatApp = new ChatApp(new ClientModel());
Parent root = FXMLLoader.load(getClass().getResource("splitPaneChatView.fxml"));
// TODO bin chatController.getChatPaneRoot() border to root border for rezising
Scene scene = new Scene(root);
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;
}
}

View File

@ -5,6 +5,7 @@ import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.application.Platform;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
@ -69,11 +70,10 @@ public class ChatController implements Initializable {
@Override
public void initialize(URL location, ResourceBundle resources) {
vBoxChatMessages.getChildren().addListener(new ListChangeListener<Node>() {
@Override
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
*/
@ -132,7 +131,7 @@ public class ChatController implements Initializable {
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue,
Boolean newValue) {
//is true if {@code whisperTargetSelectedField} has content
if(!newValue) {
if (!newValue) {
cmd = whisper + "$";
} else {
cmd = chatToLobby + "$";
@ -167,10 +166,21 @@ public class ChatController implements Initializable {
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) {
Label l = new Label(msg);
l.setBackground(Background.fill(Color.LIGHTSKYBLUE));
l.setTextFill(Color.BLACK);
Platform.runLater(new Runnable() {
@Override
public void run() {
vBoxChatMessages.getChildren().add(l);
}
});
}
}