如何向java窗体中添加背景图片
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何向java窗体中添加背景图片相关的知识,希望对你有一定的参考价值。
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 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();
参考技术A JLabel label=new JLabel("添加你的图片")
用setOpaque(false);//设置控件透明
Delphi中子窗体如何继承父窗体
我做了一个图书馆管理系统,由于查询,删除,添加等数据库操作的代码都相似,我就建了一个父窗体,包含这些操作。我想建一个子窗体继承父窗体的这些操作,请问该如何实现?
参考技术A interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Form1加上Form1;
type
TForm2 = class(TForm1这里是Form1)
procedure FormCreate(Sender: TObject);
private
Private declarations
public
Public declarations
end;
var
Form2: TForm2;
implementation
$R *.dfm
procedure TForm2.FormCreate(Sender: TObject);
begin
Form2.ButtonGet.Caption := '';
end;
也可以把查询、添加、删除等数据库操作做成函数,传递不同的参数。
以上是关于如何向java窗体中添加背景图片的主要内容,如果未能解决你的问题,请参考以下文章