请在下面的JAVA代码中加入背景图片就OK!不能遮盖文本框和按钮!
publicclassRegisterDemoextendsJInternalFrameimplementsActionListener{JPanelp;JLabella...
public class RegisterDemo extends JInternalFrame implements ActionListener{
JPanel p;
JLabel label2,label3,label4,label5,label6,label7,label8,label9;
JTextField text1,text2,text3,text4,text5,text6,text7,text8;
JButton button1,button2;
Connection conn;
PreparedStatement ps;
ResultSet rs;
Statement s;
public RegisterDemo(){
super("注册编辑");
p = new JPanel();
this.getContentPane().add(p);
p.setLayout(null);
setBounds(300,50,350,550);
Font font = new Font("楷体",Font.BOLD,25);
label9 = new JLabel("读者ID:");
label2 = new JLabel("姓名:");
label3 = new JLabel("年龄:");
label4 = new JLabel("读者信息");
label4.setFont(font);
label5 = new JLabel("系别:");
label6 = new JLabel("性别:");
label7 = new JLabel("地址:");
label8 = new JLabel("电话:");
text1 = new JTextField(25);
text2 = new JTextField(25);
text3 = new JTextField(25);
text4 = new JTextField(25);
text5 = new JTextField(25);
text6 = new JTextField(25);
text7 = new JTextField(25);
text8 = new JTextField(25);
button1 = new JButton("确认");
button2 = new JButton("重置");
label9.setBounds(50,100,120,50);
label2.setBounds(50,150,60,50);
label3.setBounds(50,200,60,50);
label4.setBounds(125,0,120,100);
label4.setForeground(Color.blue);
label5.setBounds(50,250,60,50);
label6.setBounds(50,300,60,50);
label7.setBounds(50,350,60,50);
label8.setBounds(50,400,60,50);
text1.setBounds(110,110,200,30);
text2.setBounds(110,160,200,30);
text3.setBounds(110,210,200,30);
text4.setBounds(110,260,200,30);
text5.setBounds(110,310,200,30);
text6.setBounds(110,360,200,30);
text7.setBounds(110,410,200,30);
button1.setBounds(110,460,60,30);
button2.setBounds(200,460,60,30);
p.add(label2);
p.add(label3);
p.add(label4);
p.add(label5);
p.add(label6);
p.add(label7);
p.add(label8);
p.add(label9);
p.add(text1);
p.add(text2);
p.add(text3);
p.add(text4);
p.add(text5);
p.add(text6);
p.add(text7);
p.add(button1);
p.add(button2);
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
}
}
);
button2.addActionListener(this);
setMaximizable(true);//设子窗体有最大化按钮
setClosable(true);//设子窗体有关闭按钮
setVisible(true);
}
public void actionPerformed(ActionEvent e){
}
public static void main(String[] args){
new RegisterDemo();
}
} 展开
JPanel p;
JLabel label2,label3,label4,label5,label6,label7,label8,label9;
JTextField text1,text2,text3,text4,text5,text6,text7,text8;
JButton button1,button2;
Connection conn;
PreparedStatement ps;
ResultSet rs;
Statement s;
public RegisterDemo(){
super("注册编辑");
p = new JPanel();
this.getContentPane().add(p);
p.setLayout(null);
setBounds(300,50,350,550);
Font font = new Font("楷体",Font.BOLD,25);
label9 = new JLabel("读者ID:");
label2 = new JLabel("姓名:");
label3 = new JLabel("年龄:");
label4 = new JLabel("读者信息");
label4.setFont(font);
label5 = new JLabel("系别:");
label6 = new JLabel("性别:");
label7 = new JLabel("地址:");
label8 = new JLabel("电话:");
text1 = new JTextField(25);
text2 = new JTextField(25);
text3 = new JTextField(25);
text4 = new JTextField(25);
text5 = new JTextField(25);
text6 = new JTextField(25);
text7 = new JTextField(25);
text8 = new JTextField(25);
button1 = new JButton("确认");
button2 = new JButton("重置");
label9.setBounds(50,100,120,50);
label2.setBounds(50,150,60,50);
label3.setBounds(50,200,60,50);
label4.setBounds(125,0,120,100);
label4.setForeground(Color.blue);
label5.setBounds(50,250,60,50);
label6.setBounds(50,300,60,50);
label7.setBounds(50,350,60,50);
label8.setBounds(50,400,60,50);
text1.setBounds(110,110,200,30);
text2.setBounds(110,160,200,30);
text3.setBounds(110,210,200,30);
text4.setBounds(110,260,200,30);
text5.setBounds(110,310,200,30);
text6.setBounds(110,360,200,30);
text7.setBounds(110,410,200,30);
button1.setBounds(110,460,60,30);
button2.setBounds(200,460,60,30);
p.add(label2);
p.add(label3);
p.add(label4);
p.add(label5);
p.add(label6);
p.add(label7);
p.add(label8);
p.add(label9);
p.add(text1);
p.add(text2);
p.add(text3);
p.add(text4);
p.add(text5);
p.add(text6);
p.add(text7);
p.add(button1);
p.add(button2);
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
}
}
);
button2.addActionListener(this);
setMaximizable(true);//设子窗体有最大化按钮
setClosable(true);//设子窗体有关闭按钮
setVisible(true);
}
public void actionPerformed(ActionEvent e){
}
public static void main(String[] args){
new RegisterDemo();
}
} 展开
1个回答
展开全部
jp.setOpaque(false); //把JPanel设置为透明 这样就不会遮住后面的背景 这样你就能在JPanel随意加组件了
ImageIcon img = new ImageIcon("c://Sunset.jpg"); //添加图片
JLabel background = new JLabel(img);this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
ImageIcon img = new ImageIcon("c://Sunset.jpg"); //添加图片
JLabel background = new JLabel(img);this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
追问
这段代码要放那里?
追答
最先加到jp上去啊
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |