java实现qq登录的界面用gui
时间: 2023-07-16 11:13:07 浏览: 52
可以使用Java Swing来实现QQ登录界面的GUI,以下是一个简单的示例代码:
```java
import javax.swing.*;
public class QQLoginGUI extends JFrame {
private JLabel accountLabel;
private JTextField accountField;
private JLabel passwordLabel;
private JPasswordField passwordField;
private JButton loginButton;
public QQLoginGUI() {
setTitle("QQ登录");
setSize(300, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
JPanel panel = new JPanel();
panel.setLayout(null);
accountLabel = new JLabel("账号:");
accountLabel.setBounds(50, 30, 50, 20);
panel.add(accountLabel);
accountField = new JTextField();
accountField.setBounds(100, 30, 120, 20);
panel.add(accountField);
passwordLabel = new JLabel("密码:");
passwordLabel.setBounds(50, 60, 50, 20);
panel.add(passwordLabel);
passwordField = new JPasswordField();
passwordField.setBounds(100, 60, 120, 20);
panel.add(passwordField);
loginButton = new JButton("登录");
loginButton.setBounds(120, 100, 60, 30);
panel.add(loginButton);
add(panel);
setVisible(true);
}
public static void main(String[] args) {
new QQLoginGUI();
}
}
```
这个示例代码中,首先创建了一个继承自JFrame的QQLoginGUI类,在构造函数中设置了窗口的基本属性。然后创建一个JPanel面板,通过设置其布局为null来使用绝对布局。在面板中添加账号、密码的标签和文本框,以及登录按钮。最后将面板添加到窗口中,并设置窗口可见。