Repository navigation
Expand file tree
/
Copy pathProfilePage.java
More file actions
155 lines (130 loc) · 5.45 KB
/
Copy pathProfilePage.java
File metadata and controls
155 lines (130 loc) · 5.45 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ProfilePage extends JFrame {
private JTextField nameField;
private JTextField emailField;
private JLabel profilePictureLabel;
private JButton saveButton;
private JButton homeButton;
public ProfilePage() {
setTitle("Profile");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setPreferredSize(new Dimension(1080, 800));
getContentPane().setBackground(new Color(240, 233, 212));
// Create components
nameField = new JTextField(20);
emailField = new JTextField(20);
profilePictureLabel = new JLabel();
saveButton = new JButton("Save");
homeButton = new JButton("Home");
// Navigation Bar Panel
JPanel navBarPanel = new JPanel();
navBarPanel.setBackground(new Color(214, 196, 153));
navBarPanel.setLayout(new BoxLayout(navBarPanel, BoxLayout.X_AXIS));
navBarPanel.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20));
// Home Icon Label
ImageIcon homeIcon = new ImageIcon("images/home.png");
Image homeImage = homeIcon.getImage();
Image newHomeImage = homeImage.getScaledInstance(30, 30, Image.SCALE_SMOOTH);
homeIcon = new ImageIcon(newHomeImage);
JLabel homeIconLabel = new JLabel(homeIcon);
homeIconLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
homeIconLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); // Change cursor to hand when hovering
homeIconLabel.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
dispose(); // Close the current frame
new HomePage("Yevin"); // Create a new instance of HomePage
}
});
// Logo Label
ImageIcon logoIcon = new ImageIcon("images/FurnitureFitLogo.png");
Image image = logoIcon.getImage();
Image newImg = image.getScaledInstance(100, 100, Image.SCALE_SMOOTH);
logoIcon = new ImageIcon(newImg);
JLabel logoLabel = new JLabel(logoIcon);
logoLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
// User Icon Label
ImageIcon userIcon = new ImageIcon("images/user.png");
Image userImage = userIcon.getImage();
Image newUserImage = userImage.getScaledInstance(30, 30, Image.SCALE_SMOOTH);
userIcon = new ImageIcon(newUserImage);
JLabel userIconLabel = new JLabel(userIcon);
userIconLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
// Add components to nav bar panel
navBarPanel.add(homeIconLabel);
navBarPanel.add(Box.createHorizontalGlue());
navBarPanel.add(logoLabel);
navBarPanel.add(Box.createHorizontalGlue());
navBarPanel.add(userIconLabel);
// Set button colors
saveButton.setBackground(new Color(148, 115, 81));
saveButton.setForeground(Color.BLACK);
// Add navigation bar panel to the frame
add(navBarPanel, BorderLayout.NORTH);
// Create a new panel with GridBagLayout for the remaining components
JPanel contentPanel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.CENTER;
gbc.insets = new Insets(10, 10, 10, 10);
contentPanel.add(profilePictureLabel, gbc);
gbc.gridy++;
contentPanel.add(new JLabel("Name:"), gbc);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 2;
gbc.anchor = GridBagConstraints.CENTER;
gbc.insets = new Insets(10, 10, 10, 10);
contentPanel.add(nameField, gbc);
gbc.gridy++;
contentPanel.add(new JLabel("Email:"), gbc);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 4;
gbc.anchor = GridBagConstraints.CENTER;
gbc.insets = new Insets(10, 10, 10, 10);
contentPanel.add(emailField, gbc);
gbc.gridy++;
contentPanel.add(saveButton, gbc);
// Add the content panel to the frame
add(contentPanel, BorderLayout.CENTER);
// Load current profile information
loadProfileInfo();
// Add action listeners
saveButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
saveProfileInfo();
}
});
pack();
setLocationRelativeTo(null);
setVisible(true);
}
private void loadProfileInfo() {
nameField.setText("yevin");
emailField.setText("yevin@example.com");
}
private void saveProfileInfo() {
// Validate and save the updated profile information
String name = nameField.getText();
String email = emailField.getText();
// Perform validation checks
if (name.isEmpty() || email.isEmpty()) {
JOptionPane.showMessageDialog(this, "Please fill in all fields.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
JOptionPane.showMessageDialog(this, "Profile information saved successfully.");
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new ProfilePage();
}
});
}
}