-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewProfile.java
More file actions
120 lines (102 loc) · 4.27 KB
/
ViewProfile.java
File metadata and controls
120 lines (102 loc) · 4.27 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* ViewProfile.java
*
* This program establishes a way for a user to view the profiles of other users that automatically updates the
* profiles in the event that the other user edits his or her profile.
*
* @author Team 060, Section 11
* @version May 03, 2021
* */
public class ViewProfile extends Profile {
public ViewProfile(Profile profile, IOMachine ioMachine) {
super(profile, ioMachine);
}
public void run() {
frame = new JFrame(getUsername());
frame.setSize(640, 480);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
//Everything below is for the center panel which holds user info
//name panel
JPanel namePanel = new JPanel();
nameText = new JLabel("USER: ");
namePanel.add(nameText);
usernameArea = new JTextArea(getUsername(), 5, 15);
usernameArea.setEditable(false);
namePanel.add(usernameArea);
//phone panel
JPanel phonePanel = new JPanel();
phoneText = new JLabel("PHONE: ");
phonePanel.add(phoneText);
phoneArea = new JTextArea(EnterInfoGUI.formatPhoneString(getPhoneNumber()), 5, 15);
phoneArea.setEditable(false);
phonePanel.add(phoneArea);
//email panel
JPanel emailPanel = new JPanel();
emailText = new JLabel("EMAIL: ");
emailPanel.add(emailText);
emailArea = new JTextArea(getEmail(), 5,15);
emailArea.setEditable(false);
emailPanel.add(emailArea);
//education panel
JPanel educationPanel = new JPanel();
educationText = new JLabel("EDUCATION: ");
educationPanel.add(educationText);
educationArea = new JTextArea(getEducation(), 5, 15);
educationArea.setEditable(false);
educationPanel.add(educationArea);
//about me panel
JPanel aboutMePanel = new JPanel();
aboutMeText = new JLabel("ABOUT ME:");
aboutMePanel.add(aboutMeText);
aboutMeArea = new JTextArea(EnterInfoGUI.formatAboutString(getAboutMe()), 8, 15);
aboutMeArea.setEditable(false);
aboutMePanel.add(aboutMeArea);
//interests panel
JPanel interestsPanel = new JPanel();
interestsText = new JLabel("INTERESTS: ");
interestsPanel.add(interestsText);
interestArea = new JTextArea(EnterInfoGUI.formatInterestsString(getInterests()),
8, 15);
interestArea.setEditable(false);
interestsPanel.add(interestArea);
//Combines the above panels in grid layout
JPanel profilePanel = new JPanel();
profilePanel.setLayout(new GridLayout(3, 2));
profilePanel.add(namePanel);
profilePanel.add(phonePanel);
profilePanel.add(emailPanel);
profilePanel.add(educationPanel);
profilePanel.add(aboutMePanel);
profilePanel.add(interestsPanel);
frame.add(profilePanel, BorderLayout.CENTER);
frame.setVisible(true);
//begins a timer that automatically updates the user list every 3 seconds
Timer timer = new Timer(3000, viewRefresher);
timer.setRepeats(true);
timer.start();
}
//Code that Runs every 3 seconds, updating the profile list
transient ActionListener viewRefresher = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
//gets the most recent version of the profile
Profile updatedProfile = ioMachine.findProfile(getUsername());
//updates the text areas
phoneArea.setText(EnterInfoGUI.formatPhoneString(updatedProfile.getPhoneNumber()));
emailArea.setText(updatedProfile.getEmail());
educationArea.setText(updatedProfile.getEducation());
aboutMeArea.setText(EnterInfoGUI.formatAboutString(updatedProfile.getAboutMe()));
interestArea.setText(EnterInfoGUI.formatInterestsString(updatedProfile.getInterests()));
//updates the GUI
phoneArea.repaint();
emailArea.repaint();
educationArea.repaint();
aboutMeArea.repaint();
interestArea.repaint();
frame.revalidate();
}
};
}