packagexiangmu;importjava.awt.*;importjava.awt.event.*;importjava.io.File;importjava.io.IOException;importjavax.imageio.ImageIO;importjavax.swing.*;publicclassUserLoginex...
package xiangmu;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;
public class UserLogin extends JFrame{
JButton button1,button2;
JTextField textUser;
JPasswordField textPasswd;
JPanel panel;
JLabel label1,label2;
public static void main(String args[]){
UserLogin bb=new UserLogin();
}
public UserLogin(){
super();
this.setBounds(500,200,360,360);
ImageIcon bg = new ImageIcon("wenjian/login.gif");
JLabel label = new JLabel(bg);
label.setBounds(0,0,bg.getIconWidth(),bg.getIconHeight());
this.getLayeredPane().add(label,newInteger(Integer.MIN_VALUE));
JPanel jp=(JPanel)getContentPane();
jp.setOpaque(false);
this.setUndecorated(true);
JPanel panel=new JPanel();
panel.setOpaque(false);//把JPanel设置为透明
panel.setLayout(null);
button1=new JButton("登 录");
button2=new JButton("退 出");
textUser=new JTextField();
textPasswd=new JPasswordField();
label1=new JLabel("请输入用户名:");
label2=new JLabel("请 输 入 密 码:");
button1.setBounds(80, 310, 70, 30);
button2.setBounds(220, 310, 70, 30);
textUser.setBounds(210, 200, 100, 30);
textPasswd.setBounds(210, 250, 100, 30);
label1.setBounds(60, 200, 100, 30);
label2.setBounds(60, 250, 100, 30);
this.add(panel);
panel.add(button1);
panel.add(button2);
panel.add(textUser);
panel.add(textPasswd);
panel.add(label1);
panel.add(label2);
this.setVisible(true);
this.validate();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private Object newInteger(int minValue) {
return null;
}
}
背景图能显示,就遮盖了label
展开