在eclipse中(jdk1.6.*)版本中出现编译不通过而报错,报错是因为这个包里面的方法不属于jdk正式版本,也就是不能保证下个版本还存在,所以编译器会拒绝,你可以在eclipse中如下设置: 选择Window->Preferences->Java->Compiler->Errors/Warnings;然后选择Deprecated and restricted API,将 Deprecated API从ERROR改为Warning即可!

 package Com.SwingTest;

 import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Window;
import javax.swing.JButton;
import javax.swing.JWindow; import com.sun.awt.AWTUtilities; public class SwingText_08 { private int _height = ; // 气泡提示高
private int _step = ; // 设定循环的步长
private int _stepTime = ; // 每步时间
private int _displayTime = ; // 显示时间
private Font _font; // 字体 /**
* 构造函数,初始化默认气泡提示设置
*
*/
public SwingText_08()
{
_font = new Font("微软雅黑", , );// 设定字体
try {
JWindow.class.getMethod("setAlwaysOnTop",
new Class[] { Boolean.class });
} catch (Exception e) {
}
} /**
* 重构JWindow用于显示单一气泡提示框
*
*/
class ToolTipSingle extends Window
{
private static final long serialVersionUID = 1L;
private JButton _message = new JButton(){
/**
*
*/
private static final long serialVersionUID = 1L; @Override
public void repaint()
{
}
}; @SuppressWarnings("deprecation")
public ToolTipSingle(String msg) {
super(null); int cntText=msg.length();
int with = cntText*+;
int height = _height; Rectangle screenRect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
int screenHeight = (int) screenRect.height;
int screenWidth = (int) screenRect.width; int posx = screenWidth/-with/;
int posy = screenHeight/-height/; setBounds(posx, posy, with, height);
_message.setFont(getMessageFont());
_message.setText(msg); _message.setFocusPainted(false);
//_message.setEnabled(false);
add(_message, BorderLayout.CENTER); setAlwaysOnTop(true);
setLocationRelativeTo(null); show(true);
} /**
* 动画开始
*
*/
public void animate() {
new Animation(this).start();
}
} /**
* 此类处则动画处理
*
*/
class Animation extends Thread
{ ToolTipSingle _single; public Animation(ToolTipSingle single) {
this._single = single;
} /**
* 开始动画处理
*/
@SuppressWarnings("deprecation")
public void run() {
try {
float value = 0.0f;
while((value+0.02)<1.0f)
{
value+=0.02f;
com.sun.awt.AWTUtilities.setWindowOpacity(_single, value);
Thread.sleep();
} while(_displayTime>)
{
Thread.sleep();
_displayTime = _displayTime-;
} value=;
while((value-0.02)>0f)
{
value-=0.02f;
com.sun.awt.AWTUtilities.setWindowOpacity(_single, value);
Thread.sleep();
} } catch (Exception e) {
throw new RuntimeException(e);
} _single.show(false);
}
} /**
* 设定显示信息
*
* @param icon
* @param msg
*/
public void show(String msg) {
new ToolTipSingle(msg).animate();
} /**
* 获得当前消息字体
*
* @return
*/
public Font getMessageFont() {
return _font;
} /**
* 设置当前消息字体
*
* @param font
*/
public void setMessageFont(Font font) {
_font = font;
} /**
* 获得显示时间
*
* @return
*/
public int getDisplayTime() {
return _displayTime;
} /**
* 设置显示时间
*
* @param displayTime
*/
public void setDisplayTime(int displayTime) {
this._displayTime = displayTime;
} /**
* 获得循环步长
*
* @return
*/
public int getStep() {
return _step;
} /**
* 设定循环步长
*
* @param _step
*/
public void setStep(int _step) {
this._step = _step;
} public int getStepTime() {
return _stepTime;
} public void setStepTime(int _stepTime) {
this._stepTime = _stepTime;
} public static void main(String[] argv)
{
new SwingText_08().show("全部任务已经载入完成!");
}
}

