-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainPage.java
79 lines (68 loc) · 3.02 KB
/
MainPage.java
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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MainPage extends JFrame {
public MainPage() {
super("Online Exam Registration");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Maximize the window
setExtendedState(JFrame.MAXIMIZED_BOTH);
// Optional: Uncomment the following line to hide the window's title bar and border
// setUndecorated(true);
// Main panel with background image
JPanel mainPanel = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
ImageIcon imageIcon = new ImageIcon("images\\main_bg.jpg");
Image image = imageIcon.getImage();
g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
}
};
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
// Heading label with custom font
JLabel lblHeading = new JLabel("Online Exam Registration", SwingConstants.CENTER);
lblHeading.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 24));
lblHeading.setForeground(Color.red);
lblHeading.setAlignmentX(Component.CENTER_ALIGNMENT);
// Customize and add buttons, action listeners, etc., as previously shown
JButton btnRegister = new JButton("Register");
JButton btnLogin = new JButton("Login");
btnRegister.setFont(new Font("Arial", Font.PLAIN, 18));
btnLogin.setFont(new Font("Arial", Font.PLAIN, 18));
btnRegister.setMaximumSize(new Dimension(200, 50));
btnLogin.setMaximumSize(new Dimension(200, 50));
btnRegister.setAlignmentX(Component.CENTER_ALIGNMENT);
btnLogin.setAlignmentX(Component.CENTER_ALIGNMENT);
// Action listeners for buttons
btnRegister.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Open the registration form here.");
new RegistrationForm().setVisible(true);
}
});
btnLogin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Open the login form here.");
new LoginForm().setVisible(true);
}
});
// Add components to the main panel
mainPanel.add(Box.createVerticalGlue());
mainPanel.add(lblHeading);
mainPanel.add(Box.createRigidArea(new Dimension(0, 20))); // Spacer
mainPanel.add(btnRegister);
mainPanel.add(Box.createRigidArea(new Dimension(0, 10))); // Spacer
mainPanel.add(btnLogin);
mainPanel.add(Box.createVerticalGlue());
// Add main panel to the frame
this.add(mainPanel);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new MainPage().setVisible(true);
}
});
}
}