1
1
package screens .chat_screen ;
2
2
3
3
4
+ import use_cases .chat_initiation_use_case .ChatInteractor ;
5
+ import use_cases .chat_initiation_use_case .CheckUsername_Interactor ;
6
+
4
7
import javax .swing .*;
5
8
import javax .swing .border .EmptyBorder ;
6
9
20
23
*
21
24
*/
22
25
23
- //todo: we should complete the chatHistory in this class.
24
-
25
-
26
26
27
27
28
28
class ChatView extends JFrame implements ActionListener {
29
+ //use two Interactors .
30
+ private ChatInteractor chatInteractor ;
31
+ private CheckUsername_Interactor checkusername_interactor ;
29
32
30
- // private ChatInteractor chatInteractor;
31
- private JFrame frame ;
33
+ //Use Jframes, butttons, labels ,textfileds, Jpannels,JMenuBar for UI.
34
+ final JFrame frame ;
32
35
private JButton addbutton ;
33
- private JButton sendbutton ;
34
- private JLabel l ;
35
- private JLabel label ;
36
- private JTextField usernametextfield ;
37
- private JTextField messagetextfield ;
38
- private JMenuBar menubar ;
39
- private JPanel panel ;
40
-
41
- private JPanel conversationHistoryPanel ;
36
+ final JButton sendbutton ;
37
+ final JLabel l ;
38
+ final JLabel label ;
39
+ final JTextField usernametextfield ;
40
+ final JTextField messagetextfield ;
41
+ final JMenuBar menubar ;
42
+ final JPanel panel ;
43
+
44
+ final JPanel conversationHistoryPanel ;
45
+
42
46
private JPanel messagePanel ;
43
47
private JLabel testMessageHeader ;
44
48
private JLabel testMessage ;
@@ -48,11 +52,13 @@ class ChatView extends JFrame implements ActionListener{
48
52
49
53
50
54
51
- //this is constructor od this class
52
- public ChatView (boolean isNewchat ){
55
+
56
+ //this is constructor
57
+ public ChatView ( boolean isNewchat ){
53
58
54
59
this .isNewchat = isNewchat ;
55
60
61
+
56
62
frame = new JFrame ();
57
63
58
64
// create a menubar at the top of the frame
@@ -87,7 +93,6 @@ public ChatView(boolean isNewchat){
87
93
}
88
94
89
95
90
-
91
96
// create a setup for display of buttons and other component of the frame.
92
97
public void chatdisplay (){
93
98
@@ -151,83 +156,76 @@ public void chatdisplay(){
151
156
frame .getContentPane ().add (BorderLayout .NORTH , menubar );
152
157
}
153
158
159
+
154
160
frame .getContentPane ().add (BorderLayout .CENTER , conversationHistoryPanel );
155
161
156
162
// set the frame visibile
157
163
frame .setVisible (true );
158
164
165
+ this .addbutton .addActionListener (this );
166
+ this .sendbutton .addActionListener (this );
167
+
159
168
160
169
}
161
170
162
171
163
- // we implement the Actionlistener class so we should implement this method.
164
- // this method create an action for our buttons
165
- //we use our viewmodel attribute inn this method.
172
+
173
+ //we implement ActionListener class and should override this method for our button's actions.
174
+
166
175
@ Override
167
176
public void actionPerformed (ActionEvent e ) {
168
177
169
178
// STEP1: action for the "add button" at the top of frame.
170
- // goal : we want to write user'sB username in text filed and click "add buttom" to change our chat frame title
171
- // to user'sB username.
172
- // first we convert textfield input to String and set the frame title to that input.
179
+ // goal : click on add button will change the chat frame's title to user'sB username(typed in the textfiled)
173
180
174
181
175
182
if (e .getSource () == addbutton ){
176
-
183
+ // convert textfield input to String and set the frame title to that input is username exists.
177
184
String input = usernametextfield .getText ();
185
+ if (checkusername_interactor .checkusername (input )){
186
+ frame .setTitle (input );
187
+ }
178
188
179
- frame .setTitle (input );
180
- //controller:
181
-
182
- // set the username in our viewmodel
183
- // chatInteractor.setRecipientUsername(input);
184
-
185
- //todo
186
- //we should find the user with username "input" from list of user's that have logged in and set the
187
- // user to have the same chat_ID (I did this in the viewmodel)
188
-
189
+ // also set the input -will change the private chat's RecipientUsername .
190
+ chatInteractor .setRecipientUsername (input );
189
191
190
192
}
191
193
194
+
192
195
// STEP2: action for the "send button".
193
196
// goal : to write a message in txt filed and click "send button"
194
- // so the message will come in the "txtArea" in middle of frame
195
- //again we convert the txfield input to a String .
196
-
197
-
198
- //first is to convert textfield input to String and set the frame title to that input.
197
+ // so the message will come in the middle of the frame
199
198
200
199
if (e .getSource () == sendbutton ){
201
- //when the messge type is STring
202
- String input = usernametextfield .getText ();
203
-
204
- // getting the txtmessage content in our viewmodel
205
- // chatInteractor.setMessage(input);
206
-
207
- //todo
208
- //this is part of the chatHisroy of UI. for now I put a text ( it may needed to change later)
209
-
210
- }
211
- }
212
- public static void main (String args []) {
213
- EventQueue .invokeLater (new Runnable () {
214
- @ Override
215
- public void run () {
216
- ChatView chat = new ChatView (true );
217
- // chat.getframe().setTitle("AMMY")
218
- chat .chatdisplay ();
219
200
220
- chat . addbutton . addActionListener ( chat );
221
- chat . sendbutton . addActionListener ( chat );
201
+ //convert the text field input to a String
202
+ String input = usernametextfield . getText ( );
222
203
223
- //todo
224
- //chat history
204
+ // setting our messge in the chatInteractor- will add this message to conv history.
205
+ chatInteractor . setMessage ( input );
225
206
207
+ //TODO:this is chatHisroy action.
226
208
227
- }
228
- });
229
209
210
+ }
230
211
}
212
+ // public static void main(String args[]) {
213
+ // EventQueue.invokeLater(new Runnable() {
214
+ // @Override
215
+ // public void run() {
216
+ // ChatView chat = new ChatView(true);
217
+ //// chat.getframe().setTitle("AMMY")
218
+ // chat.chatdisplay();
219
+ //
220
+ //
221
+ // //todo
222
+ // //chat history
223
+ //
224
+ //
225
+ // }
226
+ // });
227
+ //
228
+ // }
231
229
232
230
}
233
231
0 commit comments