Swing实现右下角消息框
package com.ui; import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JWindow; /**
*
* @author BLingSoft
*
* 右下角弹出式提示框 1.自动上升 2.停留一段时间,本例子中5秒 3.自动下降直至消失
*
* 4.线程控制窗口的出现和消失,同时添加鼠标事件控制,可以提前使提示框消失 5.鼠标事件结合自己的需求实现,此处只是实现一个点击事件
*
* @Time 2010-01-29
* @JDK VERSION 6.0
* @Copy Right By BLingSoft
*/
public class RightCornerPopMessage extends JWindow implements Runnable,
MouseListener { private static final long serialVersionUID = -3564453685861233338L;
private Integer screenWidth; // 屏幕宽度
private Integer screenHeight; // 屏幕高度
private Integer windowWidth = 200; // 设置提示窗口宽度
private Integer windowHeight = 100; // 设置提示窗口高度
private Integer bottmToolKitHeight; // 底部任务栏高度,如果没有任务栏则为零
private Integer stayTime = 5000; // 提示框停留时间 private Integer x; // 窗口起始X坐标
private Integer y; // 窗口起始Y坐标 private String title = "温馨提示";
private String message = "一个小小的提示消息例子!"; private JPanel mainPanel; // 主面板
private JLabel titleLabel; // 标题栏标签
private JPanel titlePanel; // 标题栏面板
private JLabel messageLabel; // 内容标签
private JPanel messagePanel; // 内容面板 public RightCornerPopMessage() {
this.init();
Thread thread = new Thread(this);
thread.start();
} private void init() {
bottmToolKitHeight = Toolkit.getDefaultToolkit().getScreenInsets(
this.getGraphicsConfiguration()).bottom;
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
screenWidth = dimension.width;
screenHeight = dimension.height; x = screenWidth - windowWidth;
y = screenHeight;
this.setLocation(x, y - bottmToolKitHeight - windowHeight);
mainPanel = new JPanel(new BorderLayout()); titleLabel = new JLabel(title);
titleLabel.setForeground(Color.WHITE);
titlePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
titlePanel.setBackground(Color.RED);
titlePanel.add(titleLabel); messageLabel = new JLabel(message);
messagePanel = new JPanel();
messagePanel.add(messageLabel);
messagePanel.setBackground(Color.YELLOW); mainPanel.add(titlePanel, BorderLayout.NORTH);
mainPanel.add(messagePanel, BorderLayout.CENTER); this.setSize(windowWidth, windowHeight);
this.setAlwaysOnTop(false);
this.getContentPane().add(mainPanel);
this.addMouseListener(this);
Toolkit.getDefaultToolkit().beep(); // 播放系统声音,提示一下
this.setVisible(true);
} @Override
public void run() {
Integer delay = 10;
Integer step = 1;
Integer end = windowHeight + bottmToolKitHeight;
while (true) {
try {
step++;
y = y - 1;
this.setLocation(x, y);
if (step > end) {
Thread.sleep(stayTime);
break;
}
Thread.sleep(delay);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
step = 1;
while (true) {
try {
step++;
y = y + 1;
this.setLocation(x, y);
if (step > end) {
this.dispose();
break;
}
Thread.sleep(delay);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.exit(0);
} @Override
public void mouseClicked(MouseEvent e) {
this.dispose();
System.exit(0);
} @Override
public void mouseEntered(MouseEvent e) { } @Override
public void mouseExited(MouseEvent e) { } @Override
public void mousePressed(MouseEvent e) { } @Override
public void mouseReleased(MouseEvent e) { } public static void main(String[] args) {
new RightCornerPopMessage();
}
}
Swing实现右下角消息框的更多相关文章
- C#代码像QQ的右下角消息框一样,无论现在用户的焦点在哪个窗口,消息框弹出后都不影响焦点的变化,那么有两种方法
你QQ的右下角消息框一样,无论现在用户的焦点在哪个窗口,消息框弹出后都不影响焦点的变化,那么有两种方法: 要么重写需要弹出的窗体的事件: protected override CreateParams ...
- EasyUI - Messager消息框
全局设定: JavaScript代码: //设置按钮中的文字,默认是-ok/cancel ,可以任意设置文字,比如现在的-确认/取消 $.messager.defaults = { ok: '确认', ...
- winform C#屏幕右下角弹出消息框并自动消失
①弹出信息框后慢慢下降消失 在主窗体中新增按钮重命名为btnShowAndDisappearMessages,在click事件中写如下代码: private void btnShowAndDisapp ...
- 【WPF】屏幕右下角消息提示框
WPF做一个仿QQ的右下角消息提示窗,网上找到几个Demo后,选了一个比较好用的. 博客 http://blog.csdn.net/huangli321456/article/details/5052 ...
- 动手动脑及java程序之用消息框进行数的运算
动手动脑 自信成就人生 动手动脑1 ✿仔细阅读示例: EnumTest.java,运行它,分析运行结果? package demo; public class Test { publi ...
- EasyUI Messager 消息框
通过 $.messager.defaults 重写默认的 defaults. 消息框(messager)提供不同样式的消息框,包括警示(alert).确认(confirm).提示(prompt).进展 ...
- jQuery EasyUI API 中文文档 - 消息框(Messager)
http://www.cnblogs.com/Philoo/archive/2011/11/15/jeasyui_api_messager.html Messager 消息框 博客园 风流涕淌 (p ...
- 基于.Net实现前端对话框和消息框
关于前端对话框.消息框的优秀插件多不胜数.造轮子是为了更好的使用轮子,并不是说自己造的轮子肯定好.所以,这个博客系统基本上都是自己实现的,包括日志记录.响应式布局等等一些本可以使用插件的.好了,废话不 ...
- 窗口-EasyUI Window 窗口、EasyUI Dialog 对话框、EasyUI Messager 消息框
EasyUI Window 窗口 扩展自 $.fn.panel.defaults.通过 $.fn.window.defaults 重写默认的 defaults. 窗口(window)是一个浮动的.可拖 ...
随机推荐
- Buffer源码深入分析
博客园对MarkDown显示的层次感不是很好,大家可以看这里:Buffeer. 本机环境: Linux 4.4.0-21-generic #37-Ubuntu SMP Mon Apr 18 18:33 ...
- 洛谷——P1348 Couple number
P1348 Couple number 题目描述 任何一个整数N都能表示成另外两个整数a和b的平方差吗?如果能,那么这个数N就叫做Couple number.你的工作就是判断一个数N是不是Couple ...
- 洛谷——1164 小A点菜(背包方案数)
大水题!! 题目背景 uim神犇拿到了uoi的ra(镭牌)后,立刻拉着基友小A到了一家……餐馆,很低端的那种. uim指着墙上的价目表(太低级了没有菜单),说:“随便点”. 题目描述 不过uim由于买 ...
- What makes grep consider a file to be binary?
grep -a worked for me: $ grep --help [...] -a, --text equivalent to --binary-files=text
- LA 3713 Astronauts
给个题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=sh ...
- 关于spring.net的面向切面编程 (Aspect Oriented Programming with Spring.NET)-简介
本文翻译自Spring.NET官方文档Version 1.3.2. 受限于个人知识水平,有些地方翻译可能不准确,但是我还是希望我的这些微薄的努力能为他人提供帮助. 侵删. 简介 Aspect-Orie ...
- matlab与C++以.mat文件方式进行数据相互流动
年前,放假回家之前,使用了C++与matlab之间的数据的互动的一个实验,感觉效果挺好.初步达到了目的,所以整理下来方便大家使用.减少大家编程学习的时间.希望对你们有用. #include " ...
- springMVC初探视图解析器——ResourceBundleViewResolver
视图解析器ResourceBundleViewResolver是根据proterties文件来找对应的视图来解析”逻辑视图“的, 该properties文件默认是放在classpath路径下的view ...
- ServicePointManager.ServerCertificateValidationCallback 冲突的解决
ServicePointManager是用于创建. 维护和删除的实例的静态类ServicePoint类. 当应用程序请求对 Internet 资源统一资源标识符 (URI) 的连接通过ServiceP ...
- Docker资源管理探秘:Docker背后的内核Cgroups机制
http://www.infoq.com/cn/articles/docker-resource-management-cgroups 随着Docker技术被越来越多的个人.企业所接受,其用途也越来越 ...