java图形用户登录界面微信登录界面
时间: 2023-09-13 17:03:29 浏览: 42
以下是使用Java Swing实现的简单的图形用户登录界面和微信登录界面的示例代码:
用户登录界面:
```java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class LoginFrame extends JFrame implements ActionListener {
private JTextField usernameField;
private JPasswordField passwordField;
public LoginFrame() {
setTitle("用户登录");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 200);
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
JPanel inputPanel = new JPanel();
inputPanel.setLayout(new GridLayout(2, 2));
inputPanel.add(new JLabel("用户名:"));
usernameField = new JTextField();
inputPanel.add(usernameField);
inputPanel.add(new JLabel("密码:"));
passwordField = new JPasswordField();
inputPanel.add(passwordField);
contentPane.add(inputPanel, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout());
JButton loginButton = new JButton("登录");
loginButton.addActionListener(this);
buttonPanel.add(loginButton);
JButton cancelButton = new JButton("取消");
cancelButton.addActionListener(this);
buttonPanel.add(cancelButton);
contentPane.add(buttonPanel, BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent event) {
String command = event.getActionCommand();
if (command.equals("登录")) {
String username = usernameField.getText();
String password = new String(passwordField.getPassword());
if (username.equals("admin") && password.equals("admin")) {
JOptionPane.showMessageDialog(this, "登录成功!");
} else {
JOptionPane.showMessageDialog(this, "用户名或密码错误!");
}
} else if (command.equals("取消")) {
usernameField.setText("");
passwordField.setText("");
}
}
public static void main(String[] args) {
LoginFrame frame = new LoginFrame();
frame.setVisible(true);
}
}
```
微信登录界面:
```java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class WeChatLoginFrame extends JFrame implements ActionListener {
private JTextField accountField;
private JPasswordField passwordField;
public WeChatLoginFrame() {
setTitle("微信登录");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 200);
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
JPanel inputPanel = new JPanel();
inputPanel.setLayout(new GridLayout(2, 2));
inputPanel.add(new JLabel("账号:"));
accountField = new JTextField();
inputPanel.add(accountField);
inputPanel.add(new JLabel("密码:"));
passwordField = new JPasswordField();
inputPanel.add(passwordField);
contentPane.add(inputPanel, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout());
JButton loginButton = new JButton("登录");
loginButton.addActionListener(this);
buttonPanel.add(loginButton);
JButton cancelButton = new JButton("取消");
cancelButton.addActionListener(this);
buttonPanel.add(cancelButton);
contentPane.add(buttonPanel, BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent event) {
String command = event.getActionCommand();
if (command.equals("登录")) {
String account = accountField.getText();
String password = new String(passwordField.getPassword());
if (account.equals("admin") && password.equals("admin")) {
JOptionPane.showMessageDialog(this, "登录成功!");
} else {
JOptionPane.showMessageDialog(this, "账号或密码错误!");
}
} else if (command.equals("取消")) {
accountField.setText("");
passwordField.setText("");
}
}
public static void main(String[] args) {
WeChatLoginFrame frame = new WeChatLoginFrame();
frame.setVisible(true);
}
}
```