java模拟qq登录界面源代码
时间: 2023-07-07 12:36:23 浏览: 61
以下是Java模拟QQ登录界面的源代码:
```java
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class LoginFrame extends JFrame implements ActionListener {
private JPanel panel;
private JLabel userLabel, passwordLabel;
private JTextField userText;
private JPasswordField passwordText;
private JButton loginButton, registerButton;
public LoginFrame() {
initUI();
setVisible(true);
}
private void initUI() {
setTitle("QQ登录");
setSize(300, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel = new JPanel();
panel.setLayout(new GridLayout(3, 2));
userLabel = new JLabel("账号:");
passwordLabel = new JLabel("密码:");
userText = new JTextField();
passwordText = new JPasswordField();
loginButton = new JButton("登录");
registerButton = new JButton("注册");
loginButton.addActionListener(this);
registerButton.addActionListener(this);
panel.add(userLabel);
panel.add(userText);
panel.add(passwordLabel);
panel.add(passwordText);
panel.add(loginButton);
panel.add(registerButton);
add(panel);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == loginButton) {
String username = userText.getText();
String password = new String(passwordText.getPassword());
// 进行登录验证
if (username.equals("admin") && password.equals("admin")) {
JOptionPane.showMessageDialog(this, "登录成功!");
} else {
JOptionPane.showMessageDialog(this, "登录失败!");
}
} else if (e.getSource() == registerButton) {
// 跳转到注册页面
JOptionPane.showMessageDialog(this, "跳转到注册页面!");
}
}
public static void main(String[] args) {
new LoginFrame();
}
}
```
此代码实现了一个简单的QQ登录界面,包括账号和密码输入框、登录和注册按钮。当用户点击登录按钮时,会进行账号密码验证;当用户点击注册按钮时,会弹出提示框。你可以在这个基础上进行二次开发,实现更多功能。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)