CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  J2SE / 基础类

消息提示框!!大虾帮忙

楼主milufeiyang(迷路飞羊)2002-05-28 10:48:19 在 Java / J2SE / 基础类 提问

弹出一个消息提示框,提示框有确定和取消两个按钮,我如何控制这两个按钮的事件?(jb的design里面好像看不到这两个按钮)  
  比如当点击确定,退出这个消息框并做相应处理  
  点击取消,直接退出回到上级页面!  
  请给出从头至尾的代码处理(包括弹出消息提示框)。  
   
  在线等待,一定给分  
  问题点数:80、回复次数:5Top

1 楼Apocalypse(逍遥思辨)回复于 2002-05-28 12:01:47 得分 20

int   reply   =   JOptionPane.showConfirmDialog(null,  
                                                                                              "question",  
                                                                                              "confirm",  
                                                                                              JOptionPane.YES_NO_OPTION,  
                                                                                              JOptionPane.QUESTION_MESSAGE);  
   
          if   (reply   !=   JOptionPane.YES_OPTION)   {  
              return;  
          }   //canceled.  
   
          continue   and   do   your   bussiness...Top

2 楼milufeiyang(迷路飞羊)回复于 2002-05-28 16:46:55 得分 0

请问该如何去掉这个message的咖啡和大问号?还有怎么改是和否两个按钮的字体及显示?Top

3 楼milufeiyang(迷路飞羊)回复于 2002-05-28 16:53:20 得分 0

分不是问题,如果不够我会再开个窗口给……Top

4 楼chenbin(剿皮)回复于 2002-05-28 16:55:08 得分 0

请参考J2SDK文档中关于JOptionPane.showConfirmDialog函数的各个参数说明Top

5 楼cxy550(小宇)回复于 2002-05-28 18:47:32 得分 60

这是一个完整的消息提示框程序,你可以根据自己的需要更改。别忘了给分哦!!  
   
  //Listing   14.3     TJOptionPane2.java  
  /*  
    *   <Applet   code=TJOptionPane2   width=400   height=75>  
    *   </Applet>  
    */  
   
  import   javax.swing.*;  
  import   java.awt.*;  
  import   java.awt.event.*;  
  import   java.util.*;  
  import   java.text.*;  
   
  public   class   TJOptionPane2   extends   JApplet   {  
          Container   container   =   null;  
   
          public   void   init()   {  
                  //   1.   Get   a   handle   on   the   applet's   content   pane.  
                  container   =   this.getContentPane();  
   
                  //   2.   Add   a   box   to   the   content   pane.  
                  Box   box   =   new   Box(BoxLayout.X_AXIS);  
                  container.add(box);  
   
                  //   3.   Add   a   button   to   the   box.  
                  JButton   button   =   new   JButton("Show   Time");  
                  button.setPreferredSize(new   Dimension(150,25));  
                  button.addActionListener(new   ButtonListener());  
                  box.add(Box.createGlue());  
                  box.add(button);  
                  box.add(Box.createGlue());  
          }  
   
          //   4.   The   listener   class.  
          class   ButtonListener   implements   ActionListener   {  
                  //   5.   Argument   values   for   the   confirmation   dialog   box.  
                  Object   confirmText   =   "Do   You   Wish   To   See   Date   Also?";  
                  String   confirmTitle   =   "Date   Confirmation   Dialog";  
                  int   optionType   =   JOptionPane.YES_NO_OPTION;  
                  int   messageType1   =   JOptionPane.QUESTION_MESSAGE;  
   
                  //   6.   Argument   values   for   the   message   dialog   box.  
                  Object   information   =   null;  
                  String   title   =   "Message   Display   Dialog";  
                  int   messageType2   =   JOptionPane.INFORMATION_MESSAGE;  
   
   
                  //   7.   Option   selected.  
                  //   If   the   selection   is   'yes',   selectedValue   =   0;  
                  //   If   the   selection   is   'No',   selectedValue   =   1;  
                  int   selectedValue;  
   
                  public   void   actionPerformed(ActionEvent   e)   {  
                          //   8.   Display   the   confirmation   dialog   box.  
                          selectedValue   =   JOptionPane.showConfirmDialog(container,  
                                                                    confirmText,   confirmTitle,  
                                                                    optionType,   messageType1);  
   
                          //   9.   Fetch   the   time   or   date   and   time.  
                          information   =   fetchInformation();  
   
                          //   10.   Display   the   message.  
                          JOptionPane.showMessageDialog(container,  
                                                                                      information,   title,  
                                                                                      messageType2);  
                  }  
   
                  //   11.   Returns   the   time   or   date   and   time   depending  
                  //   on   the   Yes   or   No   choice   made.  
                  public   String   fetchInformation()   {  
                          DateFormat   formatter   =   null;  
   
                          if   (selectedValue   ==   0)   {     //If   it   is   Yes.  
                                  formatter   =   DateFormat.getDateTimeInstance(  
                                                                                DateFormat.SHORT,  
                                                                                DateFormat.LONG);  
                          }  
                          else   if(selectedValue   ==   1)   {     //If   it   is   No.  
                                  formatter   =   DateFormat.getTimeInstance(  
                                                                                        DateFormat.LONG);  
                          }  
   
                          //   Format   the   time   or   date   and   time   and   return.  
                          return(formatter.format(new   Date()));  
                  }  
          }  
  }Top

相关问题

  • WinForm中实现消息提示框????
  • 在ASP.NET中如何设置一个消息提示框?
  • 从主窗口发消息给对话框,如何,高手提示???
  • 请问如何在点击连接后弹出消息提示框?
  • 一打开IE,就出现“正在准备安装”的消息提示框
  • 提示框
  • 如何实现象MSN的消息提示框那样,对话框顶层显示时,焦点不切换?
  • 西祠那样的提示有没有新消息的可以缩小扩大和定时刷新的提示框怎么写~~?
  • 在IE最小化的情况下,有什么办法可以让短信提示框象QQ的消息提示那样显示出来呢?
  • 提示框问题!

关键词

  • 消息
  • date
  • null
  • joptionpane
  • selectedvalue
  • box
  • 消息提示框
  • dateformat
  • messagetype
  • showconfirmdialog

得分解答快速导航

  • 帖主:milufeiyang
  • Apocalypse
  • cxy550

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo