单位建立了一个管理网站,主要用来做流程审批.
现在领导要求开发一个小的桌面客户端,能够在不打开浏览器登陆系统的情况下,用户有新任务时弹出消息提示.
应该如何实现?用java可以实现吗?
最好能有一些资料和比较详细的说明.
java的awt、swing可以做一些简单一点的桌面程序,检测信息状态,有新任务时弹出一个提示
可以用消息中间件 xxxMQ 监听用户有新任务 http://blog.csdn.net/a639735331/article/details/72594194
package service.com;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRootPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import com.sun.awt.AWTUtilities;
public class TipWindow {
JFrame frame;
JLabel label;
JEditorPane editorPane;
private int width;//窗体宽度
private int height;//窗体高度
private int stayTime;//休眠时间
private String title;//消息标题
private String message;//窗体内容
private int style;//窗体样式
static {
try {
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (ClassNotFoundException | InstantiationException
| IllegalAccessException | UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
}
/**
@param message 提示框内容(支持HTML标签)
*/
public TipWindow(int width, int height, int stayTime, int style, String title, String message) {
this.width = width;
this.height = height;
this.stayTime = stayTime;
this.style = style;
this.title = title;
this.message = message;
}
public TipWindow(int stayTime, int style, String title, String message) {
this.width = 300;
this.height = 100;
this.stayTime = stayTime;
this.style = style;
this.title = title;
this.message = message;
}
public void initialize() {
frame = new JFrame();
editorPane = new JEditorPane();
editorPane.setEditable(false);
editorPane.setContentType("text/html");
editorPane.setText(message);
frame.add(editorPane);
frame.setTitle(title);
//设置窗体的位置及大小
Point location = MouseInfo.getPointerInfo().getLocation();
frame.setBounds((int)location.getX(), (int)location.getY(), width, height);
frame.setUndecorated(true);//去掉窗口的装饰
frame.getRootPane().setWindowDecorationStyle(style);//设置窗体样式
AWTUtilities.setWindowOpacity(frame, 0);//初始化透明度
frame.setVisible(true);
frame.setAlwaysOnTop(true);//窗体置顶
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
hide();
}
});
}
//窗体逐渐变清晰
public void show() {
for (int i = 1; i < 20; i++) {
try {
Thread.sleep(50);
} catch (Exception e) {
AWTUtilities.setWindowOpacity(frame, i * 0.05F);
}
}
}
//窗体逐渐变淡甚至消失
public void hide() {
float opacity = 100;
while(true) {
if (opacity < 2) {
break;
}
opacity -= 2;
AWTUtilities.setWindowOpacity(frame, opacity / 100);
try {
Thread.sleep(150);
} catch (Exception e) {
e.printStackTrace();
}
}
frame.dispose();
}
public void run() {
initialize();
show();
try {
Thread.sleep(stayTime * 1000);
} catch (Exception e) {
e.printStackTrace();
}
hide();
}
public static void main(String[] args) {
String title = "友情提示!";
String message = "主人!
该休息了!";
TipWindow tipWindow = new TipWindow(2, JRootPane.QUESTION_DIALOG, title, message);
tipWindow.run();
}
}
弹窗界面用awt,推送用socket。
我写过一个类似 我那玩意的目的是实现目录上传和服务器同步刷新之类的功能, 我用C++开发的客户端程序,你也可以用java写客户端但是那样程序体积太大,我用的是socket通信,但是你那个功能的实现的话不需要使用socket ,直接在服务端开放一个接口,给客户端可以访问即可,然后通过参数去匹配做啥米事~