学生表(包含学生信息) 用户表(包含用户角色和登录信息) 请假申请表(包含请假相关信息) 审批记录表(记录每次审批的结果) 使用Java Swing创建用户登录界面,并根据角色跳转到不同的功能界面。 学生界面:显示学生信息和请假申请表单,可以提交新的请假申请或编辑已有申请。 辅导员界面:显示待审批的请假申请列表,可以进行审批操作。 院领导界面:显示待审批的请假申请列表,可以进行审批操作。 校领导界面:显示待审批的请假申请列表,可以进行审批操作。 在学生界面中,根据登录学号自动填写学生信息。用户手动填写其余请假信息,并提交申请到数据库中。 在辅导员、院领导和校领导界面中,显示待审批的请假申请列表。根据请假天数判断需要哪些角色审批,审批通过或驳回后更新数据库中的请假申请表和审批记录表。 如果审批被驳回,学生可以重新编辑请假申请并再次提交审批。 所有角色都可以查看审批记录,包括申请人、辅导员、院领导和校领导。 根据描述生成相应swing代码,并带着java对数据库操作
时间: 2024-04-08 09:35:27 浏览: 19
以下是使用Java Swing创建用户登录界面的示例代码:
```java
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class LoginFrame extends JFrame {
private JTextField usernameTextField;
private JPasswordField passwordField;
private JComboBox<String> roleComboBox;
private JButton loginButton;
public LoginFrame() {
setTitle("User Login");
setSize(300, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(4, 2));
JLabel usernameLabel = new JLabel("Username:");
usernameTextField = new JTextField();
JLabel passwordLabel = new JLabel("Password:");
passwordField = new JPasswordField();
JLabel roleLabel = new JLabel("Role:");
String[] roles = {"Student", "Instructor", "Dean"};
roleComboBox = new JComboBox<>(roles);
loginButton = new JButton("Login");
panel.add(usernameLabel);
panel.add(usernameTextField);
panel.add(passwordLabel);
panel.add(passwordField);
panel.add(roleLabel);
panel.add(roleComboBox);
panel.add(new JLabel()); // Empty label for alignment
panel.add(loginButton);
add(panel);
loginButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String username = usernameTextField.getText();
String password = new String(passwordField.getPassword());
String role = (String) roleComboBox.getSelectedItem();
// Perform authentication and role-based redirection here
if (authenticate(username, password, role)) {
redirectToFunctionalityPage(role);
} else {
JOptionPane.showMessageDialog(LoginFrame.this, "Invalid login credentials", "Login Error", JOptionPane.ERROR_MESSAGE);
}
}
});
}
private boolean authenticate(String username, String password, String role) {
// Perform authentication logic here
// You can check against the user table in the database
// Return true for successful authentication, false otherwise
return true;
}
private void redirectToFunctionalityPage(String role) {
// Open the functionality page based on the selected role
if (role.equals("Student")) {
StudentFrame studentFrame = new StudentFrame();
studentFrame.setVisible(true);
} else if (role.equals("Instructor")) {
InstructorFrame instructorFrame = new InstructorFrame();
instructorFrame.setVisible(true);
} else if (role.equals("Dean")) {
DeanFrame deanFrame = new DeanFrame();
deanFrame.setVisible(true);
}
// Close the login frame
dispose();
}
public static void main(String[] args) {
LoginFrame loginFrame = new LoginFrame();
loginFrame.setVisible(true);
}
}
```
以上代码创建了一个登录界面,其中包含用户名、密码和角色的输入框,以及一个登录按钮。用户输入正确的登录凭据后,根据所选角色跳转到不同的功能界面。
以下是示例的学生界面代码:
```java
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class StudentFrame extends JFrame {
private JTextField studentIdTextField;
private JTextField studentNameTextField;
private JTextArea leaveApplicationTextArea;
private JButton submitButton;
private JButton editButton;
public StudentFrame() {
setTitle("Student Interface");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(4, 2));
JLabel studentIdLabel = new JLabel("Student ID:");
studentIdTextField = new JTextField();
JLabel studentNameLabel = new JLabel("Student Name:");
studentNameTextField = new JTextField();
JLabel leaveApplicationLabel = new JLabel("Leave Application:");
leaveApplicationTextArea = new JTextArea();
submitButton = new JButton("Submit");
editButton = new JButton("Edit");
panel.add(studentIdLabel);
panel.add(studentIdTextField);
panel.add(studentNameLabel);
panel.add(studentNameTextField);
panel.add(leaveApplicationLabel);
panel.add(leaveApplicationTextArea);
panel.add(submitButton);
panel.add(editButton);
add(panel);
submitButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String studentId = studentIdTextField.getText();
String studentName = studentNameTextField.getText();
String leaveApplication = leaveApplicationTextArea.getText();
// Save the leave application to the database
JOptionPane.showMessageDialog(StudentFrame.this, "Leave application submitted", "Success", JOptionPane.INFORMATION_MESSAGE);
}
});
editButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Enable editing of the leave application
leaveApplicationTextArea.setEditable(true);
}
});
// Set student information based on the logged-in student ID
studentIdTextField.setText("123456"); // Replace with actual logged-in student ID
studentIdTextField.setEditable(false);
studentNameTextField.setText("John Doe"); // Replace with actual student name
studentNameTextField.setEditable(false);
}
}
```
以上代码创建了一个学生界面,其中显示了学生的信息(学号和姓名),以及请假申请表单。学生可以提交新的请假申请或编辑已有申请。请假申请通过按钮和编辑按钮实现相应的功能。根据登录的学号自动填写学生信息。
请注意,以上示例代码只是一个框架,具体的数据库操作和功能实现需要根据你的需求进一步开发。你可以使用Java的数据库连接技术(如JDBC)来与数据库进行交互,执行查询、插入、更新和删除等操作。