1
1
package screens .chat_screen ;
2
2
3
3
4
+
5
+
6
+ import javax .swing .*;
7
+ import javax .swing .border .EmptyBorder ;
8
+
9
+
10
+ import java .awt .*;
11
+ import java .awt .event .ActionEvent ;
12
+ import java .awt .event .ActionListener ;
13
+
14
+
15
+ import entities .chat .CommonPrivatechat ;
16
+ import entities .chat .PrivateChatfactory ;
17
+ import use_cases .chat_initiation_use_case .ChatInputBoundry ;
4
18
import use_cases .chat_initiation_use_case .ChatInteractor ;
5
- import use_cases .chat_initiation_use_case .CheckUsername_Interactor ;
19
+ import use_cases .chat_initiation_use_case .ChatModel ;
20
+
6
21
7
22
import javax .swing .*;
8
23
import javax .swing .border .EmptyBorder ;
25
40
26
41
27
42
public class ChatView extends JFrame implements ActionListener {
28
- //use two Interactors .
29
- private ChatInteractor chatInteractor ;
30
- private CheckUsername_Interactor checkusername_interactor ;
43
+ //use Contrroller
44
+
45
+ private ChatController controller ;
31
46
32
47
//Use Jframes, butttons, labels ,textfileds, Jpannels,JMenuBar for UI.
33
48
final JFrame frame ;
@@ -52,9 +67,10 @@ public class ChatView extends JFrame implements ActionListener{
52
67
53
68
54
69
55
- //this is constructor
56
- public ChatView ( boolean isNewchat ){
57
70
71
+ //this is constructor
72
+ public ChatView ( ChatController controller , boolean isNewchat ){
73
+ this .controller = controller ;
58
74
this .isNewchat = isNewchat ;
59
75
60
76
@@ -89,11 +105,7 @@ public ChatView( boolean isNewchat){
89
105
sendbutton .setFocusable (false );
90
106
91
107
92
- }
93
-
94
-
95
- // create a setup for display of buttons and other component of the frame.
96
- public void chatDisplay (){
108
+ // create a setup for display of buttons and other component of the frame.
97
109
98
110
// set frame size and frame title
99
111
frame .setSize (450 , 500 );
@@ -107,14 +119,12 @@ public void chatDisplay(){
107
119
menubar .add (addbutton );
108
120
109
121
110
-
111
122
// adding label and textfiled1 to our panel .
112
123
panel .add (label );
113
124
panel .add (messagetextfield );
114
125
panel .add (sendbutton );
115
126
116
127
117
-
118
128
// add content to conversationHistoryPanel
119
129
conversationHistoryPanel .setLayout (new BoxLayout (conversationHistoryPanel , BoxLayout .Y_AXIS ));
120
130
@@ -147,11 +157,9 @@ public void chatDisplay(){
147
157
conversationHistoryPanel .add (messagePanel2 );
148
158
149
159
150
-
151
-
152
160
//Locating the Components to the frame.
153
161
frame .getContentPane ().add (BorderLayout .SOUTH , panel );
154
- if (isNewchat ){
162
+ if (isNewchat ) {
155
163
frame .getContentPane ().add (BorderLayout .NORTH , menubar );
156
164
}
157
165
@@ -168,63 +176,55 @@ public void chatDisplay(){
168
176
}
169
177
170
178
171
-
172
179
//we implement ActionListener class and should override this method for our button's actions.
173
180
174
181
@ Override
175
182
public void actionPerformed (ActionEvent e ) {
176
183
177
184
// STEP1: action for the "add button" at the top of frame.
178
- // goal : click on add button will change the chat frame's title to user'sB username(typed in the textfiled)
179
-
180
185
181
186
if (e .getSource () == addbutton ){
182
187
// convert textfield input to String and set the frame title to that input is username exists.
188
+
183
189
String input = usernametextfield .getText ();
184
- if (checkusername_interactor .checkusername (input )){
185
- frame .setTitle (input );
186
- }
190
+ controller .create (input );
191
+
187
192
188
- // also set the input -will change the private chat's RecipientUsername .
189
- chatInteractor .setRecipientUsername (input );
193
+ frame .setTitle (input );
190
194
191
195
}
192
196
193
197
194
198
// STEP2: action for the "send button".
195
- // goal : to write a message in txt filed and click "send button"
196
- // so the message will come in the middle of the frame
197
199
198
200
if (e .getSource () == sendbutton ){
199
201
200
- //convert the text field input to a String
201
- String input = usernametextfield .getText ();
202
-
203
- // setting our messge in the chatInteractor- will add this message to conv history.
204
- chatInteractor .setMessage (input );
205
-
206
202
//TODO:this is chatHisroy action.
207
203
208
204
209
205
}
206
+
210
207
}
208
+
209
+
210
+
211
211
// public static void main(String args[]) {
212
- // EventQueue.invokeLater(new Runnable() {
213
- // @Override
214
- // public void run() {
215
- // ChatView chat = new ChatView(true);
216
- //// chat.getframe().setTitle("AMMY")
217
- // chat.chatdisplay();
218
212
//
213
+ // PrivateChatfactory chatfactory = new CommonPrivatechat();
214
+ // ChatInputBoundry Interactor = new ChatInteractor(chatfactory);
215
+ // ChatController controller = new ChatController(Interactor);
216
+ // new ChatView(controller,true);
219
217
//
220
- // //todo
221
- // //chat history
218
+ // controller.create(new ChatModel("Hi").getRecipientusername());
222
219
//
220
+ // new ChatView(controller,true);
221
+ //// // find the created privatechat and the username
222
+ //// System.out.println(controller.getNewprivatechat().getRecipientUsername());
223
223
//
224
- // }
225
- // });
226
224
//
227
225
// }
228
226
227
+
229
228
}
230
229
230
+
0 commit comments