Java的秘密:使用全屏幕模式

转载 2004年07月10日 17:23:00

发信人: ttlink (Anakin Skywalker), 信区: Java                                                                          
标  题: Java的秘密:使用全屏幕模式 (zz)                                                                                
发信站: 日月光华 (2003年04月16日09:08:24 星期三), 站内信件                                                             

http://www.csdn.net/develop/article/17/17856.shtm                                                                      
turbochen(原作)                                                                                                      
什么时候会用到全屏幕模式?                                                                                             
    也许用到的机会很少,但JDK还是为我们提供了这个的功能。像许多软件中的                                                
打印预览功能,还有某些文本编辑器中为了获得更大的编辑画面,也用到了全屏幕                                               
模式,如果你有兴趣写一个像ACDSee这样的软件,使用全屏幕模式可以让用户看到                                               
更大的图片画面。                                                                                                       

如何使用全屏幕模式?                                                                                                   
    关键是java.awt.*里面的两个与显示设备有关的类:GraphicsEnvironment和                                                
GraphicsDevice。                                                                                                       
                                                                                                                       
    GraphicsEnvironment为Java应用程序提供了特定平台的 GraphicsDevice                                                   
对象和 Font 对象集合。这些GraphicsDevice可以是各种本机和远端机器的资源,                                               
如屏幕、打印机或者是Image Buffer,甚至是Graphics2D绘图方法的目标对象。                                                  

    而GraphicsDevice就是指特定的图形环境了,如屏幕和打印设备等。这样,我                                               
们就可以用GraphicsDevice来操纵屏幕了。GraphicsDevice提供的                                                             
setFullScreenWindow()方法就是设置全屏幕用的。                                                                          
                                                                                                                       
    由于GraphicsEnvironment的构造器是受保护的(protected),我们不能直接构                                               
造一个                                                                                                                 
GraphicsEnvironment对象来获得GraphicsDevice对象。幸好它提供了                                                          
getLocalGraphicsEnvironment()方法,用来获得一个GraphicsEnvironment实例:                                               
                                                                                                                       
        GraphicsEnvironment ge = GraphicsEnvironment.                                                                  
getLocalGraphicsEnvironment();                                                                                         
    有了GraphicsEnvironment可以调用getDefaultScreenDevice方法获得当前的                                                
屏幕设备了:                                                                                                           
        GraphicsDevice gd = ge.getDefaultScreenDevice();                                                               
                                                                                                                       
自己动手体验一下                                                                                                       
    有了上面的简介,写一个实例来体验一下吧:                                                                           
                                                                                                                       
import java.awt.*;                                                                                                     
import java.awt.event.*;                                                                                               
import javax.swing.*;                                                                                                  
                                                                                                                       
public class FullScreenTest                                                                                            
{                                                                                                                      
    public static void main(String[] args)                                                                             
    {                                                                                                                  
                                                                                                                       
           GraphicsEnvironment ge =                                                                                    
                GraphicsEnvironment.getLocalGraphicsEnvironment();                                                     
           GraphicsDevice gd = ge.getDefaultScreenDevice();                                                            
           FullScreenWindow myWindow = new FullScreenWindow();                                                         
           if ( gd.isFullScreenSupported() )                                                                           
                gd.setFullScreenWindow(myWindow);                                                                      
           else                                                                                                        
                System.out.println("Unsupported full screen.");                                                        
                                                                                                                       
    }                                                                                                                  
}                                                                                                                      

class FullScreenWindow extends JWindow                                                                                 
{                                                                                                                      
    public FullScreenWindow()                                                                                          
    {                                                                                                                  
        this.addMouseListener(new MouseAdapter()                                                                       
        {                                                                                                              
            public void mousePressed(MouseEvent evt)                                                                   
            {                                                                                                          
                quit();                                                                                                
            }                                                                                                          
            });                                                                                                        
    }                                                                                                                  
                                                                                                                       
    public void quit()                                                                                                 
    {                                                                                                                  
        this.dispose();                                                                                                
    }                                                                                                                  
                                                                                                                       
    public void paint(Graphics g)                                                                                      
    {                                                                                                                  
        g.setFont(new Font("Arial",Font.BOLD,30));                                                                     
        g.setColor(Color.RED);                                                                                         
        g.drawString("这是全屏幕模式",100,100);                                                                        
                                                                                                                       
    }                                                                                                                  
                                                                                                                       
}                                                                                                                      
                                                                                                                       
                                                                                                                       
                                                                                                                       
                                                                                                                       
你也可以进入Turbo Chen的Java技术专栏, 看更多的Java的秘密系列文章                                                       
                                                                                                                       
                                                                                                                       
--                                                                                                                     
                                                                                                                       
