使用showConfirmDialog显示确认框

------------------siwuxie095

工程名:TestJOptionPane

包名:com.siwuxie095.showdialog

类名:TestConfirmDialog.java

工程结构目录如下:

代码:


package com.siwuxie095.showdialog;

import java.awt.BorderLayout;

import java.awt.EventQueue;

import javax.swing.JFrame;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.UIManager;

import javax.swing.UnsupportedLookAndFeelException;

import javax.swing.border.EmptyBorder;

import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;

import javax.swing.JButton;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

public class TestConfirmDialog extends JFrame {

private JPanel contentPane;

/**

* Launch the application.

*/

public static
void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public
void run() {

try {

TestConfirmDialog frame = new TestConfirmDialog();

frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

}

/**

* Create the frame.

*/

public TestConfirmDialog() {

try {

UIManager.setLookAndFeel(new WindowsLookAndFeel());

} catch (UnsupportedLookAndFeelException e1) {

e1.printStackTrace();

}

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setBounds(100, 100, 450, 300);

contentPane = new JPanel();

contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

contentPane.setLayout(new BorderLayout(0, 0));

setContentPane(contentPane);

JButton btnshowconfirmdialog = new JButton("显示确认框(showConfirmDialog)");

//为
按钮
添加鼠标点击事件

btnshowconfirmdialog.addMouseListener(new MouseAdapter() {

@Override

public
void mouseClicked(MouseEvent e) {

//直接通过静态方法调用,指定父级窗体

信息

//返回值是 int 类型,创建以接收返回值

//没有关闭确认框时,后面的主窗体是完全无法操作的(即
阻塞)

// int value=JOptionPane.showConfirmDialog(TestConfirmDialog.this,

// "你确认退出吗?");

//

// if (value==JOptionPane.YES_OPTION) {

// System.out.println("你选择了
是");

// System.exit(0);

// }else if (value==JOptionPane.NO_OPTION) {

// System.out.println("你选择了
否");

// }else if (value==JOptionPane.CANCEL_OPTION) {

// System.out.println("你选择了
取消");

// }else if (value==JOptionPane.CLOSED_OPTION) {

// System.out.println("你直接将窗体关闭了,没有选择");

// }

//需要指定
父级窗体,信息,标题,选项类型,信息类型

int valuex=JOptionPane.showConfirmDialog(TestConfirmDialog.this,

"你确认要退出程序吗?", "请确认",

JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

//判断时要根据第四个参数 optionType

//可以选择一个最有用的按钮来判断它的值并处理即可,不用全部都判断

if (valuex==JOptionPane.YES_OPTION) {

System.exit(0);

}

}

});

btnshowconfirmdialog.setFocusable(false);

contentPane.add(btnshowconfirmdialog, BorderLayout.NORTH);

}

}

将窗体
JFrame 的 LookAndFeel 设定为 Windows

在根面板 contentPane 的上方添加一个 JButton,

将其 focusable 属性设为
false

为 JButton 添加 mouseClicked 事件,点击 按钮 弹出确认框

运行程序:

【made by siwuxie095】

时间: 2024-08-08 03:55:19

使用showConfirmDialog显示确认框的相关文章

jQuery mobile 学习06 提示框和确认框

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getS

Android 学习笔记之AndBase框架学习(二) 使用封装好的进度框,Toast框,弹出框,确认框...

PS:渐渐明白,在实验室呆三年都不如在企业呆一年... 学习内容: 1.使用AbActivity内部封装的方法实现进度框,Toast框,弹出框,确认框...   AndBase中AbActivity封装好了许多方法提供我们去使用,使得在使用的时候更加的方便,只需要传递相关参数即可..省去了我们自己使用基础的函数进行构造...   就好比进度框,Toast框,弹出框,确认框...这些基本的东西都在AndBase的AbActivity封装好了...我们只需要传递参数调用其中内部的方法就可以完成这些视

C# GridView Edit &amp; Delete, 点击Delete的时候弹出确认框

1. 使用GridView自带属性ShowEditButton和ShowDeleteButton,均设为True  <Columns> ... <asp:CommandField ShowEditButton="True" ShowDeleteButton="True"></asp:CommandField> </Columns> 则在GridView指定列的位置会显示Edit和Delete的LinkButton 2.

jQuery UI实现的自定义confirm确认框简单介绍

jQuery UI实现的自定义confirm确认框简单介绍:本章节介绍一下jQuery UI自定义了一个confirm的确认对话框效果.通过html代码自定义对话框的显示界面和外观,可以自定义confirm框的按钮.本例中定义了一个confirm确认按钮和一个cancel取消按钮.html代码: <button id="callConfirm">Confirm!</button> <div id="dialog" title="

javascript中输出信息的方法-信息确认框-提示输入框-文档流输出

js中输出信息的方法 1.文档流输出 document.write('hello'); 2.输出信息提示框 模态对话框 window.alert('要输出显示的内容');  或 alert('要输出显示的内容'); alert(n); 3.信息确认框 var f =  window.confirm('是否要进入新浪网');  confirm(""); if(f){ location.href = 'http://www.sina.com.cn'; } 4.提示输入框 window.pr

点击显示弹框

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>弹框</title> <link rel="stylesheet" href="style.css"> <style> html{font-size:100px;} /*弹窗登陆页start*/ .

WPF 提示框、确认框、确认输入框

1.提示框 分为提示.异常.失败.成功几种类型 方法: /// <summary> /// 弹出提示 /// 标题:提示 /// </summary> /// <param name="strContent">内容</param> public static void ShowInfoMessageBox(string strContent) { AlertRadWindow(Application.Current.MainWindow,

[转]js中confirm实现执行操作前弹出确认框的方法

原文地址:http://www.jb51.net/article/56986.htm 本文实例讲述了js中confirm实现执行操作前弹出确认框的方法.分享给大家供大家参考.具体实现方法如下: 现在在删除或其它操作前弹出确定提示,我们有很多方法,最基本的就是利用js自带的函数confirm来操作了 最简单的用法如下: 鼠标事件使用confirm 复制代码 代码如下: <a href="#" onclick= "if(confirm( '是否确定! ')==false)r

使用showMessageDialog显示消息框

-----------------siwuxie095 工程名:TestJOptionPane 包名:com.siwuxie095.showdialog 类名:TestMessageDialog.java 工程结构目录如下: 代码: package com.siwuxie095.showdialog; import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.