com.sun.awt.AWTUtilities.setWindowOpacity相关说明的更多相关文章

  1. Java:import com.sun.awt.AWTUtilities;报错

    参考网址:http://stackoverflow.com/questions/860187/access-restriction-on-class-due-to-restriction-on-req ...

  2. linux下验证码无法显示:Could not initialize class sun.awt.X1 解决方案

    转自:http://my.oschina.net/xiangtao/blog/28441 网站验证码突然无法显示,并报如下错误. Caused by: java.lang.NoClassDefFoun ...

  3. weblogic .NoClassDefFoundError: Could not initialize class sun.awt.X11Graphi

    这个是常见问题,可以通过增加Weblogic的启动参数来解决: -Djava.awt.headless=true 你可以修改 startWebLogic.sh 文件. export JAVA_OPTI ...

  4. weblogic环境,应用上传图片报Could not initialize class sun.awt.X11.XToolkit

    问题描写叙述 遇到的问题是在weblogic环境,应用在上传图片的时候报Could not initialize class sun.awt.X11.XToolkit 错误. 详细错误例如以下 17: ...

  5. exception java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment

      exception java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironmen ...

  6. Linux下java验证码不显示:Could not initialize class sun.awt.X11FontManager

    一.问题 javaweb项目,登录的时候有个图片验证码的功能.在Windows本地测试能够正常显示,部署到Linux上就不行了.报错如下: org.springframework.web.util.N ...

  7. java:提示Could not initialize class sun.awt.X11GraphicsEnvironment

    前几天发现tomcat提示 Could not initialize class sun.awt.X11GraphicsEnvironment  问题.以为不验证,就没太关注,今天发现,有同事提示了个 ...

  8. 验证码无法显示,服务器端出现异常:Could not initialize class sun.awt.X11GraphicsEnvironment

    异常信息: Caused by: java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvir ...

  9. Linux下验证码无法显示,Could not initialize class sun.awt.X1 解决方案

    环境:Oracle Linux 6.4,JDK1.6,Weblogic11g 在通过java.awt生成图片验证码时,提示: Could not initialize class sun.awt.X1 ...

随机推荐

  1. 后缀crt证书转换

    转换地址:https://www.chinassl.net/ssltools/convert-ssl.html 转换成功后点下载即可

  2. DevExpress导出Excel样式设置

    /// <summary> /// 导出到Excel /// </summary> /// <param name="gridControl"> ...

  3. haproxy有关session的问题

    在实验的时候遇到一个问题就是当我登录网站的时候,然后我再刷新一下,用户的状态就退出了 我现在的框架是这样的,前面有一台haproxy作为反向代理,后面有两台服务器跑的是java应用.后面两台服务器做的 ...

  4. angularJS核心原理

    一.angularJS优点和缺点 优点 1.1免去重复劳动-获取元素.给元素加事件.创建元素 1.2接管UI:angularJS根据数据创建UI元素,免去手工创建UI元素. 1.3自动同步:根据数据个 ...

  5. Executor , ExecutorService 和 Executors

    三者的主要区别和关系如下: Executor 和 ExecutorService 这两个接口主要的区别是:ExecutorService 接口继承了 Executor 接口,是 Executor 的子 ...

  6. java jvm perf

    http://www.oracle.com/technetwork/java/performance-138178.html http://www.oracle.com/technetwork/jav ...

  7. linux命令(30):tail

    linux ---tail命令 linux中tail命令---用于查看文件内容 最基本的是cat.more和less. 1. 如果你只想看文件的前5行,可以使用head命令,如: head -5 /e ...

  8. 請問 localtime() 為什麼不會造成 memory leak?

    http://www.programmer-club.com.tw/ShowSameTitleN/vc/22380.html ************************************* ...

  9. 推荐2个干净的PE

    1,微PE(之前著名的通用PE.绝对PE都出自该作者) 官网:http://www.wepe.com.cn/ 2,金狐维护盘 官网:http://www.jinhu.me/

  10. tomcat 8 加 struts2的 java.lang.NoSuchFieldException: resourceEntries

    google发现已经有人把这个bug提交给了apache,issue地址,具体原因就是 Tomcat8 introduce super class WebappClassLoaderBase and ...