一个java写的QQ登录的界面,请教背景图片怎么设置
importjava.awt.Color;
importjava.awt.Font;
importjavax.swing.ImageIcon;
importjavax.swing.JButton;
importjavax.swing.JCheckBox;
importjavax.swing.JComboBox;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JMenu;
importjavax.swing.JMenuBar;
importjavax.swing.JMenuItem;
importjavax.swing.JPanel;
importjavax.swing.JTextField;
publicclassQQextendsJFrame{
/**
*@paramargs
*/
publicQQ(){
super("QQ");
this.setSize(390,300);
this.setLayout(null);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanelp=(JPanel)this.getContentPane();
//账号输入框
JTextFieldtf1=newJTextField();
tf1.setBounds(80,100,200,30);
p.add(tf1);
//注册账号标签
JLabellb1=newJLabel("注册账号");
lb1.setBounds(300,100,70,27);
p.add(lb1);
lb1.setFont(newFont("仿宋",Font.BOLD,14));
lb1.setForeground(Color.BLUE);
JTextFieldtf2=newJTextField();
tf2.setBounds(80,140,200,27);
p.add(tf2);
//找回密码标签
JLabellb2=newJLabel("找回密码");
lb2.setBounds(300,140,70,27);
p.add(lb2);
lb2.setFont(newFont("仿宋",Font.BOLD,14));
lb2.setForeground(Color.BLUE);
//记住密码,自动登录多选框
JCheckBoxck1=newJCheckBox("记住密码");
JCheckBoxck2=newJCheckBox("自动登录");
ck1.setBounds(80,180,80,30);
ck2.setBounds(170,180,80,30);
p.add(ck1);
p.add(ck2);
//登录按钮
JButtonbtn=newJButton("登录");
btn.setBounds(100,210,140,30);
p.add(btn);
btn.setFont(newFont("仿宋",Font.BOLD,16));
//多账号登录
JButtonbtn1=newJButton("多账号");
btn1.setBounds(10,210,80,30);
p.add(btn1);
btn1.setFont(newFont("仿宋",Font.BOLD,14));
//加头像
ImageIconimage=newImageIcon("英雄头像\\Ahri.png");
JLabellb3=newJLabel(image);
p.add(lb3);
lb3.setBounds(5,100,70,70);
//下拉菜单,表状态
JComboBoxcbox=newJComboBox();
//ImageIconcm=newImageIcon("a.gif");
cbox.addItem("离开");
cbox.addItem("隐身");
cbox.addItem("上线");
cbox.addItem("忙碌");
cbox.setBounds(20,180,60,25);
p.add(cbox);
JMenuBarm=newJMenuBar();
m.setDefaultLocale(null);
m.setLayout(null);
m.setLocation(0,50);
m.setBounds(0,100,10,10);
JMenumm=newJMenu("图");
JMenuItemmi1=newJMenuItem("在线");
JMenuItemmi2=newJMenuItem("影身");
JMenuItemmi3=newJMenuItem("忙碌");
JMenuItemmi4=newJMenuItem("离开");
this.setJMenuBar(m);
m.add(mm);
mm.add(mi1);
mm.add(mi2);
mm.add(mi3);
mm.add(mi4);
this.setResizable(false);//不允许放大,改变窗口大小等
this.setVisible(true);
}
publicstaticvoidmain(String[]args){
QQq=newQQ();
}
}
这是我写的QQ登录的界面,但是不知道怎么设置背景图片,请各位大神指教
GUI
分享到:
------解决方案--------------------
importjava.awt.Color;
importjava.awt.Font;
importjava.awt.Graphics;
importjava.awt.Image;
importjava.io.File;
importjava.io.IOException;
importjavax.imageio.ImageIO;
importjavax.swing.ImageIcon;
importjavax.swing.JButton;
importjavax.swing.JCheckBox;
importjavax.swing.JComboBox;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JMenu;
importjavax.swing.JMenuBar;
importjavax.swing.JMenuItem;
importjavax.swing.JPanel;
importjavax.swing.JTextField;
publicclassQQextendsJFrame{
/**
*@paramargs
*/
publicQQ(){
super("QQ");
this.setSize(390,300);
this.setLayout(null);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//JPanelp=(JPanel)this.getContentPane();
JPanelp=newImagePane();
this.setContentPane(p);
//账号输入框
JTextFieldtf1=newJTextField();
tf1.setBounds(80,100,200,30);
p.add(tf1);
//注册账号标签
JLabellb1=newJLabel("注册账号");
lb1.setBounds(300,100,70,27);
p.add(lb1);