java登陆界面如何插入背景图片
/****功能:客户端登陆界面**/packagecom.xx.client.view;importjavafx.scene.image.Image;importjava...
/**
*
* 功能:客户端登陆界面
*
*/
package com.xx.client.view;
import javafx.scene.image.Image;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class XxClientLogin extends JFrame {
//定义北部需要的组件
JLabel jbl1;
//定义中部需要的组件
//.中部有三个JPanel,有一个叫选项卡窗口管理
JTabbedPane jtp;
JPanel jp2,jp3,jp4;
JLabel jp2_jbl1,jp2_jbl2,jp2_jbl3,jp2_jbl4;
JButton jp2_jb1;
JTextField jp2_jtf;
JPasswordField jp2_jpf;
JCheckBox jp2_jcb1,jp2_jcb2;
//定义南部需要的组件
JPanel jp1;
JButton jp1_jb1,jp1_jb2,jp1_jb3;
public static void main(String[] args) {
// TODO Auto-generated method stub
XxClientLogin XxClientLogin=new XxClientLogin();
}
public XxClientLogin()
{
//处理北部
jbl1=new JLabel(new ImageIcon("ffff/10.png"));
//处理中部
jp2=new JPanel(new GridLayout(3,3));
jp2_jbl1=new JLabel("Xx号码",JLabel.CENTER);
jp2_jbl2=new JLabel("Xx密码",JLabel.CENTER);
jp2_jbl3=new JLabel("忘记密码",JLabel.CENTER);
jp2_jbl3.setForeground(Color.blue);
jp2_jbl4=new JLabel("申请密码保护",JLabel.CENTER);
jp2_jb1=new JButton(new ImageIcon("ffff/12"));
jp2_jtf=new JTextField();
jp2_jpf=new JPasswordField();
jp2_jcb1=new JCheckBox("隐身登陆");
jp2_jcb2=new JCheckBox("记住密码");
//把控件按照顺序加入到jp2
jp2.add(jp2_jbl1);
jp2.add(jp2_jtf);
jp2.add(jp2_jb1);
jp2.add(jp2_jbl2);
jp2.add(jp2_jpf);
jp2.add(jp2_jbl3);
jp2.add(jp2_jcb1);
jp2.add(jp2_jcb2);
jp2.add(jp2_jbl4);
jtp=new JTabbedPane();
jtp.add("Xx号码",jp2);
jp3= new JPanel();
jtp.add("手机号码",jp3);
jp4=new JPanel();
jtp.add("电子邮件",jp4);
//处理南部
jp1=new JPanel();
jp1_jb1=new JButton(new ImageIcon("ffff/13.png"));
jp1_jb2=new JButton(new ImageIcon("ffff/11.png"));
jp1_jb3=new JButton(new ImageIcon("ffff/14.png"));
//把三个按钮放入到jp1
jp1.add(jp1_jb1);
jp1.add(jp1_jb2);
jp1.add(jp1_jb3);
this.add(jbl1,"North");
this.add(jtp,"Center");
//..把jp1放在南部
this.add(jp1,"South");
this.setSize(350, 500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}
我在自学,这是问我根据视频打的,但是应该怎么插入一个背景图片啊?我怎么一插入就将他们覆盖了? 展开
*
* 功能:客户端登陆界面
*
*/
package com.xx.client.view;
import javafx.scene.image.Image;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class XxClientLogin extends JFrame {
//定义北部需要的组件
JLabel jbl1;
//定义中部需要的组件
//.中部有三个JPanel,有一个叫选项卡窗口管理
JTabbedPane jtp;
JPanel jp2,jp3,jp4;
JLabel jp2_jbl1,jp2_jbl2,jp2_jbl3,jp2_jbl4;
JButton jp2_jb1;
JTextField jp2_jtf;
JPasswordField jp2_jpf;
JCheckBox jp2_jcb1,jp2_jcb2;
//定义南部需要的组件
JPanel jp1;
JButton jp1_jb1,jp1_jb2,jp1_jb3;
public static void main(String[] args) {
// TODO Auto-generated method stub
XxClientLogin XxClientLogin=new XxClientLogin();
}
public XxClientLogin()
{
//处理北部
jbl1=new JLabel(new ImageIcon("ffff/10.png"));
//处理中部
jp2=new JPanel(new GridLayout(3,3));
jp2_jbl1=new JLabel("Xx号码",JLabel.CENTER);
jp2_jbl2=new JLabel("Xx密码",JLabel.CENTER);
jp2_jbl3=new JLabel("忘记密码",JLabel.CENTER);
jp2_jbl3.setForeground(Color.blue);
jp2_jbl4=new JLabel("申请密码保护",JLabel.CENTER);
jp2_jb1=new JButton(new ImageIcon("ffff/12"));
jp2_jtf=new JTextField();
jp2_jpf=new JPasswordField();
jp2_jcb1=new JCheckBox("隐身登陆");
jp2_jcb2=new JCheckBox("记住密码");
//把控件按照顺序加入到jp2
jp2.add(jp2_jbl1);
jp2.add(jp2_jtf);
jp2.add(jp2_jb1);
jp2.add(jp2_jbl2);
jp2.add(jp2_jpf);
jp2.add(jp2_jbl3);
jp2.add(jp2_jcb1);
jp2.add(jp2_jcb2);
jp2.add(jp2_jbl4);
jtp=new JTabbedPane();
jtp.add("Xx号码",jp2);
jp3= new JPanel();
jtp.add("手机号码",jp3);
jp4=new JPanel();
jtp.add("电子邮件",jp4);
//处理南部
jp1=new JPanel();
jp1_jb1=new JButton(new ImageIcon("ffff/13.png"));
jp1_jb2=new JButton(new ImageIcon("ffff/11.png"));
jp1_jb3=new JButton(new ImageIcon("ffff/14.png"));
//把三个按钮放入到jp1
jp1.add(jp1_jb1);
jp1.add(jp1_jb2);
jp1.add(jp1_jb3);
this.add(jbl1,"North");
this.add(jtp,"Center");
//..把jp1放在南部
this.add(jp1,"South");
this.setSize(350, 500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}
我在自学,这是问我根据视频打的,但是应该怎么插入一个背景图片啊?我怎么一插入就将他们覆盖了? 展开
1个回答
展开全部
直接上代码了,这是我以前写的
package am_2;
import java.awt.*;
import javax.swing.*;
public class JLayeredPane_1 extends JFrame {
public JLayeredPane_1() {
this.setSize(300, 400);
JLayeredPane layeredPane = this.getLayeredPane();
layeredPane.add(new BackgroundPanel(), new Integer(0)); // the same to
// layeredPane.add(panelBg);
layeredPane.add(new PanelContent(), new Integer(1));
this.setLocationRelativeTo(null);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public class BackgroundPanel extends JPanel {
public BackgroundPanel() {
this.add(new JLabel(getIcon()));
this.setBounds(0, 0, 300, 400);
}
public ImageIcon getIcon() {
final Image imageBg = Toolkit.getDefaultToolkit().getImage(
this.getClass().getResource("/img/0.jpg"));
ImageIcon imageIcon = new ImageIcon(imageBg);
return imageIcon;
}
@Override
public void paint(Graphics g) {
Image imageBg = Toolkit.getDefaultToolkit().getImage(
this.getClass().getResource("/img/0.jpg"));
g.drawImage(imageBg, 0, 0, 300, 400, null);
}
}
public class PanelContent extends JPanel {
public PanelContent() {
JButton button = new JButton("测试按钮 1");
JButton button2 = new JButton("测试按钮 2");
JButton button3 = new JButton("测试按钮 3");
this.setBounds(100, 100, 100, 100);
this.setOpaque(false); // 设置为透明
this.add(button);
this.add(button2);
this.add(button3);
}
}
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JLayeredPane_1 frame = new JLayeredPane_1();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询