Java SE中运行程序,弹出一个框,不影响后台运行程序,程序运行完,框自动关闭!

需求:Java SE中运行程序,弹出一个框,用来告诉用户,系统已经运行了,关不关闭该框,都不影响后台程序的运行,该框可以随时关闭,但是不影响程序的运行,当程序运行完,框会自动关闭!

效果如图:

package com.accord.util;

import java.awt.FlowLayout;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * @author
 * 2018年9月25日
 * 窗口的打开和关闭
 */
public class TransferingUtil {
	
	public static void main(String[] args) throws Exception {
		TransferingUtil.open();
		Thread.sleep(1000);
		TransferingUtil.close();
	}
    
	static JFrame frame;
	public static void open() {
		frame = new JFrame();
		frame.setTitle("温馨提示:系统导数运行中。。。");
		frame.setBounds(400,300,600,400);
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		//frame.getRootPane().setWindowDecorationStyle(JRootPane.COLOR_CHOOSER_DIALOG);
		frame.setLocationRelativeTo(null);
		frame.setVisible(true);
		
		String imgPath = System.getProperty("user.dir") + "/config/1.png";
		ImageIcon img = new ImageIcon(imgPath);
		JLabel bg = new JLabel(img);
		frame.getLayeredPane().add(bg,new Integer(Integer.MIN_VALUE));
		bg.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
		JPanel jp= (JPanel)frame.getContentPane();//强制类型转换
		jp.setOpaque(false);
		jp.setLayout(new FlowLayout());
		jp.add(bg);
	}
	
	
	public static void close() {
		frame.setVisible(false);
		frame.dispose();
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值