3、 编写一个模仿QQ界面。 提示: (1)要用new JLabel(new ImageIcon("img/yluqq.jpg"));来放置图片; (2)要用null布局,再用setBounds(组件左上角x坐标,组件左上角5坐标,组件宽度,组件高度)来放置组件;
时间: 2024-03-24 12:40:12 浏览: 30
以下是一个简单的模仿QQ界面的代码,其中包含了一个背景图片和若干个组件的设置,可以根据需要进行修改:
```java
import javax.swing.*;
import java.awt.*;
public class QQDemo extends JFrame {
public QQDemo() {
// 设置窗口标题
setTitle("QQ Demo");
// 设置窗口大小和位置
setSize(300, 400);
setLocation(200, 200);
// 设置窗口布局为null
setLayout(null);
// 添加背景图片
JLabel bgLabel = new JLabel(new ImageIcon("img/yluqq.jpg"));
bgLabel.setBounds(0, 0, 300, 400);
add(bgLabel);
// 添加文本框和标签
JTextField textField = new JTextField();
textField.setBounds(50, 50, 200, 30);
add(textField);
JLabel label = new JLabel("QQ号码/手机/邮箱");
label.setBounds(50, 85, 200, 20);
label.setForeground(Color.WHITE);
add(label);
// 添加按钮
JButton loginButton = new JButton("登录");
loginButton.setBounds(50, 120, 200, 30);
add(loginButton);
JButton registerButton = new JButton("注册账号");
registerButton.setBounds(50, 160, 200, 30);
add(registerButton);
JButton forgetButton = new JButton("忘记密码");
forgetButton.setBounds(50, 200, 200, 30);
add(forgetButton);
// 设置窗口可见性
setVisible(true);
}
public static void main(String[] args) {
new QQDemo();
}
}
```
注意:上述代码中的背景图片需要放置在项目根目录下的img文件夹中。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)