⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jsplashwindow.java

📁 连连看的源码
💻 JAVA
字号:
package nicholas.swing;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * <p>Title: JSplashWindow</p>
 * <p>Description: start up window</p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: ColinSoft</p>
 * @author Nicholas Lin
 * @version beta
 */
 
public class JSplashWindow extends JWindow {
	
	private static JSplashWindow csw;
	private Image image;
	private String user;
	private String lab;
	private int x1 = 155;
	private int y1 = 220;
	private int x2 = 250;
	private int y2 = 235;
	private DisposeAdapter da;
	
	/**
	 *constructor
	 */	
    private JSplashWindow(String u, ImageIcon icon) {

		setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
		image = icon.getImage();
		user = u;
		setAlwaysOnTop(true);

		setSize(icon.getIconWidth(),icon.getIconHeight());
		Dimension screen = getToolkit().getScreenSize();
		setLocation((screen.width-getSize().width)/2, (screen.height-getSize().height)/2);
		this.setVisible(true);
    }
    
    /**
     *set close on click
     *use as about dialog
     */
    public void setCloseOnClick(boolean b) {
    	if(b) {
    		if(da==null)
    			da = new DisposeAdapter();
    		addMouseListener(da);
    	} else if(da!=null) {
   			this.removeMouseListener(da);
    	}
    }
    
    /**
     *set the place where user name will be show
     */
    public void setUserLocation(int x,int y) {
    	x1 = x;
    	y1 = y;
    }
    
    /**
     *set the place where status will be show
     */
    public void setStatusLocation(int x,int y) {
    	x2 = x;
    	y2 = y;
    }
	
	/**
	 *paint
	 */
	public void paint(Graphics g) {
		g.drawImage(image,0,0,this);
		g.drawString(user,x1,y1);
		if(lab!=null)
			g.drawString(lab,x2,y2);
	}
    
    /**
     *set the status text
     */
    public void setText(String lab) {
    	this.lab = lab;
    	repaint();
    }
    
    /**
     *inner class
     *to close the JWindow on click
     */
    private class DisposeAdapter extends MouseAdapter {
    	
    	public void mouseClicked(MouseEvent me) {
    		dispose();
    	}
    }
    
    /**
     *static method to set the instance
     *only once is premitted
     */
    public static synchronized boolean setInstance(String user,ImageIcon icon) {
    	if(csw==null) {
    		csw = new JSplashWindow(user,icon);
    		return true;
    	}
    	return false;
    }
    
    /**
     *get the instance of JSplashWindow
     *@return JSplashWindow
     */
    public static synchronized JSplashWindow getInstance() {
        return csw;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -