在java中给面板添加背景,JAVA在面板中增添背景图

当前位置:我的异常网» Eclipse » JAVA在面板中增添背景图

JAVA在面板中增添背景图

www.myexceptions.net  网友分享于:2013-11-11  浏览:275次

JAVA在面板中添加背景图

package SMT.view;

import java.awt.BorderLayout;

import java.awt.FlowLayout;

import java.awt.Graphics;

import java.sql.Statement;

import java.awt.Image;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.image.ImageObserver;

import java.awt.image.ImageProducer;

import java.sql.Connection;

import java.sql.DriverManager;

import java.text.SimpleDateFormat;

import java.util.Date;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JDesktopPane;

import javax.swing.JFileChooser;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JMenu;

import javax.swing.JMenuBar;

import javax.swing.JMenuItem;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JToolBar;

import SMT.model.YH;

import SMT.sql.Sqlconn;

public class MainFrame extends JFrame implements ActionListener {

private JDesktopPane desktopPane;

private JMenuBar menubar;

private JButton btnUser,btnCom,btnPur,btnSale,btnAdd,btnMoney,btnBef,btnExit;

private JPanel imagePanel;

private ImageIcon background;

public MainFrame(){

desktopPane = new JDesktopPane();

menubar = new JMenuBar();

btnUser = new JButton("用户管理");

btnCom = new JButton("仓库管理");

btnPur = new JButton("采购管理");

btnSale = new JButton("销售管理");

btnAdd = new JButton("销售统计");

btnMoney = new JButton("金额统计");

btnBef = new JButton("备份管理");

btnExit = new JButton(" 注 销 ");

menubar.add(btnUser);

menubar.add(btnCom);

menubar.add(btnPur);

menubar.add(btnSale);

menubar.add(btnAdd);

menubar.add(btnMoney);

menubar.add(btnBef);

menubar.add(btnExit);

btnUser.addActionListener(this);

btnCom.addActionListener(this);

btnPur.addActionListener(this);

btnSale.addActionListener(this);

btnAdd.addActionListener(this);

btnMoney.addActionListener(this);

btnBef.addActionListener(this);

btnExit.addActionListener(this);

this.getContentPane().add(desktopPane,BorderLayout.CENTER);

///this.getContentPane().add(toolbar,BorderLayout.NORTH);

this.setJMenuBar(menubar);

this.setSize(686, 500);

this.setBounds(200, 100, 686, 500);

this.setResizable(false);

this.setVisible(true);

this.setTitle("081超市管理系统");

this.setDefaultCloseOperation(EXIT_ON_CLOSE);

}

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

new MainFrame();

}

@Override

public void actionPerformed(ActionEvent e) {

if(e.getSource().equals(btnUser)){

if(YHManage.count==0){

YHManage yhManage=new YHManage();

yhManage.showData();

desktopPane.add(yhManage);

}

else

{JOptionPane.showMessageDialog(null,"该窗口已经打开");}

}

if(e.getSource().equals(btnExit)){

int i=JOptionPane.showConfirmDialog(null, "是否确定退出系统", "提示:", 0,3);

if(i==0){

this.dispose();

}

}

if(e.getSource().equals(btnBef)){

Beifen beifen = new Beifen();

desktopPane.add(beifen);

beifen.toFront();

}

}

}

在这里面添加个背景图片.....急需代码

------解决方案--------------------

建个label标签,用label.setIcon();方法

例子:public static ImageIcon bombIcon = new ImageIcon("images/Bomb.gif");

文章评论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值