您的位置:首页 > 编程语言 > Java开发

《Java 编程技巧1001条》 第423条: 检测窗口何时已图标化(Iconified)

2017-12-26 08:36 357 查看


《Java 编程技巧1001条》423 Detecting When a Window Is Iconified
423 检测窗口何时已图标化(Iconified)
You have learned how to catch many events. Another pair of events that a Java application receives are WINDOW_ICONIFY and WINDOW_DEICONIFY. You should note that icon events are platform dependent because not all operating systems iconify applications. You may find it useful to handle icon events if you wish to disable a graphics intensive program from updating while it is iconified. There usually is no reason to update a window that is not visible. The following code demonstrates how to disable the paint method if an application is iconified:
你已知道了怎样去俘获许多种的事件. Java程序接受的另一对事件是WINDOW_ICONIFY(窗口图标化)和WINDOW_DEICONIFY(窗口去图标化). 你必须注意icon事件是和平台有关的,因为并不是所有的操作系统都把应用程序图标化. 你可发现, 如果你希望禁止一个已图标化的图形密集程序刷新, 利用icon事件是有用的. 通常没有理由要刷新一个不可见窗口. 以下的代码说明了一个应用程序已图标化时怎样禁止paint方法:
import java.awt.*;
  
class iconifyApplication extends Frame {
   boolean icon = false;
  
   public iconifyApplication(String label)
     {
       setTitle(label);
       resize(100,100);
     }
  
   public boolean handleEvent(Event evt)
     {
       System.out.println("here");
       if (evt.id == Event.WINDOW_DESTROY)
         System.exit(0); // quit application
       else if (evt.id == Event.WINDOW_ICONIFY)
         icon = true;
       else if (evt.id == Event.WINDOW_DEICONIFY)
         icon = false;
       return(super.handleEvent(evt)); // Dont handle other events
     }
    
   public void paint(Graphics g)
     {
       if (!icon) 
         System.out.println("update");      
       else
         System.out.println("don't update");
     }
    
   public static void main(String[] args)
     {
       iconifyApplication f = new iconifyApplication ("iconify");
       f.show();
     }
 }

1001 Java Programming Tips
Page 
PAGE
1652
 of 
numpages 
15

filename 
jt074_095.doc

第9-11部分 tips 334-423 全结束
 第12部分 抽象窗口化工具箱tips 424-590 已上载,见

第13部分 多媒体程序设计tips 591-625中,
有关声音播放的tips591-609 未上载,而。。。
有关图像播放的tips610-625已上载,见。。。

第14部分 图形 tips 626-661 已全上载。
所以,接下去要上载的就是多媒体程序设计中,未上载的部分,其
详细目录为:
。。。待录
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: