Skip to content

Commit b20255b

Browse files
committed
Added action listeners to buttons
1 parent 5e93e5e commit b20255b

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

src/main/java/appscreen/AppScreen.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package appscreen;
22

3+
import testerEntities.Chat;
4+
35
import javax.swing.*;
46
import java.awt.*;
5-
import java.awt.event.ActionEvent;
6-
import java.awt.event.ActionListener;
77
import java.util.ArrayList;
8-
import testerEntities.*;
98

109
public class AppScreen implements AppScreenPresenter, AppScreenController, ChatName, Refresh {
1110

@@ -31,13 +30,24 @@ public AppScreen(String currentUsername, ArrayList<Chat> chats) {
3130
// top panel containing the buttons for creating a new chat
3231
JPanel topPanel = new JPanel();
3332
topPanel.setLayout(new GridLayout(1,2));
33+
3434
JButton addPrivateChat = new JButton("+ Private Chat");
3535
JButton addGroupChat = new JButton("+ Group Chat");
3636

3737
addPrivateChat.setPreferredSize(new Dimension(40, 30));
3838
addGroupChat.setPreferredSize(new Dimension(40, 30));
3939

40-
// TODO: implement the action listeners for the buttons +PrivateChat and +GroupChat
40+
// adding the action listeners for the +private-chat and +group-chat buttons
41+
addPrivateChat.addActionListener(e -> {
42+
ChatView newChat = new ChatView(currentUsername, true);
43+
newChat.chatDisplay();
44+
45+
});
46+
addGroupChat.addActionListener(e -> {
47+
ChatView newChat = new ChatView(currentUsername, true);
48+
newChat.chatDisplay();
49+
});
50+
4151

4252
topPanel.add(addPrivateChat);
4353
topPanel.add(addGroupChat);
@@ -80,16 +90,10 @@ public void displayAppScreen(){
8090
b.add(jLabel);
8191

8292
// defines the action of opening a chat when a chat is clicked on
83-
b.addActionListener(new ActionListener() {
93+
b.addActionListener(e -> {
8494

85-
@Override
86-
public void actionPerformed(ActionEvent e) {
87-
88-
/* TODO: call chatView to open the display the window (?) for chat
89-
- not sure if AppScreen and ChatView would be combined into one window, or
90-
two separate windows
91-
*/
92-
}
95+
ChatView newChat = new ChatView(currentUsername, false);
96+
newChat.chatDisplay();
9397
});
9498
jPanel.add(b);
9599
}
@@ -206,11 +210,4 @@ public Chat getChat(String chatID) {
206210
throw new RuntimeException("Current user is not part of this chat");
207211
}
208212

209-
/**
210-
* Get the username of the current user
211-
* @return currentUserName
212-
*/
213-
public String getCurrentUsername() {
214-
return currentUsername;
215-
}
216213
}

0 commit comments

Comments
 (0)