1
- package chatlinitation ;
1
+ package screens . chat_screen ;
2
2
3
3
4
4
import javax .swing .*;
5
+ import javax .swing .border .EmptyBorder ;
5
6
6
7
7
8
import java .awt .*;
15
16
* "userB'S username." AT the bottom of the frame, there is another text field to type a message and
16
17
* send button to send the message
17
18
*
18
- * In the middle of the frame I put andJTextArea for the chat History .
19
+ * In the middle of the frame there i sJpanel and Jlabels for the converstaion history .
19
20
*
20
21
*/
21
22
26
27
27
28
class ChatView extends JFrame implements ActionListener {
28
29
29
- private ChatViewmodel viewmodel ;
30
+ // private ChatInteractor chatInteractor ;
30
31
private JFrame frame ;
31
32
private JButton addbutton ;
32
- private JButton send ;
33
+ private JButton sendbutton ;
33
34
private JLabel l ;
34
35
private JLabel label ;
35
36
private JTextField usernametextfield ;
36
37
private JTextField messagetextfield ;
37
38
private JMenuBar menubar ;
38
39
private JPanel panel ;
39
- private JTextArea textArea ;
40
+
41
+ private JPanel conversationHistoryPanel ;
42
+ private JPanel messagePanel ;
43
+ private JLabel testMessageHeader ;
44
+ private JLabel testMessage ;
45
+
46
+ //isNewchat check we already have a chat with a user
47
+ private boolean isNewchat ;
48
+
40
49
41
50
42
51
//this is constructor od this class
43
- public ChatView (){
44
- viewmodel = new ChatViewmodel ();
52
+ public ChatView (boolean isNewchat ){
53
+
54
+ this .isNewchat = isNewchat ;
55
+
45
56
frame = new JFrame ();
46
57
47
58
// create a menubar at the top of the frame
@@ -59,7 +70,8 @@ public ChatView(){
59
70
addbutton = new JButton ("add" );
60
71
addbutton .setFocusable (false );
61
72
62
-
73
+ // create conversation history-related components
74
+ conversationHistoryPanel = new JPanel ();
63
75
64
76
//create a new "panel" and new "label" and a text flied ."label"a nd "txtfield1"
65
77
panel = new JPanel ();
@@ -68,13 +80,14 @@ public ChatView(){
68
80
69
81
70
82
//adding "send" button
71
- send = new JButton ("Send" );
72
- send .setFocusable (false );
83
+ sendbutton = new JButton ("Send" );
84
+ sendbutton .setFocusable (false );
73
85
74
86
75
87
}
76
88
77
89
90
+
78
91
// create a setup for display of buttons and other component of the frame.
79
92
public void chatdisplay (){
80
93
@@ -94,18 +107,51 @@ public void chatdisplay(){
94
107
// adding label and textfiled1 to our panel .
95
108
panel .add (label );
96
109
panel .add (messagetextfield );
97
- panel .add (send );
110
+ panel .add (sendbutton );
111
+
112
+
98
113
114
+ // add content to conversationHistoryPanel
115
+ conversationHistoryPanel .setLayout (new BoxLayout (conversationHistoryPanel , BoxLayout .Y_AXIS ));
116
+
117
+ // messagePanel = new JPanel();
118
+ // messagePanel.setLayout(new BoxLayout(messagePanel, BoxLayout.Y_AXIS));
119
+ // testMessageHeader = new JLabel("Username placeholder | Timestamp placeholder");
120
+ // testMessage = new JLabel("Message placeholder");
121
+ // messagePanel.add(testMessageHeader);
122
+ // messagePanel.add(testMessage);
123
+ //
124
+ // conversationHistoryPanel.add(messagePanel);
125
+
126
+ JPanel messagePanel1 = new JPanel ();
127
+ messagePanel1 .setLayout (new BoxLayout (messagePanel1 , BoxLayout .Y_AXIS ));
128
+ messagePanel1 .setBorder (new EmptyBorder (10 , 10 , 10 , 10 ));
129
+ JLabel testMessageHeader1 = new JLabel ("Username placeholder1 | Timestamp placeholder" );
130
+ JLabel testMessage1 = new JLabel ("Message placeholder1" );
131
+ messagePanel1 .add (testMessageHeader1 );
132
+ messagePanel1 .add (testMessage1 );
133
+
134
+ JPanel messagePanel2 = new JPanel ();
135
+ messagePanel2 .setLayout (new BoxLayout (messagePanel2 , BoxLayout .Y_AXIS ));
136
+ messagePanel2 .setBorder (new EmptyBorder (10 , 10 , 10 , 10 ));
137
+ JLabel testMessageHeader2 = new JLabel ("Username placeholder2 | Timestamp placeholder" );
138
+ JLabel testMessage2 = new JLabel ("Message placeholder2" );
139
+ messagePanel2 .add (testMessageHeader2 );
140
+ messagePanel2 .add (testMessage2 );
141
+
142
+ conversationHistoryPanel .add (messagePanel1 );
143
+ conversationHistoryPanel .add (messagePanel2 );
99
144
100
145
101
- // set the text part in the middle
102
- textArea = new JTextArea ();
103
146
104
147
105
148
//Locating the Components to the frame.
106
149
frame .getContentPane ().add (BorderLayout .SOUTH , panel );
107
- frame .getContentPane ().add (BorderLayout .NORTH , menubar );
108
- frame .getContentPane ().add (BorderLayout .CENTER , textArea );
150
+ if (isNewchat ){
151
+ frame .getContentPane ().add (BorderLayout .NORTH , menubar );
152
+ }
153
+
154
+ frame .getContentPane ().add (BorderLayout .CENTER , conversationHistoryPanel );
109
155
110
156
// set the frame visibile
111
157
frame .setVisible (true );
@@ -127,11 +173,14 @@ public void actionPerformed(ActionEvent e) {
127
173
128
174
129
175
if (e .getSource () == addbutton ){
176
+
130
177
String input = usernametextfield .getText ();
178
+
131
179
frame .setTitle (input );
180
+ //controller:
132
181
133
- //set the username in our viewmodel
134
- viewmodel .setRecipientUsername (input );
182
+ // set the username in our viewmodel
183
+ // chatInteractor .setRecipientUsername(input);
135
184
136
185
//todo
137
186
//we should find the user with username "input" from list of user's that have logged in and set the
@@ -148,12 +197,12 @@ public void actionPerformed(ActionEvent e) {
148
197
149
198
//first is to convert textfield input to String and set the frame title to that input.
150
199
151
- if (e .getSource () == send ){
200
+ if (e .getSource () == sendbutton ){
152
201
//when the messge type is STring
153
202
String input = usernametextfield .getText ();
154
203
155
- //setting the txtmessage content in our viewmodel
156
- viewmodel .setMessage (input );
204
+ // getting the txtmessage content in our viewmodel
205
+ // chatInteractor .setMessage(input);
157
206
158
207
//todo
159
208
//this is part of the chatHisroy of UI. for now I put a text ( it may needed to change later)
@@ -164,13 +213,15 @@ public static void main(String args[]) {
164
213
EventQueue .invokeLater (new Runnable () {
165
214
@ Override
166
215
public void run () {
167
- ChatView chat = new ChatView ();
216
+ ChatView chat = new ChatView (true );
217
+ // chat.getframe().setTitle("AMMY")
168
218
chat .chatdisplay ();
169
219
170
220
chat .addbutton .addActionListener (chat );
221
+ chat .sendbutton .addActionListener (chat );
222
+
171
223
//todo
172
- //after chat history is done next line code can run.
173
- // chat.send.addActionListener(chat);
224
+ //chat history
174
225
175
226
176
227
}
0 commit comments