From 9022c9012edfd915545c464b7bf40d15cebf7de4 Mon Sep 17 00:00:00 2001 From: Sony Date: Fri, 24 Jul 2020 11:58:24 +0430 Subject: [PATCH] back button added in chat menu --- .idea/workspace.xml | 31 +++++++++++-------------- src/main/java/Model/Messaging/Chat.java | 7 ++++++ src/main/java/View/Menu/ChatMenu.java | 8 ++++++- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5b25b82..64ff424 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,10 +2,7 @@ - - - @@ -371,13 +368,6 @@ - - 1589828474462 - 1589833893359 - @@ -722,7 +719,6 @@ @@ -844,10 +841,10 @@ - + - + @@ -888,10 +885,10 @@ - + - + diff --git a/src/main/java/Model/Messaging/Chat.java b/src/main/java/Model/Messaging/Chat.java index 3a3be98..97c96c8 100644 --- a/src/main/java/Model/Messaging/Chat.java +++ b/src/main/java/Model/Messaging/Chat.java @@ -1,6 +1,7 @@ package Model.Messaging; import Model.Account.Account; +import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ScrollPane; import javafx.scene.control.TextField; @@ -14,6 +15,7 @@ public class Chat { private ArrayList members; private TextField textField; private int id; + private Button back = new Button("Back"); public TextField getTextField() { return textField; @@ -62,8 +64,13 @@ public ScrollPane showChat() { } TextField textField = new TextField(); this.textField = textField; + vBox.getChildren().add(back); vBox.getChildren().add(textField); chatRoom.setContent(vBox); return chatRoom; } + + public Button getBackButton() { + return back; + } } diff --git a/src/main/java/View/Menu/ChatMenu.java b/src/main/java/View/Menu/ChatMenu.java index eb591be..7ebcf2c 100644 --- a/src/main/java/View/Menu/ChatMenu.java +++ b/src/main/java/View/Menu/ChatMenu.java @@ -30,8 +30,13 @@ public void show() { window.setScene(scene); } - public void run() { + @Override + public void execute() { TextField textField = chat.getTextField(); + chat.getBackButton().setOnAction(e -> { + parentMenu.show(); + parentMenu.execute(); + }); textField.setOnAction(e -> { // if e == enter.key chat.addMessage(new Message(account, textField.getText())); @@ -51,6 +56,7 @@ private void setChat() { try { dataOutputStream.writeUTF("getChatById " + chatId); String input = dataInputStream.readUTF(); + if (input == null) return; Type type = new TypeToken(){}.getType(); Chat updatedChat = new Gson().fromJson(input, type); chat = updatedChat;