A. java弹出新窗口
定义一个按钮的OnClick事件
里面用写方法调用弹出窗口
代码
import java.awt.*;
import javax.swing.*;
import java.awt.Rectangle;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Frame1 extends JFrame
{
private JButton jButton1=new JButton();
public Frame1 ()
{
try {
jbInit();
}
catch(Exception exception) {
exception.printStackTrace();
}
this.setVisible(true);
}
private void jbInit () throws Exception
{
this.setBounds(300,180,400,300);
getContentPane().setLayout(null);
jButton1.setBounds(new Rectangle(127, 120, 139, 36));
jButton1.setMnemonic('C');
jButton1.setText("点我(C)");
jButton1.addActionListener(new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
jButton1_actionPerformed(e);
}
});
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().add(jButton1);
}
public static void main (String[] args)
{
Frame1 frame1=new Frame1();
}
public void jButton1_actionPerformed (ActionEvent e)
{
this.setVisible(false);
JFrame jf1=new JFrame("子窗口");
jf1.setBounds(100,50,800,600);
jf1.setDefaultCloseOperation(jf1.EXIT_ON_CLOSE);
jf1.setVisible(true);
}
}
B. jsp怎么弹出“您有1条新消息”这样的提示框
消息提示页面1.jsp,可以参考参考
<%@ page import="org.springframework.web.context.WebApplicationContext,
org.springframework.web.context.support.WebApplicationContextUtils,
com.seipher.waterSYS..IPromptDAO,
java.util.List"%>
<%@ page contentType="text/html;charset=gb2312" language="java" %>
<meta http-equiv="refresh" content="300">
<HTML><HEAD>
<%
WebApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
IPromptDAO promptDAO = (IPromptDAO) appContext.getBean("PromptDAOProxy");
Long depId = (Long)session.getAttribute("departmentId");
List result = promptDAO.findByDepUnRead(depId);
if ( result.size()> 0 ) {
%>
<SCRIPT language=JavaScript>
<!--
/**//*
** ==================================================================================================
** 类名:CLASS_MSN_MESSAGE
** 功能:提供类似MSN消息框
** 示例:
---------------------------------------------------------------------------------------------------
var MSG = new CLASS_MSN_MESSAGE("aa",200,120,"短消息提示:","您有1封消息","今天请我吃饭哈");
MSG.show();
---------------------------------------------------------------------------------------------------
** 作者:ttyp
** 邮件:[email protected]
** 日期:2005-3-18
** ==================================================================================================
**/
/**//*
* 消息构造
*/
function CLASS_MSN_MESSAGE(id,width,height,caption,title,message,target,action){
this.id = id;
this.title = title;
this.caption= caption;
this.message= message;
this.target = target;
this.action = action;
this.width = width?width:200;
this.height = height?height:120;
this.timeout= 1500;
this.speed = 20;
this.step = 1;
this.right = screen.width -1;
this.bottom = screen.height;
this.left = this.right - this.width;
this.top = this.bottom - this.height;
this.timer = 0;
this.pause = false;
this.close = false;
this.autoHide = true;
}
/**//*
* 隐藏消息方法
*/
CLASS_MSN_MESSAGE.prototype.hide = function(){
if(this.onunload()){
var offset = this.height>this.bottom-this.top?this.height:this.bottom-this.top;
var me = this;
if(this.timer>0){
window.clearInterval(me.timer);
}
var fun = function(){
if(me.pause==false||me.close){
var x = me.left;
var y = 0;
var width = me.width;
var height = 0;
if(me.offset>0){
height = me.offset;
}
y = me.bottom - height;
if(y>=me.bottom){
window.clearInterval(me.timer);
me.Pop.hide();
} else {
me.offset = me.offset - me.step;
}
me.Pop.show(x,y,width,height);
}
}
this.timer = window.setInterval(fun,this.speed)
}
}
/**//*
* 消息卸载事件,可以重写
*/
CLASS_MSN_MESSAGE.prototype.onunload = function() {
return true;
}
/**//*
* 消息命令事件,要实现自己的连接,请重写它
*
*/
CLASS_MSN_MESSAGE.prototype.oncommand = function(){
this.close = true;
// location='../waterAlert/PromptAction.do?action=selectWaitLink';
this.hide();
}
/**//*
* 消息显示方法
*/
CLASS_MSN_MESSAGE.prototype.show = function(){
var oPopup = window.createPopup(); //IE5.5+
this.Pop = oPopup;
var w = this.width;
var h = this.height;
var str = "<DIV style='BORDER-RIGHT: #455690 1px solid; BORDER-TOP: #a6b4cf 1px solid; Z-INDEX: 99999; LEFT: 0px; BORDER-LEFT: #a6b4cf 1px solid; WIDTH: " + w + "px; BORDER-BOTTOM: #455690 1px solid; POSITION: absolute; TOP: 0px; HEIGHT: " + h + "px; BACKGROUND-COLOR: #c9d3f3'>"
str += "<TABLE style='BORDER-TOP: #ffffff 1px solid; BORDER-LEFT: #ffffff 1px solid' cellSpacing=0 cellPadding=0 width='100%' bgColor=#cfdef4 border=0>"
str += "<TR>"
str += "<TD style='FONT-SIZE: 12px;COLOR: #0f2c8c' width=30 height=24></TD>"
str += "<TD style='PADDING-LEFT: 4px; FONT-WEIGHT: normal; FONT-SIZE: 12px; COLOR: #1f336b; PADDING-TOP: 4px' vAlign=center width='100%'>" + this.caption + "</TD>"
str += "<TD style='PADDING-RIGHT: 2px; PADDING-TOP: 2px' vAlign=center align=right width=19>"
str += "<SPAN title=关闭 style='FONT-WEIGHT: bold; FONT-SIZE: 12px; CURSOR: hand; COLOR: red; MARGIN-RIGHT: 4px' id='btSysClose' >×</SPAN></TD>"
str += "</TR>"
str += "<TR>"
str += "<TD style='PADDING-RIGHT: 1px;PADDING-BOTTOM: 1px' colSpan=3 height=" + (h-28) + ">"
str += "<DIV style='BORDER-RIGHT: #b9c9ef 1px solid; PADDING-RIGHT: 8px; BORDER-TOP: #728eb8 1px solid; PADDING-LEFT: 8px; FONT-SIZE: 12px; PADDING-BOTTOM: 8px; BORDER-LEFT: #728eb8 1px solid; WIDTH: 100%; COLOR: #1f336b; PADDING-TOP: 8px; BORDER-BOTTOM: #b9c9ef 1px solid; HEIGHT: 100%'>" + this.title + "<BR><BR>"
str += "<DIV style='WORD-BREAK: break-all' align=left><A href='javascript:void(0)' hidefocus=true id='btCommand'><FONT color=#ff0000>" + this.message + "</FONT></A></DIV>"
str += "</DIV>"
str += "</TD>"
str += "</TR>"
str += "</TABLE>"
str += "</DIV>"
oPopup.document.body.innerHTML = str;
this.offset = 0;
var me = this;
oPopup.document.body.onmouseover = function(){me.pause=true;}
oPopup.document.body.onmouseout = function(){me.pause=false;}
var fun = function(){
var x = me.left;
var y = 0;
var width = me.width;
var height = me.height;
if(me.offset>me.height){
height = me.height;
} else {
height = me.offset;
}
y = me.bottom - me.offset;
if(y<=me.top){
me.timeout--;
if(me.timeout==0){
window.clearInterval(me.timer);
if(me.autoHide){
me.hide();
}
}
} else {
me.offset = me.offset + me.step;
}
me.Pop.show(x,y,width,height);
}
this.timer = window.setInterval(fun,this.speed)
var btClose = oPopup.document.getElementById("btSysClose");
btClose.onclick = function(){
me.close = true;
me.hide();
}
var btCommand = oPopup.document.getElementById("btCommand");
btCommand.onclick = function(){
me.oncommand();
}
}
/**//*
** 设置速度方法
**/
CLASS_MSN_MESSAGE.prototype.speed = function(s){
var t = 20;
try {
t = praseInt(s);
} catch(e){}
this.speed = t;
}
/**//*
** 设置步长方法
**/
CLASS_MSN_MESSAGE.prototype.step = function(s){
var t = 1;
try {
t = praseInt(s);
} catch(e){}
this.step = t;
}
CLASS_MSN_MESSAGE.prototype.rect = function(left,right,top,bottom){
try {
this.left = left !=null?left:this.right-this.width;
this.right = right !=null?right:this.left +this.width;
this.bottom = bottom!=null?(bottom>screen.height?screen.height:bottom):screen.height;
this.top = top !=null?top:this.bottom - this.height;
} catch(e){}
}
var MSG1 = new CLASS_MSN_MESSAGE("aa",200,120,"<%=session.getAttribute("departmentName")%>短消息提示:","您有<%=result.size()%>个待办工作","请及时处理");
MSG1.rect(null,null,null,screen.height-50);
MSG1.speed = 10;
MSG1.step = 5;
//alert(MSG1.top);
MSG1.show();
//同时两个有闪烁,只能用层代替了,不过层不跨框架
var MSG2 = new CLASS_MSN_MESSAGE("aa",200,120,"短消息提示:","您有2封消息","好的啊");
// MSG2.rect(100,null,null,screen.height);
// MSG2.show();
//-->
</SCRIPT>
<META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD>
<%result = null;}%>
<BODY></BODY></HTML>
C. Java在Swing中如何实现弹出一个对话框的效果
可以使用JoptionPane:
有几种提抄示框:
第一种:
JOptionPane.showMessageDialog(jPanel,"提示消息","标题",JOptionPane.WARNING_MESSAGE);
D. 用Java做一个聊天程序,在任务栏处提示效果怎么做
java 可以实现将程序最小化到托盘的吧.....
甚至还可以设定最小化到托盘的图标,这样的话,当有新消息到达时,你可以把它的图标设置成无色的另一图片(或者只将其最小化,而不设置其图标),然后再设置成原来的图片,如此反复,就实现了闪烁的功能.........
不过似乎先要判断当前操作系统是否支持系统托盘..........下面这个程序实现了系统托盘,但是似乎在我的电脑上没实现出来,难道操作系统不支持?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SystemTrayTest extends JFrame implements ActionListener
{
//创建菜单、菜单项数组、消息类型
PopupMenu popup=new PopupMenu();
Menu menu=new Menu("消息类型");
MenuItem[] itemArray ={new MenuItem("信息消息"),new MenuItem("常规消息"),
new MenuItem("警告消息"),new MenuItem("错误消息"),new MenuItem("退出程序")};
//定义系统托盘、托盘图标变量
SystemTray tray;
TrayIcon trayIcon;
//构造方法
public SystemTrayTest(){
//对菜单项添加监听并将菜单项添加到菜单中
for(int i=0;i<itemArray.length;i++){
if(i<4){
itemArray[i].addActionListener(this);//为菜单项注册监听器
//将菜单项数组中前3个菜单项添加进"弹出消息"菜单中
menu.add(itemArray[i]);
}
itemArray[4].addActionListener(this);//添加监听
popup.add(menu);//将弹出消息菜单添加到菜单中
popup.add(itemArray[4]);//将退出菜单添加到菜单中
}
// 判断当前操作系统是否支持系统托盘
if (SystemTray.isSupported()) {
//获取系统托盘
tray = SystemTray.getSystemTray();
//加载图标
Image image = Toolkit.getDefaultToolkit().getImage("d:/trayIcon.jpg");
//创建托盘图标
trayIcon=new TrayIcon(image,"系统托盘测试",popup);
//托盘图标自动设置尺寸
trayIcon.setImageAutoSize(true);
try{//添加托盘图标到系统托盘中
tray.add(trayIcon);
}
catch(AWTException e){
e.printStackTrace();
}
//为托盘图标注册监听器
trayIcon.addActionListener(this);
}
//设置窗体关闭按扭所执行的动作
this.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
SystemTrayTest.this.hide();//隐藏窗体
}
});
//设置窗体属性
this.setTitle("系统托盘测试");
this.setBounds(200,200,150,100);
this.setVisible(true);
}
//重写actionPerformed方法
public void actionPerformed(ActionEvent e){
if(e.getSource()==itemArray[0])
{//点击信息消息菜单项执行的动作
trayIcon.displayMessage("信息","程序最小化,仍在运行",TrayIcon.MessageType.INFO);
}else if(e.getSource()==itemArray[1])
{//点击信息消息菜单项执行的动作
trayIcon.displayMessage("常规信息","现在一切正常",TrayIcon.MessageType.NONE);
}else if(e.getSource()==itemArray[2])
{//单击警告消息菜单项执行的动作
trayIcon.displayMessage("警告信息","有不明来源的攻击",TrayIcon.MessageType.WARNING);
}else if(e.getSource()==itemArray[3])
{//点击错误消息菜单项执行的动作
trayIcon.displayMessage("错误信息","程序发生严重错误",TrayIcon.MessageType.ERROR);
}else if(e.getSource()==itemArray[4])
{//点击退出程序菜单项执行的动作
System.exit(0);
}else if(e.getSource()==trayIcon)
{//双击托盘图标执行的代码
this.show(true);
}
}
//主方法
public static void main(String args[])
{//创建SystemTrayTest窗体对象
new SystemTrayTest();
}
}
E. java如何实现消息提示
你说的是类似msn弹出式消息吧
两年前做过一个项目有用到你说这个功能,所用框架除了没用到spring,其他是一样的。另外用了ajax跟dwr框架,当时我们做的是一个CRM系统,主要在员工登陆系统用消息显示上级领导发出的紧急任务、跟在项目控制流程中用消息显示项目实时进度。
整理了下思路,给你讲下但是我们怎么实现的吧,仅供参考:
站内消息不需要用到线程。主要都用系统当前时间、消息状态控制消息的显示与否
首先数据库要一张消息表,记录消息体信息。包括消息主题、用户id、时间、发出页面、消息状态。
主体实现主要是用js控制,我们用的dwr技术,将消息体的获取,时间控制及当前时间要显示的消息个数,都写到dwr配置的类中。
接着在消息js中通过dwr生成的js名称调用上述的方法获取消息信息,将数据封装到js中,在需要使用消息的页面只需要导入消息js、dwr的js就可以使用了。
当时我们是从网上下载了一个页面,自己改的js,然后决定用dwr控制数据的流转,如果不懂,就留个邮箱,我发一个html给你,你一看就会明白了。
F. 用Java实现,新消息提醒功能,类似于新浪微博的新消息提醒,请问谁有例子
新浪那个实时来提醒是定时发自动ajax请求的。
你可以打开控制台,看 network,是每隔一段时间发动ajax请求,返回是否有新消息。
var timer = setInterval(function(){
//这里是ajax的代码
}, 时间间隔);
G. java中怎样自动弹出消息
import java.awt.BorderLayout;
import javax.swing.JFrame;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
import javax.swing.*;
public class Exp extends JFrame
{
public Exp()
{
try
{
jbInit();
// 把窗体放到中间
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = this.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
this.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
this.setVisible(true);
}
catch (Exception exception)
{
exception.printStackTrace();
}
}
private void jbInit() throws Exception
{
getContentPane().setLayout(null);
this.setTitle("例子");
this.addWindowListener(new Exp_this_windowAdapter(this));
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
this.setSize(new Dimension(400, 300));
}
public static void main(String[] args)
{
Exp a=new Exp();
}
//窗体关闭事件
public void this_windowClosing(WindowEvent e)
{
/*当窗体关闭时候,弹出个对话框,问"您确定退出吗?",标题栏为:"关闭",弹出的对话框
有两个按钮,一个为"是",一个为"否",若单击"是",则退出程序,否则什么也不做*/
int b= JOptionPane.showConfirmDialog(this,"您确定退出吗?","关闭",JOptionPane.OK_OPTION);
//单击按钮 "是" 的返回数值为0
if(b==0)
{
System.exit(0);
}
}
}
class Exp_this_windowAdapter extends WindowAdapter
{
private Exp adaptee;
Exp_this_windowAdapter(Exp adaptee)
{
this.adaptee = adaptee;
}
public void windowClosing(WindowEvent e)
{
adaptee.this_windowClosing(e);
}
}
我QQ是: 349227882 哪里看不明白问我,关键代码在我注释的地方;
H. java手机消息推送怎么做
主要介绍其中的五种实现方式:短轮询、Comet、Flash XMLSocket、Server-sent、WebSocketI. java里弹出提示窗口的方法是什么
javax.swing.JOptionPane
JOptionPane
public JOptionPane(Object message,
int messageType,
int optionType,
Icon icon,
Object[] options,
Object initialValue)在指定最初选择的选项的前提下,创建一个显示消息的 JOptionPane 的实例,使其具有指定的消息类型、图标和选项。
参数:
message - 要显示的 Object
messageType - 要显示的消息类型:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE 或 PLAIN_MESSAGE
optionType - 要在窗格中显示的选项:DEFAULT_OPTION、YES_NO_OPTION、YES_NO_CANCEL_OPTION、OK_CANCEL_OPTION
icon - 要显示的图标图像
options - 用户可以选择的选项
initialValue - 最初选择的选项;如果为 null,则不做最初选择;只有在使用 options 时才有意义