Skip to content

Commit

Permalink
back button added in chat menu
Browse files Browse the repository at this point in the history
  • Loading branch information
faraz1380 committed Jul 24, 2020
1 parent dd129f0 commit 9022c90
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
31 changes: 14 additions & 17 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/main/java/Model/Messaging/Chat.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,6 +15,7 @@ public class Chat {
private ArrayList<Account> members;
private TextField textField;
private int id;
private Button back = new Button("Back");

public TextField getTextField() {
return textField;
Expand Down Expand Up @@ -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;
}
}
8 changes: 7 additions & 1 deletion src/main/java/View/Menu/ChatMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -51,6 +56,7 @@ private void setChat() {
try {
dataOutputStream.writeUTF("getChatById " + chatId);
String input = dataInputStream.readUTF();
if (input == null) return;
Type type = new TypeToken<Chat>(){}.getType();
Chat updatedChat = new Gson().fromJson(input, type);
chat = updatedChat;
Expand Down

0 comments on commit 9022c90

Please sign in to comment.