package com.message;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import java.awt.Insets;
import java.awt.Toolkit;
import javax.swing.JDialog;
/**
* @author Administrator 此工具类用法:实例化出对象,调用 void show("标题","内容") 方法. InfoUtil tool
* = new InfoUtil(); tool.show("标题","内容")
*/
public class InfoUtil {
private Point oldP; // 上一次坐标,拖动窗口时用
private TipWindow tw = null; // 提示框
private ImageIcon img = null; // 图像组件
private JLabel imgLabel = null; // 背景图片标签
private JPanel headPan = null;
private JPanel feaPan = null;
private JPanel btnPan = null;
private JLabel title = null; // 栏目名称
private JLabel head = null; // 蓝色标题
private JLabel close = null; // 关闭按钮
private JTextArea feature = null; // 内容
private JLabel releaseLabel = null; // 发布时间
private JButton sure = null;
private String titleT = null;
private String word = null;
private String time = null;
// private SimpleDateFormat sdf = new
// SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public void init() {
// 新建300x220的消息提示框
tw = new TipWindow(300, 180);
img = new ImageIcon("/images/tip-background.gif");//最好写相对路径
imgLabel = new JLabel(img);
// 设置各个面板的布局以及面板中控件的边界
headPan = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
feaPan = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
btnPan = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
title = new JLabel("欢迎使用本系统");
head = new JLabel(titleT);
close = new JLabel("x");
feature = new JTextArea(word);
// releaseLabel = new JLabel("发布于 " + time);
sure = new JButton("确认");
sure.setHorizontalAlignment(SwingConstants.CENTER);
// sure.setOpaque(true);
// sure.setBackground(Color.ORANGE);
// 将各个面板设置为透明,否则看不到背景图片
((JPanel) tw.getContentPane()).setOpaque(false);
headPan.setOpaque(false);
feaPan.setOpaque(false);
btnPan.setOpaque(false);
// 设置JDialog的整个背景图片
tw.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
imgLabel.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
headPan.setPreferredSize(new Dimension(300, 60));
// 设置提示框的边框,宽度和颜色
tw.setBackground(Color.LIGHT_GRAY);
tw.getRootPane().setBorder(
BorderFactory.createMatteBorder(1, 1, 1, 1, Color.gray));
title.setPreferredSize(new Dimension(260, 26));
title.setVerticalTextPosition(JLabel.CENTER);
title.setHorizontalTextPosition(JLabel.CENTER);
title.setFont(new Font("宋体", Font.PLAIN, 12));
title.setForeground(Color.black);
close.setFont(new Font("Arial", Font.BOLD, 15));
close.setPreferredSize(new Dimension(20, 20));
close.setVerticalTextPosition(JLabel.CENTER);
close.setHorizontalTextPosition(JLabel.CENTER);
close.setCursor(new Cursor(12));
close.setToolTipText("关闭");
head.setPreferredSize(new Dimension(250, 35));
head.setVerticalTextPosition(JLabel.CENTER);
head.setHorizontalTextPosition(JLabel.CENTER);
head.setFont(new Font("宋体", Font.PLAIN, 14));
head.setForeground(Color.black);
feature.setEditable(false);
feature.setPreferredSize(new Dimension(260, 500));
feature.setForeground(Color.RED);
feature.setFont(new Font("宋体", Font.PLAIN, 14));
feature.setBackground(Color.orange);
// 设置文本域自动换行
feature.setLineWrap(true);
// releaseLabel.setForeground(Color.DARK_GRAY);
// releaseLabel.setFont(new Font("宋体", Font.PLAIN, 12));
sure.setPreferredSize(new Dimension(60, 30));
// 设置标签鼠标手形
sure.setCursor(new Cursor(12));
// headPan.add(title);
headPan.add(head);
headPan.add(close);
feaPan.add(feature);
// feaPan.add(releaseLabel);
btnPan.add(sure);
tw.add(headPan, BorderLayout.NORTH);
tw.add(feaPan, BorderLayout.CENTER);
tw.add(btnPan, BorderLayout.SOUTH);
}
public void handle() {
// 为更新按钮增加相应的事件
sure.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
// JOptionPane.showMessageDialog(tw, "谢谢,再见");
tw.close();
}
public void mouseEntered(MouseEvent e) {
sure.setBorder(BorderFactory.createLineBorder(Color.gray));
}
public void mouseExited(MouseEvent e) {
sure.setBorder(null);
}
});
// 增加鼠标拖动事件
title.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
// TODO Auto-generated method stub
Point newP = new Point(e.getXOnScreen(), e.getYOnScreen());
int x = tw.getX() + (newP.x - oldP.x);
int y = tw.getY() + (newP.y - oldP.y);
tw.setLocation(x, y);
oldP = newP;
}
});
// 鼠标按下时初始坐标,供拖动时计算用
title.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
oldP = new Point(e.getXOnScreen(), e.getYOnScreen());
}
});
// 右上角关闭按钮事件
close.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
tw.close();
}
public void mouseEntered(MouseEvent e) {
close.setBorder(BorderFactory.createLineBorder(Color.gray));
}
public void mouseExited(MouseEvent e) {
close.setBorder(null);
}
});
}
public void show(String titleT, String word) {
this.titleT = titleT;
this.word = word;
// time = sdf.format(new Date());
init();
handle();
tw.setAlwaysOnTop(true);
tw.setUndecorated(true);
tw.setResizable(false);
tw.setVisible(true);
tw.run();
}
public void close() {
tw.close();
}
}
class TipWindow extends JDialog {
private static final long serialVersionUID = 8541659783234673950L;
private static Dimension dim;
private int x, y;
private int width, height;
private static Insets screenInsets;
public TipWindow(int width, int height) {
this.width = width;
this.height = height;
dim = Toolkit.getDefaultToolkit().getScreenSize();
screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(
this.getGraphicsConfiguration());
x = (int) (dim.getWidth() - width - 3);
y = (int) (dim.getHeight() - screenInsets.bottom - 3);
initComponents();
}
public void run() {
for (int i = 0; i <= height; i += 10) {
try {
this.setLo
没有合适的资源?快使用搜索试试~ 我知道了~
java NIO推送实例
共73个文件
class:24个
java:13个
jar:8个
5星 · 超过95%的资源 需积分: 9 14 下载量 89 浏览量
2018-05-22
09:35:43
上传
评论
收藏 14.9MB ZIP 举报
温馨提示
java NIO 消息推送实例代码,解压Tmp.zip Desk为桌面程序,DeskAppServer为服务端程序,江巅
资源推荐
资源详情
资源评论
收起资源包目录
tmp.zip (73个子文件)
Desk
.project 380B
jbs-desk.log.lck 0B
src
com
info
AppInfo.java 332B
util
Log.java 3KB
message
InfoUtil.java 9KB
socket
SocketService.java 5KB
parent.java 2KB
lib
commons-collections-3.2.jar 558KB
commons-beanutils-1.8.3.jar 227KB
ezmorph-1.0.4.jar 84KB
json-lib-2.2.2-jdk15.jar 141KB
commons-lang3-3.2.1.jar 376KB
commons-logging-1.2.jar 60KB
commons-lang-2.6.jar 278KB
jbs-desk.log.1 75B
jbs-desk.log.1.lck 0B
.settings
org.eclipse.jdt.core.prefs 670B
org.eclipse.core.resources.prefs 70B
resources
images
tip-background.gif 3KB
systemicon.png 4KB
jbs-desk.log 23KB
.classpath 4KB
bin
images
tip-background.gif 3KB
systemicon.png 4KB
com
parent$1.class 1KB
info
AppInfo.class 640B
util
MyFormatter.class 2KB
Log.class 3KB
message
TipWindow.class 2KB
InfoUtil$3.class 841B
InfoUtil$2.class 1KB
InfoUtil$1.class 1KB
InfoUtil$4.class 1KB
InfoUtil.class 5KB
parent.class 1KB
socket
SocketService$1.class 2KB
SocketService.class 3KB
SocketService$2.class 3KB
DeskAppServer
.project 565B
src
main
resources
deve
application.properties 16B
prod
test
pre
java
jbs
deskapp
config
ConfigInfo.java 135B
SocketEvent.java 288B
socket
ClientSocketTable.java 1KB
ServerSocketListener.java 5KB
handler
ContentHandler.java 2KB
AppMain.java 662B
controller
BaseController.java 106B
RokidController.java 1KB
target
conf
application.properties 16B
DeskAppServer-0.0.1-SNAPSHOT.jar.original 12KB
DeskAppServer-0.0.1-SNAPSHOT.jar 14.91MB
maven-status
maven-compiler-plugin
compile
default-compile
createdFiles.lst 0B
inputFiles.lst 701B
generated-sources
annotations
classes
jbs
deskapp
AppMain.class 982B
config
SocketEvent.class 444B
ConfigInfo.class 367B
socket
ServerSocketListener.class 5KB
ClientSocketTable.class 3KB
handler
ContentHandler.class 2KB
ServerSocketListener$1.class 2KB
controller
RokidController.class 2KB
BaseController.class 387B
application.properties 16B
META-INF
MANIFEST.MF 323B
maven
jbs.deskapp
DeskAppServer
pom.properties 238B
pom.xml 2KB
maven-archiver
pom.properties 130B
test-classes
jbs
deskapp
DeskAppServer
AppTest.class 1KB
.settings
org.eclipse.m2e.core.prefs 90B
org.eclipse.jdt.core.prefs 736B
org.eclipse.core.resources.prefs 124B
pom.xml 2KB
.classpath 1KB
共 73 条
- 1
资源评论
- weixin_426863052018-07-26还没看不知道怎么样
- myjier0012018-09-20下载来测试一下,看看功能实现的怎样
wyyybf
- 粉丝: 7
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功