在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. Java 异常处理的 9 个最佳实践

    在 Java 中,异常处理是个很麻烦的事情.初学者觉得它很难理解,甚至是经验丰富的开发者也要花费很长时间决定异常是要处理掉和抛出. 所以很多开发团队约定一些原则处理异常.如果你是一个团队的新成员,你可 ...

  2. 在向"带有自增字段的数据库表"中插入数据时,自定义"该自增字段"的数据

    在设计数据库表的时候,经常会使用自增主键或其他自增字段.比如: DB_UserGroups表中GroupID为该表主键,并为自增字段. 但在将某字段设置自增后,想在插入数据时,人为指定自增字段的数据内 ...

  3. 【Android】3.0 第3章 百度地图及其应用--预备知识

    分类:C#.Android.VS2015.百度地图应用: 创建日期:2016-02-04 一.概述 这一章先来点有意思的百度地图应用示例,然后再分章详细介绍用C#开发Android App的各种基本技 ...

  4. 使用vim-latex排版

    前几天在某个群上看到了一篇简历,内容不重要,一看排版很漂亮的说.一问才知道是用latex排版工具排版的.一想到我都大三下学期的,也快大四了,是不是要准备一份简历.于是就想使用latex这个排版工具来排 ...

  5. python学习之base64模块

    常见方法: base64.encodebytes() 参数: 接收一个字节对象. 返回值: 返回base64编码的数据(以'\n'结尾的数据). base64.decodebytes() 参数: 接收 ...

  6. 在Spark中通过Scala + Mongodb实现连接池

    How to implement connection pool in spark https://github.com/YulinGUO/BigDataTips/blob/master/spark/ ...

  7. hive12启动报错org.apache.thrift.server.TThreadPoolServer.<init>(Lorg/apache/thrift/server/TThreadPoolServer$Args;)

    执行如下命令启动hive服务:./bin/hive --service hiveserver,报如下错误: Starting Hive Thrift ServerException in thread ...

  8. hdu 1007最近点对问题

    先说下题意,很简单,给n个点的坐标,求距离最近的一对点之间距离的一半.第一行是一个数n表示有n个点,接下来n行是n个点的x坐标和y坐标,实数. 这个题目其实就是求最近点对的距离.主要思想就是分治.先把 ...

  9. hdu2199(高精度二分模版)

    Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,can you find its solution between 0 and ...

  10. JAVA-JSP声明语句

    相关资料: <21天学通Java Web开发> 结果总结: 1.<%! %>声明的变量为全局变量. 实例代码: <html> <head> <ti ...