50 lines
1.4 KiB
Java
50 lines
1.4 KiB
Java
package fr.univ.lyon1.gui.handlers;
|
|
|
|
import fr.univ.lyon1.common.ServerConfiguration;
|
|
import fr.univ.lyon1.gui.ClientGUI;
|
|
import fr.univ.lyon1.gui.ClientPanel;
|
|
import javafx.scene.Group;
|
|
import javafx.scene.Scene;
|
|
import javafx.stage.Stage;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import java.io.IOException;
|
|
|
|
public class MainHandler implements Handler {
|
|
private ClientPanel clientPanel;
|
|
@Nullable
|
|
private ClientGUI client;
|
|
|
|
@Override
|
|
public void launch(Stage stage) throws IOException, InterruptedException {
|
|
@NotNull
|
|
final ServerConfiguration serverConfiguration = ServerConfiguration.load();
|
|
this.client = new ClientGUI(this, serverConfiguration.getAddress(), serverConfiguration.getPort());
|
|
|
|
stage.setTitle("Chat client");
|
|
stage.setWidth(440);
|
|
|
|
this.clientPanel = new ClientPanel(this);
|
|
Group root = new Group();
|
|
root.getChildren().add(this.clientPanel);
|
|
Scene scene = new Scene(root, 600, 500);
|
|
|
|
stage.setScene(scene);
|
|
stage.show();
|
|
|
|
if (this.client != null) {
|
|
this.client.run();
|
|
}
|
|
}
|
|
|
|
public void sendMessage(String msg) {
|
|
if (client != null) {
|
|
client.sendMessage(msg);
|
|
}
|
|
}
|
|
|
|
public void receiveMessage(String msg) {
|
|
clientPanel.addMessage(msg);
|
|
}
|
|
}
|