用JAVA设计一个QQ登录界面
时间: 2023-12-18 09:03:36 浏览: 29
好的,我可以为您提供一个简单的QQ登录界面的JAVA代码示例:
```
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class QQLogin extends JFrame implements ActionListener {
private JLabel accountLabel, passwordLabel;
private JTextField accountField;
private JPasswordField passwordField;
private JButton loginButton, cancelButton;
public QQLogin() {
super("QQ Login");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 150);
setLocationRelativeTo(null);
accountLabel = new JLabel("Account:");
passwordLabel = new JLabel("Password:");
accountField = new JTextField(15);
passwordField = new JPasswordField(15);
loginButton = new JButton("Login");
cancelButton = new JButton("Cancel");
JPanel panel = new JPanel(new GridLayout(3, 2));
panel.add(accountLabel);
panel.add(accountField);
panel.add(passwordLabel);
panel.add(passwordField);
panel.add(loginButton);
panel.add(cancelButton);
add(panel);
loginButton.addActionListener(this);
cancelButton.addActionListener(this);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == loginButton) {
String account = accountField.getText();
String password = new String(passwordField.getPassword());
if (account.equals("") || password.equals("")) {
JOptionPane.showMessageDialog(this, "Please enter account and password", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
// 进行登录操作
JOptionPane.showMessageDialog(this, "Login succeed!", "Message", JOptionPane.INFORMATION_MESSAGE);
dispose();
} else if (e.getSource() == cancelButton) {
dispose();
}
}
public static void main(String[] args) {
new QQLogin();
}
}
```
这段代码使用了JFrame、JLabel、JTextField、JPasswordField、JButton和JOptionPane等Swing组件,实现了一个简单的QQ登录界面。您可以根据需要进行修改和完善。