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

📄 fullscreenframe.java

📁 打印管理程序,测试完全通过.windows开发环境.
💻 JAVA
字号:
package jp.co.ntl.swing.ext;

import java.awt.GraphicsDevice;
import java.awt.DisplayMode;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;

import jp.co.ntl.ext.GlobalContext;
import jp.co.ntl.preference.PreferenceInfo;

public abstract class FullScreenFrame extends JFrame {
	private static final int	bufferSize	 = 2;
	
    private GraphicsDevice		device;
    private BufferStrategy		strategy;		//僆僼僗僋儕乕儞僀儊乕僕
    private Graphics			gbb;			//僶僢僋僶僢僼傽傊偺昤夋梡
    private DisplayMode		currentMode;	//屻偱尦偵栠偡
    

    private Timer				timer;
    private PreferenceInfo		prefInfo;
///    private boolean			exitThread = false;
///    private RepaintThread		repaintThread = null;
    
    public FullScreenFrame(GraphicsDevice device, DisplayMode[] defaultMode) {
        super(device.getDefaultConfiguration());
        this.device = device;
        currentMode = device.getDisplayMode();
      
		prefInfo = new PreferenceInfo();
		try {
			prefInfo.readXml();
		} catch (ParserConfigurationException e) {
			JOptionPane.showMessageDialog(null, e.toString());
			return;
		} catch (SAXException e) {
			JOptionPane.showMessageDialog(null, e.toString());
			return;
		} catch (FileNotFoundException e) {
			JOptionPane.showMessageDialog(null, e.toString());
			return;
		} catch (IOException e) {
			JOptionPane.showMessageDialog(null, e.toString());
			return;
		}
        
        initFullScreen(defaultMode);
    
        if (isFullScreenSupported() && prefInfo.getClientKind() != PreferenceInfo.CLIENT_MAC) {
        	timer = new Timer();
        	timer.schedule(new TimerTask() {
        		public void run() {
        			repaintFullScreen();
        		}
        	}, 1000);
/*        	repaintThread = new RepaintThread();
        	timer = new Timer();
        	timer.schedule(new TimerTask() {
        		public void run() {
        			repaintThread.start();
        		}
        	}, 2000);*/
        }
    }
    
/*    private class RepaintThread extends Thread {
    	public void run() {
    		while (!exitThread) {
    			repaintFullScreen();
    			try {
    				Thread.sleep(500);
    			} catch (InterruptedException e) {
    				
    			}
    		}
    	}
    }*/
    
    public abstract void paintFullScreen(Graphics g);
    
    public void repaintFullScreen() {
   		if (!isFullScreenSupported() || prefInfo.getClientKind() == PreferenceInfo.CLIENT_MAC) {
   			Graphics	g = getGraphics();
   			if (g != null) {
   				this.paintAll(g);
   			}
   		} else {
   			for (int i = 0; i < bufferSize; i++) {
   				if (!strategy.contentsLost()) {
   					gbb = strategy.getDrawGraphics();
   					paintFullScreen(gbb);
   					strategy.show();
   					gbb.dispose();
    			}
    		}
    	}
    }
    public void closeFullScreen() {
    	if (isFullScreenSupported()) {
    		changeDisplayMode(new DisplayMode[] { currentMode });
   			device.setFullScreenWindow(null);
    	}
    	if (timer != null) {
    		timer.cancel();
    	}
/*    	if (repaintThread != null) {
    		exitThread = true;
    		try {
    			repaintThread.join();
    		} catch (InterruptedException e) {
    		}
    	}*/
        setVisible(false);
    }
    
    public boolean isFullScreenSupported() {
    	if (prefInfo.isDebug() || !device.isFullScreenSupported()) {
    		return false;
    	}
    	
    	return true;
    }
    
    /**
    * 僼儖僗僋儕乕儞偺弶婜壔
    */
    private void initFullScreen(DisplayMode[] defaultMode) {
        setUndecorated(true);  //僼儗乕儉偺榞傪昞帵偟側偄 ver1.4
        if (isFullScreenSupported()) {
        	if (prefInfo.getClientKind() != PreferenceInfo.CLIENT_MAC) {
///        		setIgnoreRepaint(true); //OS偺嵞昤夋梫媮傪柍帇  ver1.4
        	}
       		device.setFullScreenWindow(this); //僼儖僗僋儕乕儞偵偡傞 ver1.4
        	changeDisplayMode(defaultMode);
        	if (prefInfo.getClientKind() != PreferenceInfo.CLIENT_MAC) {
        		createBufferStrategy(bufferSize); //僟僽儖僶僢僼傽儕儞僌
        		strategy = getBufferStrategy();
        	}
        }
        
        requestFocus();
    }
    /**
    * 揔愗側僨傿僗僾儗僀儌乕僪偵偡傞
    */
    private void changeDisplayMode(DisplayMode[] defaultMode){
        //曄峏偵懳墳偟偰偄傞偲偒
        if (device.isDisplayChangeSupported()) {
            DisplayMode[] modes = device.getDisplayModes();
            for (int i = 0; i < defaultMode.length; i++) {
            	for (int j = 0; j < modes.length; j++) {
            		if (equalsDisplayMode(defaultMode[i], modes[j])) {
            			device.setDisplayMode(modes[j]);
            			return;
            		}
            	}
            }
        }
    }
    /**
    * 僨傿僗僾儗僀儌乕僪偺斾妑
    */
    private boolean equalsDisplayMode(DisplayMode mode1,DisplayMode mode2){
        return ( (mode1.getWidth() == mode2.getWidth()) 
            && (mode1.getHeight() == mode2.getHeight()) 
            && (mode1.getBitDepth() == mode2.getBitDepth()));
    }
}

⌨️ 快捷键说明

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