※ 来源:·日月光华 bbs.fudan.edu.cn·[FROM:the city of Vampire]                                                        

Java的秘密:使用全屏幕模式

google_ad_client = "pub-8800625213955058";/* 336x280, 创建于 07-11-21 */google_ad_slot = "0989131976";...
  • java169
  • java169
  • 2008年05月24日 00:34
  • 151

Java的秘密:使用全屏幕模式

什么时候会用到全屏幕模式? 也许用到的机会很少,但JDK还是为我们提供了这个的功能。像许多软件中的打印预览功能,还有某些文本编辑器中为了获得更大的编辑画面,也用到了全屏幕模式,如果你有兴趣写一个像AC...
  • chensheng913
  • chensheng913
  • 2004年11月01日 22:19
  • 6425

java-Java的秘密:使用全屏幕模式

什么时候会用到全屏幕模式? 也许用到的机会很少,但JDK还是为我们提供了这个的功能。像许多软件中的打印预览功能,还有某些文本编辑器中为了获得更大的编辑画面,也用到了全屏幕模式,如果你有兴趣写一个像AC...
  • fgwf1
  • fgwf1
  • 2004年11月04日 21:30
  • 735

Java的秘密武器:使用全屏幕模式

  也许用到的机会很少,但JDK还是为我们提供了这个的功能。像许多软件中的打印预览功能,还有某些文本编辑器中为了获得更大的编辑画面,也用到了全屏幕模式,如果你有兴趣写一个像ACDSee这样的软件,使用...
  • ark1111
  • ark1111
  • 2004年11月02日 15:08
  • 734

模式的秘密——单例模式

模式的秘密——单例模式             单例模式是指有些对象只需要一个,比如:古代的皇帝,单例的作用是保证整个应用程序中某一个实例有且只有一个。单例模式分为两种类型:饿汉模式和懒汉模式。 ...
  • zhimingshangyan
  • zhimingshangyan
  • 2016年03月01日 23:34
  • 841

全屏幕模式

也许用到的机会很少,但JDK还是为我们提供了这个的功能。像许多软件中的打印预览功能,还有某些文本编辑器中为了获得更大的编辑画面,也用到了全屏幕模式,如果你有兴趣写一个像ACDSee这样的软件,使用全屏...
  • a_nuo
  • a_nuo
  • 2008年05月13日 11:16
  • 334

菜鸟学设计模式(一)——小单例有大秘密

单例模式大家并不陌生,也都知道它分为什么懒汉式、饿汉式之类的。但是你对单例模式的理解足够透彻吗?今天我带大家一起来看看我眼中的单例,可能会跟你的认识有所不同。 下面是一个简单的小实例: //简单懒汉...
  • liushuijinger
  • liushuijinger
  • 2013年06月17日 08:58
  • 20298

模式的秘密——责任链模式

模式的秘密——责任链模式 一、什么是责任链模式 将接收者对象连成一条链条,并在该链上传递请求,直到有一个接收者对象处理它。通过让更多对象有机会处理请求,避免了请求发送者和接收者之间的耦合。 二、...
  • zhimingshangyan
  • zhimingshangyan
  • 2016年09月04日 16:09
  • 515

luogu2666 Bessie的秘密牧场

题目背景 背景就是描述,描述就是背景。 题目描述 Farmmer John最近收割了几乎无限多块牧草,将它们堆放在空地上。这些牧草都是正方形的,而且都有非负整数长度的边长(当然有0)。一天它的奶...
  • xh_0319
  • xh_0319
  • 2017年09月28日 18:58
  • 69

模式的秘密——工厂模式

模式的秘密——工厂模式 一、   工厂模式的概念 工厂模式:为创建对象提供过度接口,以便将创建对象的具体过程屏蔽隔离起来,达到提高灵活性的目的。   二、   工厂模式的应用场景 工厂方法 ...
  • zhimingshangyan
  • zhimingshangyan
  • 2016年08月29日 08:26
  • 493
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章: Java的秘密:使用全屏幕模式
举报原因:
原因补充:

(最多只允许输入30个字)