- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserControlPanel.java
More file actions
Latest commit
170 lines (131 loc) · 4.92 KB
/
Copy pathUserControlPanel.java
File metadata and controls
170 lines (131 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
importjava.awt.BorderLayout;
importjava.awt.Color;
importjava.awt.Dimension;
importjava.awt.GridLayout;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjavax.swing.BorderFactory;
importjavax.swing.JButton;
importjavax.swing.JFrame;
importjavax.swing.JPanel;
importjavax.swing.JScrollPane;
importjavax.swing.JTextArea;
importjavax.swing.border.Border;
publicclassUserControlPanel {
privateUseruser;
privateStringname;
privateJFrameuserFrame;
privateJTextAreauserID;
privateJButtonfollow;
privateJTextAreafollowing;
privateJTextAreatweet;
privateJButtonpostTweet;
privateJTextAreaposts;
privateJPanelupperPanel;
privateJPanelfollowingPanel;
privateJPaneltweetingPanel;
privateJPanelpostsPanel;
privateJPanelcontainerPanel;
//initialize the user control panel
publicvoidinitializeUI(StringuserName, Useruser) {
this.user = user;
this.name = userName;
userFrame = newJFrame(userName);
userFrame.setSize(400, 300);
userFrame.setVisible(true);
this.userID = newJTextArea();
this.follow = newJButton("Follow");
this.following = newJTextArea();
this.following.setPreferredSize(newDimension(175, 350));
this.following.setEditable(false);
this.tweet = newJTextArea();
this.postTweet = newJButton("Post");
this.posts = newJTextArea();
this.posts.setPreferredSize(newDimension(275, 325));
this.posts.setEditable(false);
this.upperPanel = newJPanel();
this.followingPanel = newJPanel();
this.followingPanel.setPreferredSize(newDimension(200, 300));
this.tweetingPanel = newJPanel();
this.postsPanel = newJPanel();
this.containerPanel = newJPanel();
containerPanel.setPreferredSize(newDimension(300, 400));
renderWindow();
}
//renders the window with all panels added
privatevoidrenderWindow() {
BorderfollowingBorder = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.RED), "Live View (Current Following)");
BorderupperPanelBorder = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.GREEN), "Follow Users");
BordertweetingPanelBorder = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLUE), "Tweet a message");
BorderpostsPanelBorder = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.YELLOW), "Live View (News Feed)");
upperPanel.setLayout((newGridLayout(1, 2)));
upperPanel.add(newJScrollPane(userID));
upperPanel.add(follow);
upperPanel.setBorder(upperPanelBorder);
followingPanel.setLayout(newBorderLayout());
followingPanel.add(newJScrollPane(following));
followingPanel.setBorder(followingBorder);
tweetingPanel.setLayout((newGridLayout(1, 2)));
tweetingPanel.add(newJScrollPane(tweet));
tweetingPanel.add(postTweet);
tweetingPanel.setBorder(tweetingPanelBorder);
postsPanel.add(newJScrollPane(posts));
postsPanel.setBorder(postsPanelBorder);
userFrame.setLayout(newBorderLayout());
containerPanel.setLayout(newBorderLayout());
containerPanel.add(upperPanel, BorderLayout.NORTH);
containerPanel.add(tweetingPanel, BorderLayout.SOUTH);
containerPanel.add(postsPanel, BorderLayout.CENTER);
userFrame.add(followingPanel, BorderLayout.WEST);
userFrame.add(containerPanel, BorderLayout.CENTER);
setUpButtons();
userFrame.pack();
userFrame.setVisible(true);
}
//get user ID
publicJTextAreagetUserID() {
returnthis.userID;
}
//get follow button
publicJButtongetFollowButton() {
returnthis.follow;
}
//get the text in tweet
publicJTextAreagetTweet() {
returnthis.tweet;
}
//get post tweet button
publicJButtongetPostTweetButton() {
returnthis.postTweet;
}
//upadates the following tree
publicvoidupdateFollowingTree(StringuserID) {
following.append(userID + "\n");
}
//updates the panel where posts are displayed
publicvoidupdatePostsPanel(StringuserID, Stringtweet) {
posts.append(userID + ": " + tweet + "\n");
}
//sets up button actions
publicvoidsetUpButtons() {
getFollowButton().addActionListener(newActionListener() {
publicvoidactionPerformed(ActionEvente) {
StringuserID = getUserID().getText();
//User userFollowed = new User();
//System.out.println(userID);
if ((user.followUser(userID) == true) && (userID != name)) {
updateFollowingTree(userID);
user.followUser(userID);
getUserID().setText("");
}
}
});
getPostTweetButton().addActionListener(newActionListener() {
publicvoidactionPerformed(ActionEvente) {
Stringmessage = getTweet().getText();
user.postTweet(message);
getTweet().setText("");
}
});
}
}