1
1
package appscreen ;
2
2
3
+ import testerEntities .Chat ;
4
+
3
5
import javax .swing .*;
4
6
import java .awt .*;
5
- import java .awt .event .ActionEvent ;
6
- import java .awt .event .ActionListener ;
7
7
import java .util .ArrayList ;
8
- import testerEntities .*;
9
8
10
9
public class AppScreen implements AppScreenPresenter , AppScreenController , ChatName , Refresh {
11
10
@@ -31,13 +30,24 @@ public AppScreen(String currentUsername, ArrayList<Chat> chats) {
31
30
// top panel containing the buttons for creating a new chat
32
31
JPanel topPanel = new JPanel ();
33
32
topPanel .setLayout (new GridLayout (1 ,2 ));
33
+
34
34
JButton addPrivateChat = new JButton ("+ Private Chat" );
35
35
JButton addGroupChat = new JButton ("+ Group Chat" );
36
36
37
37
addPrivateChat .setPreferredSize (new Dimension (40 , 30 ));
38
38
addGroupChat .setPreferredSize (new Dimension (40 , 30 ));
39
39
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
+
41
51
42
52
topPanel .add (addPrivateChat );
43
53
topPanel .add (addGroupChat );
@@ -80,16 +90,10 @@ public void displayAppScreen(){
80
90
b .add (jLabel );
81
91
82
92
// defines the action of opening a chat when a chat is clicked on
83
- b .addActionListener (new ActionListener () {
93
+ b .addActionListener (e -> {
84
94
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 ();
93
97
});
94
98
jPanel .add (b );
95
99
}
@@ -206,11 +210,4 @@ public Chat getChat(String chatID) {
206
210
throw new RuntimeException ("Current user is not part of this chat" );
207
211
}
208
212
209
- /**
210
- * Get the username of the current user
211
- * @return currentUserName
212
- */
213
- public String getCurrentUsername () {
214
- return currentUsername ;
215
- }
216
213
}
0 commit comments