-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAdminDashboard.java
More file actions
170 lines (145 loc) · 6.68 KB
/
Copy pathAdminDashboard.java
File metadata and controls
170 lines (145 loc) · 6.68 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
import javax.swing.*;
import java.awt.*;
public class AdminDashboard extends JFrame {
public AdminDashboard() {
// Set frame properties
setTitle("Admin Dashboard");
setSize(1650, 1080);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
// Main panel with BorderLayout
JPanel mainPanel = new JPanel(new BorderLayout());
mainPanel.setBackground(Color.BLACK);
// Left sidebar panel with options (adjusted to start from the top)
JPanel leftPanel = new JPanel();
leftPanel.setPreferredSize(new Dimension(220, getHeight()));
leftPanel.setBackground(Color.decode("#1a1a1a"));
leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS));
// Icon (Settings)
ImageIcon originalIcon = new ImageIcon(
"C:\\Users\\Shubham Upadhyay\\OneDrive\\Desktop\\VS CODE\\Practice\\OTHER-CLG\\JAVA-MPR\\BlueA.png");
Image iconImage = originalIcon.getImage();
Image scaledIconImage = iconImage.getScaledInstance(100, 100, Image.SCALE_SMOOTH);
ImageIcon scaledIcon = new ImageIcon(scaledIconImage);
JLabel iconLabel = new JLabel(scaledIcon);
iconLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
// Settings button
JButton settingsButton = createButton("View Exam History", 18f);
settingsButton.setAlignmentX(Component.CENTER_ALIGNMENT);
settingsButton.setMaximumSize(new Dimension(200, 50));
settingsButton.addActionListener(e -> viewHistory());
// View Profiles button
JButton homebutton2 = createButton("Back to Home", 18f);
homebutton2.setAlignmentX(Component.CENTER_ALIGNMENT);
homebutton2.setMaximumSize(new Dimension(200, 50));
homebutton2.addActionListener(e -> adminhome());
// Logout button
JButton logoutButton = createButton("Log Out", 18f);
logoutButton.setAlignmentX(Component.CENTER_ALIGNMENT);
logoutButton.setBackground(new Color(73, 0, 204));
logoutButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
logoutButton.setMaximumSize(new Dimension(200, 50));
logoutButton.addActionListener(e -> openHomePage());
// Add components to left panel (starting from the top)
leftPanel.add(iconLabel);
leftPanel.add(Box.createRigidArea(new Dimension(0, 30)));
leftPanel.add(settingsButton);
leftPanel.add(Box.createRigidArea(new Dimension(0, 30)));
leftPanel.add(homebutton2);
leftPanel.add(Box.createVerticalGlue());
leftPanel.add(logoutButton);
// Right panel with GridBagLayout for flexibility
JPanel rightPanel = new JPanel(new GridBagLayout());
rightPanel.setBackground(Color.BLACK);
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(15, 30, 15, 30);
// Welcome label (centered)
JLabel welcomeLabel = new JLabel("Welcome Admin!", JLabel.CENTER);
welcomeLabel.setForeground(Color.WHITE);
welcomeLabel.setFont(new Font("SansSerif", Font.BOLD, 32));
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 2;
gbc.anchor = GridBagConstraints.NORTH;
rightPanel.add(welcomeLabel, gbc);
// Buttons for the admin panel
String[] buttonLabels = {"Modify Subject", "Modify Question"};
int row = 1;
for (String label : buttonLabels) {
JButton button = createButton(label, 20f);
button.setPreferredSize(new Dimension(250, 70));
gbc.gridx = (row - 1) % 2;
gbc.gridy = (row - 1) / 2 + 1;
gbc.gridwidth = 1;
gbc.anchor = GridBagConstraints.CENTER;
// Add action listener for "Add Subject" button
if (label.equals("Modify Question")) {
button.addActionListener(e -> openAdminDashboard2());
}
if (label.equals("Modify Subject")) {
button.addActionListener(e -> modifySubject());
}
rightPanel.add(button, gbc);
row++;
}
// Panel for positioning the logo at the top-right corner
JPanel topRightPanel = new JPanel(new BorderLayout());
topRightPanel.setBackground(Color.BLACK);
ImageIcon logoIcon = new ImageIcon(
"C:\\Users\\Shubham Upadhyay\\OneDrive\\Desktop\\VS CODE\\Practice\\OTHER-CLG\\JAVA-MPR\\TechSage.Logo.jpg");
Image logoImage = logoIcon.getImage();
Image scaledLogoImage = logoImage.getScaledInstance(200, 200, Image.SCALE_SMOOTH); // Increased size to 250x250
ImageIcon scaledLogoIcon = new ImageIcon(scaledLogoImage);
JLabel logoLabel = new JLabel(scaledLogoIcon);
logoLabel.setHorizontalAlignment(JLabel.RIGHT);
// Add the logo to topRightPanel
topRightPanel.add(logoLabel, BorderLayout.EAST);
mainPanel.add(topRightPanel, BorderLayout.NORTH); // Logo at top-right corner
// Add panels to the main panel
mainPanel.add(leftPanel, BorderLayout.WEST); // Left sidebar to the west
mainPanel.add(rightPanel, BorderLayout.CENTER); // Right side content
// Add main panel to the frame
add(mainPanel);
}
// Utility method to create a styled button
private JButton createButton(String text, float fontSize) {
JButton button = new JButton(text);
button.setFont(button.getFont().deriveFont(fontSize));
button.setBackground(new Color(73, 0, 204));
button.setForeground(Color.WHITE);
button.setFocusPainted(false);
return button;
}
public void openHomePage() {
this.dispose();
TechSageMain mainPage = new TechSageMain();
mainPage.setVisible(true);
}
public void viewHistory()
{
this.dispose();
ExamHistory history = new ExamHistory();
history.setVisible(true);
}
public void openAdminDashboard2() {
this.dispose(); // Close the current AdminDashboard frame
AdminDashboard2 dashboard2 = new AdminDashboard2();
dashboard2.setVisible(true); // Open the new AdminDashboard2 frame
}
public void modifySubject() {
this.dispose(); // Close the current AdminDashboard frame
ModifySubject modifySubject = new ModifySubject();
modifySubject.setVisible(true); // Open the new ModifySubject frame
}
public void adminhome() {
this.dispose();
AdminDashboard home = new AdminDashboard();
home.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
AdminDashboard frame = new AdminDashboard();
frame.setVisible(true);
});
}
}