写一个java的图形界面理发店登陆系统
时间: 2023-08-16 07:10:16 浏览: 94
基于java+小程序的理发店预约系统-java-.zip
好的,下面是一个简单的Java图形界面理发店登陆系统的示例代码,其中使用了JFrame、JPanel、JLabel、JTextField、JPasswordField和JButton等组件:
```java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class BarberShopLoginSystem extends JFrame implements ActionListener {
private JPanel panel;
private JLabel userLabel, passwordLabel, titleLabel;
private JTextField userTextField;
private JPasswordField passwordField;
private JButton loginButton, resetButton;
public BarberShopLoginSystem() {
setTitle("理发店登陆系统");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
panel = new JPanel();
panel.setLayout(null);
titleLabel = new JLabel("理发店登陆系统");
titleLabel.setBounds(120, 30, 200, 20);
panel.add(titleLabel);
userLabel = new JLabel("用户名:");
userLabel.setBounds(50, 80, 80, 20);
panel.add(userLabel);
userTextField = new JTextField();
userTextField.setBounds(130, 80, 150, 20);
panel.add(userTextField);
passwordLabel = new JLabel("密 码:");
passwordLabel.setBounds(50, 120, 80, 20);
panel.add(passwordLabel);
passwordField = new JPasswordField();
passwordField.setBounds(130, 120, 150, 20);
panel.add(passwordField);
loginButton = new JButton("登 陆");
loginButton.setBounds(80, 180, 80, 25);
loginButton.addActionListener(this);
panel.add(loginButton);
resetButton = new JButton("重 置");
resetButton.setBounds(200, 180, 80, 25);
resetButton.addActionListener(this);
panel.add(resetButton);
add(panel);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == loginButton) {
String user = userTextField.getText();
String password = new String(passwordField.getPassword());
if (user.equals("admin") && password.equals("admin123")) {
JOptionPane.showMessageDialog(this, "登陆成功!");
} else {
JOptionPane.showMessageDialog(this, "用户名或密码错误!");
}
} else if (ae.getSource() == resetButton) {
userTextField.setText("");
passwordField.setText("");
}
}
public static void main(String[] args) {
new BarberShopLoginSystem();
}
}
```
这个登陆系统中,用户需要输入用户名和密码才能登陆系统。如果用户名和密码匹配,系统会弹出一个提示框提示用户登陆成功;否则,弹出提示框提示用户名或密码错误。用户可以点击“重置”按钮清空用户名和密码输入框。
阅读全文