JAVA界面加了背景图片但是显示不出来,代码在下面
publicclassJMextendsJFrame{JLabelyh=newJLabel("用户名");JLabelmm=newJLabel("密码");JTextFi...
public class JM extends JFrame {
JLabel yh = new JLabel("用户名");
JLabel mm = new JLabel("密码");
JTextField yh1 = new JTextField(15);
JPasswordField mm1 =new JPasswordField(15);
JRadioButton jmm = new JRadioButton("记住密码");
JButton dl =new JButton("登陆");
JButton qx = new JButton("取消");
JButton zc = new JButton("注册");
public JM (){
this.setTitle("登陆界面");
this.setSize(300, 270);
JPanel j = (JPanel)this.getContentPane();
JLabel bg = new JLabel(new ImageIcon("006Cx3u5ly1fbz7xwdx1sj30i40dydg4.jpg"));
j.add(bg);
bg.setBounds(0, 0, 300, 270);
Container c = this.getContentPane();
c.setLayout(null);
yh.setBounds(20, 0, 100, 100);
yh1.setBounds(70,37, 200, 27);
mm.setBounds(20, 30, 100, 100);
mm1.setBounds(70, 67, 200,27);
jmm.setBounds(70, 95, 80, 30);
dl.setBounds(70, 135, 60, 35);
qx.setBounds(135, 135, 60, 35);
zc.setBounds(200, 135, 60, 35);
c.add(yh);
c.add(yh1);
c.add(mm);
c.add(mm1);
c.add(jmm);
c.add(dl);
c.add(qx);
c.add(zc);
setOpaque(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}
private void setOpaque(boolean b) {
// TODO Auto-generated method stub
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new JM();
}
} 展开
JLabel yh = new JLabel("用户名");
JLabel mm = new JLabel("密码");
JTextField yh1 = new JTextField(15);
JPasswordField mm1 =new JPasswordField(15);
JRadioButton jmm = new JRadioButton("记住密码");
JButton dl =new JButton("登陆");
JButton qx = new JButton("取消");
JButton zc = new JButton("注册");
public JM (){
this.setTitle("登陆界面");
this.setSize(300, 270);
JPanel j = (JPanel)this.getContentPane();
JLabel bg = new JLabel(new ImageIcon("006Cx3u5ly1fbz7xwdx1sj30i40dydg4.jpg"));
j.add(bg);
bg.setBounds(0, 0, 300, 270);
Container c = this.getContentPane();
c.setLayout(null);
yh.setBounds(20, 0, 100, 100);
yh1.setBounds(70,37, 200, 27);
mm.setBounds(20, 30, 100, 100);
mm1.setBounds(70, 67, 200,27);
jmm.setBounds(70, 95, 80, 30);
dl.setBounds(70, 135, 60, 35);
qx.setBounds(135, 135, 60, 35);
zc.setBounds(200, 135, 60, 35);
c.add(yh);
c.add(yh1);
c.add(mm);
c.add(mm1);
c.add(jmm);
c.add(dl);
c.add(qx);
c.add(zc);
setOpaque(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}
private void setOpaque(boolean b) {
// TODO Auto-generated method stub
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new JM();
}
} 展开
展开全部
你的背景图片的Java程序,我帮你改完了,你看看吧(只是改了JM();构造函数中的内容,去掉了setOpaque函数,其它的地方没动)
import javax.swing.*;
public class JM extends JFrame {
JLabel yh = new JLabel("用户名");
JLabel mm = new JLabel("密码");
JTextField yh1 = new JTextField(15);
JPasswordField mm1 =new JPasswordField(15);
JRadioButton jmm = new JRadioButton("记住密码");
JButton dl =new JButton("登陆");
JButton qx = new JButton("取消");
JButton zc = new JButton("注册");
public JM (){
this.setTitle("登陆界面");
this.setSize(300, 270);
JPanel c = (JPanel)this.getContentPane();
c.setLayout(null);
//Container c = this.getContentPane();
yh.setBounds(20, 0, 100, 100);
yh1.setBounds(70,37, 200, 27);
mm.setBounds(20, 30, 100, 100);
mm1.setBounds(70, 67, 200,27);
jmm.setBounds(70, 95, 80, 30);
dl.setBounds(70, 135, 60, 35);
qx.setBounds(135, 135, 60, 35);
zc.setBounds(200, 135, 60, 35);
c.add(yh);
c.add(yh1);
c.add(mm);
c.add(mm1);
c.add(jmm);
c.add(dl);
c.add(qx);
c.add(zc);
JLabel bg = new JLabel(new ImageIcon("006Cx3u5ly1fbz7xwdx1sj30i40dydg4.jpg"));
bg.setBounds(0, 0, 300, 270);
c.add(bg);
c.setOpaque(false);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}
//private void setOpaque(boolean b) {
// TODO Auto-generated method stub
//}
public static void main(String[] args) {
// TODO Auto-generated method stub
new JM();
}
}
运行结果
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询