我正在Java 6
(1.6.0_24)中开发应用程序,它使用透明JFrame
来获得消失的动画。这是我的代码:
public static void slowDisappearWindowAction(Window source, int milisSlow, int milisFast) throws InterruptedException{
float level = 1.0f;
//slow effect -> 50%
for(int i=0; i<8 ; i++){
level=level-0.05f;
AWTUtilities.setWindowOpacity(source,level);
Thread.sleep(milisSlow);
}
//fast effect -> 0%
for(int i=0; i<8 ; i++){
level=level-0.05f;
AWTUtilities.setWindowOpacity(source,level);
Thread.sleep(milisFast);
}
AWTUtilities.setWindowOpacity(source,0.1f);
}
Java 7
它在我的机器上运行良好,但是当我在另一台已安装的 PC 上测试它时,出现以下错误:
Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException:
The frame is decorated
at java.awt.Frame.setOpacity(Unknown Source)
at java.awt.Window$1.setOpacity(Unknown Source)
at com.sun.awt.AWTUtilities.setWindowOpacity(Unknown Source)
at pl.design.bead.pattern.model.window.WindowHelper.slowDisappearWindowAction(WindowHelper.java:21)
at pl.design.bead.pattern.forms.MainForm$ExitController.windowClosing(MainForm.java:123)
at java.awt.AWTEventMulticaster.windowClosing(Unknown Source)
at java.awt.Window.processWindowEvent(Unknown Source)
at javax.swing.JFrame.processWindowEvent(Unknown Source)
at java.awt.Window.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
我认为这是因为Java 7
我应该使用Window.setOpacity(...)
而不是AWTUtilities
方法。
可以在Java 6
应用程序中使用透明度,它将运行在Java 7
?