如何向java窗体中添加背景图片
importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclasszbextendsJFram...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class zb extends JFrame implements ActionListener {
private static final Color red = null;
private JPanel jp = new JPanel();
JPanel topjp = new JPanel();
JPanel leftjp = new JPanel();
JPanel rightjp = new JPanel();
JButton cmanage = new JButton("客户资料管理");
JButton pmanage= new JButton("售票管理");
JButton wmanage = new JButton("票务管理");
JButton smanage = new JButton("购送票管理");
JButton dmanage = new JButton("定单信息管理");
JLabel index = new JLabel("航空订票系统");
Font jbfont = new Font("宋体",Font.BOLD,20);
Font indexfont = new Font("华文隶书",Font.BOLD+Font.ITALIC,50);
JLabel gnumber = new JLabel("管理员帐号");
JTextField textgnumber = new JTextField();
JLabel mname = new JLabel("密码");
JTextField textmname= new JTextField();
JButton select = new JButton("查询");
private JButton[] jb={cmanage,dmanage,pmanage,smanage,wmanage};
JTable table = new JTable();
public Image image;
public zb() {
jp.setLayout(null);
leftjp.setLayout(null);
rightjp.setLayout(null);
jp.add(topjp);
jp.add(leftjp);
jp.add(rightjp);
leftjp.setBounds(0,50,230,700);
topjp.add(index);
topjp.setBounds(0,0,1000,70);
topjp.setBackground(Color.darkGray);
leftjp.setBackground(Color.lightGray);
rightjp.setBounds(200,50,800,700);
rightjp.add(gnumber);
rightjp.add(textgnumber);
rightjp.add(mname);
rightjp.add(textmname);
rightjp.add(select);
for(int i=0;i<5;i++){
jb[i].setBounds(20,50+i*80,180,60);
leftjp.add(jb[i]);
jb[i].setFont(jbfont);
jb[i].addActionListener(this);}
index.setFont(indexfont);
index.setForeground(Color.white);
gnumber.setBounds(70,30,100,30);
textgnumber.setBounds(150,30,100,30);
mname.setBounds(280,30,100,30);
textmname.setBounds(330,30,100,30);
select.setBounds(490,30,100,30);
this.add(jp);
this.setTitle("航空订票系统");
this.setBounds(0,0,1000,700);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == jb[0]) {
} }
public static void main(String []args){
new zb();}} 展开
import java.awt.event.*;
import javax.swing.*;
public class zb extends JFrame implements ActionListener {
private static final Color red = null;
private JPanel jp = new JPanel();
JPanel topjp = new JPanel();
JPanel leftjp = new JPanel();
JPanel rightjp = new JPanel();
JButton cmanage = new JButton("客户资料管理");
JButton pmanage= new JButton("售票管理");
JButton wmanage = new JButton("票务管理");
JButton smanage = new JButton("购送票管理");
JButton dmanage = new JButton("定单信息管理");
JLabel index = new JLabel("航空订票系统");
Font jbfont = new Font("宋体",Font.BOLD,20);
Font indexfont = new Font("华文隶书",Font.BOLD+Font.ITALIC,50);
JLabel gnumber = new JLabel("管理员帐号");
JTextField textgnumber = new JTextField();
JLabel mname = new JLabel("密码");
JTextField textmname= new JTextField();
JButton select = new JButton("查询");
private JButton[] jb={cmanage,dmanage,pmanage,smanage,wmanage};
JTable table = new JTable();
public Image image;
public zb() {
jp.setLayout(null);
leftjp.setLayout(null);
rightjp.setLayout(null);
jp.add(topjp);
jp.add(leftjp);
jp.add(rightjp);
leftjp.setBounds(0,50,230,700);
topjp.add(index);
topjp.setBounds(0,0,1000,70);
topjp.setBackground(Color.darkGray);
leftjp.setBackground(Color.lightGray);
rightjp.setBounds(200,50,800,700);
rightjp.add(gnumber);
rightjp.add(textgnumber);
rightjp.add(mname);
rightjp.add(textmname);
rightjp.add(select);
for(int i=0;i<5;i++){
jb[i].setBounds(20,50+i*80,180,60);
leftjp.add(jb[i]);
jb[i].setFont(jbfont);
jb[i].addActionListener(this);}
index.setFont(indexfont);
index.setForeground(Color.white);
gnumber.setBounds(70,30,100,30);
textgnumber.setBounds(150,30,100,30);
mname.setBounds(280,30,100,30);
textmname.setBounds(330,30,100,30);
select.setBounds(490,30,100,30);
this.add(jp);
this.setTitle("航空订票系统");
this.setBounds(0,0,1000,700);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == jb[0]) {
} }
public static void main(String []args){
new zb();}} 展开
展开全部
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ks extends JFrame implements ActionListener {
private static final Color red = null;
private JPanel jp = new JPanel();
JPanel topjp = new JPanel();
JPanel leftjp = new JPanel();
JPanel rightjp = new JPanel();
JButton cmanage = new JButton("客户资料管理");
JButton pmanage = new JButton("售票管理");
JButton wmanage = new JButton("票务管理");
JButton smanage = new JButton("购送票管理");
JButton dmanage = new JButton("定单信息管理");
JLabel index = new JLabel("航空订票系统");
Font jbfont = new Font("宋体", Font.BOLD, 20);
Font indexfont = new Font("华文隶书", Font.BOLD + Font.ITALIC, 50);
JLabel gnumber = new JLabel("管理员帐号");
JTextField textgnumber = new JTextField();
JLabel mname = new JLabel("密码");
JTextField textmname = new JTextField();
JButton select = new JButton("查询");
private JButton[] jb = { cmanage, dmanage, pmanage, smanage, wmanage };
JTable table = new JTable();
public Image image;
public ks() {
jp.setLayout(null);
leftjp.setLayout(null);
rightjp.setLayout(null);
jp.add(topjp);
jp.add(leftjp);
jp.add(rightjp);
leftjp.setBounds(0, 50, 230, 700);
topjp.add(index);
topjp.setBounds(0, 0, 1000, 70);
topjp.setBackground(Color.darkGray);
leftjp.setBackground(Color.lightGray);
rightjp.setBounds(200, 50, 800, 700);
rightjp.add(gnumber);
rightjp.add(textgnumber);
rightjp.add(mname);
rightjp.add(textmname);
rightjp.add(select);
for (int i = 0; i < 5; i++) {
jb[i].setBounds(20, 50 + i * 80, 180, 60);
leftjp.add(jb[i]);
jb[i].setFont(jbfont);
jb[i].addActionListener(this);
}
index.setFont(indexfont);
index.setForeground(Color.white);
gnumber.setBounds(70, 30, 100, 30);
textgnumber.setBounds(150, 30, 100, 30);
mname.setBounds(280, 30, 100, 30);
textmname.setBounds(330, 30, 100, 30);
select.setBounds(490, 30, 100, 30);
JLabel jl = new JLabel(new ImageIcon("C:\\Users\\LR\\Desktop\\1.png"));
jl.setBounds(0, 0, 1000, 700);
this.getLayeredPane().add(jl);// 设置背景为图片
this.add(jp);
this.setTitle("航空订票系统");
this.setBounds(0, 0, 1000, 700);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jb[0]) {
}
}
public static void main(String[] args) {
new ks();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询