intsql resulttype 是int=JOptionPane.showConfirmDialog(null, "是否退出系统"); System.out.println(result);问题

Access denied |
used Cloudflare to restrict access
Please enable cookies.
What happened?
The owner of this website () has banned your access based on your browser's signature (3b4c76ac-ua98).JOptionPane对话框的一些返回值
确认对话框ConfirmDialog给出提示信息和若干个按钮供用户选择,共有4个showConfirmDialog重载方法。对话框的按钮通常为:“是”、“否”、“取消”和“确认”及组合,showConfirmDialog()方法的返回值为整型常量,当按下一个按钮时,返回相应的整型常量,“是”、“否”、“取消”和“确认”对应的常量分别是:0、1、2、0,当按下对话框的“关闭按钮”关闭对话框时,返回值是:-1。
1.&&showConfirmDialog(Component&parentComponent,
Object&message);
这个方法由参数“Object&message”给出提示信息,按钮为默认的“是”、“否”和“取消”。
n=JOptionPane.showConfirmDialog(null, "提示信息");
2.showConfirmDialog(Component
parentComponent, Object message, String title, int
optionType);
optionType”确定了按钮的定制,具体取值是:
DEFAULT_OPTION
//“确定”按钮
YES_NO_OPTION
//&“是”、“否”按钮
YES_NO_CANCEL_OPTION
//“是”、“否”、“取消”按钮
OK_CANCEL_OPTION
//“确定”、“取消”按钮
参数“Object
message”给出提示信息,参数“String title”给出对话框标题。
n=JOptionPane.showConfirmDialog(null,
"提示信息","标题",JOptionPane.DEFAULT_OPTION);
只有一个“确定”选择,选中后返回值是0。
n=JOptionPane.showConfirmDialog(null,
"提示信息","标题",JOptionPane.YES_NO_OPTION);
选中“是”返回0,选中“否”返回1。
n=JOptionPane.showConfirmDialog(null,
"提示信息","标题",JOptionPane.YES_NO_CANCEL_OPTION);
返回值:“是”:0,“否”:1,“取消”:2&。
n=JOptionPane.showConfirmDialog(null,
"提示信息","标题",JOptionPane.OK_CANCEL_OPTION);
返回值:“确定”:0,“取消”:2&。
3.showConfirmDialog(Component
parentComponent, Object message, String title, int optionType, int
messageType);
这个方法增加了一个图标类型的参数“int
messageType”,具体取值是:
ERROR_MESSAGE
INFORMATION_MESSAGE
WARNING_MESSAGE
QUESTION_MESSAGE(默认类型)
PLAIN_MESSAGE(无图标)
具体应用可参考消息对话框的实例。
n=JOptionPane.showConfirmDialog(null,"提示信息","标题",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.
INFORMATION_MESSAGE);
4. showConfirmDialog(Component
parentComponent, Object message, String title, int optionType, int
messageType, Icon icon);
这个方法增加了一个参数“Icon
icon”,通过该参数,用户可以把自己的图标添加到对话框中;
Icon icon=new
ImageIcon("grapes.gif");
n=JOptionPane.showConfirmDialog(null,"提示信息","标题",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.
INFORMATION_MESSAGEicon);
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。在JFrame中,窗体右上角的小红叉默认点击就是关闭窗体,如果frame窗体和showConfirmDialog对话框创建一个联系:
& &当点击frame小红叉时,弹出对话框(是否关闭窗口?),点击对话框按钮后,对话框关闭,而frame不关闭!
& &就是在当前窗口的构造函数添加一句话:
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);代码如下:
1 package T
3 import java.awt.event.WindowA
4 import java.awt.event.WindowE
5 import javax.swing.JF
6 import javax.swing.JOptionP
8 public class Demo {
private JF
<span style="color: #
<span style="color: #
public static void main(String[] args) {
<span style="color: #
Demo window = new Demo();
<span style="color: #
window.frame.addWindowListener(new WindowAdapter() {
<span style="color: #
public void windowClosing(WindowEvent e) {
<span style="color: #
int i= JOptionPane.showConfirmDialog(null, "确认退出吗?");
<span style="color: #
if(i==JOptionPane.OK_OPTION){
<span style="color: #
System.exit(0);
<span style="color: #
<span style="color: #
<span style="color: #
<span style="color: #
<span style="color: #
<span style="color: #
<span style="color: #
<span style="color: #
public Demo() {
<span style="color: #
initialize();
<span style="color: #
<span style="color: #
<span style="color: #
private void initialize() {
<span style="color: #
frame = new JFrame();
<span style="color: #
frame.setBounds(100, 100, 450, 300);
<span style="color: #
// frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//默认点击关闭
<span style="color: #
frame.setVisible(true);
<span style="color: #
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
<span style="color: #
<span style="color: # }
& & 截图如下:
阅读(...) 评论()showConfirmDialog() - Displaying Confirmation Dialog Boxes
showConfirmDialog() - Displaying Confirmation Dialog Boxes
This section provides a tutorial example on how to use the static method, showConfirmDialog(), to create and display confirmation dialog boxes for 3 different types of options and 4 different types of messages: information, warning, error, and plain.
The second type of dialog boxes you can create and display with the javax.swing.JOptionPane class is the confirmation dialog box.
This can be done with the static method: showConfirmDialog(frame, message, title, option, type), where:
"frame" is a frame object to be used as the parent frame.
"message" is the message string to be display on the dialog box.
"title" is the title string to be used as the dialog box title.
"option" is an integer code representing a specific confirmation option type. Valid type codes are predefined
as constants in the JOptionPane class: YES_NO_OPTION, YES_NO_CANCEL_OPTION, and OK_CANCEL_OPTION.
"type" is an integer code representing a specific message dialog box type. Valid type codes are predefined
as constants in the JOptionPane class: INFORMATION_MESSAGE, WARNING_MESSAGE, ERROR_MESSAGE and PLAIN_MESSAGE.
Here is an example program I wrote to test the showConfirmDialog() method:
/* JOptionPaneShowConfirmDialog.java
* Copyright (c) 2014, , All Rights Reserved.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class JOptionPaneShowConfirmDialog implements ActionListener {
JFrame myFrame =
int optionType = JOptionPane.YES_NO_OPTION;
int messageType = RMATION_MESSAGE;
public static void main(String[] a) {
(new JOptionPaneShowConfirmDialog()).test();
private void test() {
myFrame = new JFrame("showConfirmDialog() Test");
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container myPane = myFrame.getContentPane();
myPane.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
setMyConstraints(c,0,0,GridBagConstraints.CENTER);
myPane.add(getFieldPanel(),c);
setMyConstraints(c,0,1,GridBagConstraints.CENTER);
myPane.add(getButtonPanel(),c);
myFrame.pack();
myFrame.setVisible(true);
private JPanel getFieldPanel() {
JPanel p = new JPanel(new GridBagLayout());
p.setBorder(BorderFactory.createTitledBorder("Settings"));
GridBagConstraints c = new GridBagConstraints();
setMyConstraints(c,0,0,GridBagConstraints.EAST);
p.add(new JLabel("Option Type:"),c);
setMyConstraints(c,1,0,GridBagConstraints.WEST);
p.add(getOptionPanel(),c);
setMyConstraints(c,0,1,GridBagConstraints.EAST);
p.add(new JLabel("Message type:"),c);
setMyConstraints(c,1,1,GridBagConstraints.WEST);
p.add(getMessagePanel(),c);
private JPanel getOptionPanel() {
JPanel myPanel = new JPanel(new GridBagLayout());
ButtonGroup myGroup = new ButtonGroup();
JRadioButton myButton = new JRadioButton("Yes-No",true);
myButton.addActionListener(this);
myGroup.add(myButton);
myPanel.add(myButton);
myButton = new JRadioButton("Yes-No-Cancel",false);
myButton.addActionListener(this);
myGroup.add(myButton);
myPanel.add(myButton);
myButton = new JRadioButton("Ok-Cancel",false);
myButton.addActionListener(this);
myGroup.add(myButton);
myPanel.add(myButton);
return myP
private JPanel getMessagePanel() {
JPanel myPanel = new JPanel(new GridBagLayout());
ButtonGroup myGroup = new ButtonGroup();
JRadioButton myButton = new JRadioButton("Information",true);
myButton.addActionListener(this);
myGroup.add(myButton);
myPanel.add(myButton);
myButton = new JRadioButton("Warning",false);
myButton.addActionListener(this);
myGroup.add(myButton);
myPanel.add(myButton);
myButton = new JRadioButton("Error",false);
myButton.addActionListener(this);
myGroup.add(myButton);
myPanel.add(myButton);
myButton = new JRadioButton("Plain",false);
myButton.addActionListener(this);
myGroup.add(myButton);
myPanel.add(myButton);
return myP
private JPanel getButtonPanel() {
JPanel p = new JPanel(new GridBagLayout());
JButton myButton = new JButton("Show");
myButton.addActionListener(this);
p.add(myButton);
public void actionPerformed(ActionEvent e) {
String cmd = ((AbstractButton) e.getSource()).getText();
System.out.println("Button clicked: "+cmd);
if (cmd.equals("Information")) {
messageType = RMATION_MESSAGE;
} else if (cmd.equals("Warning")) {
messageType = JOptionPane.WARNING_MESSAGE;
} else if (cmd.equals("Error")) {
messageType = JOptionPane.ERROR_MESSAGE;
} else if (cmd.equals("Plain")) {
messageType = JOptionPane.PLAIN_MESSAGE;
} else if (cmd.equals("Yes-No")) {
optionType = JOptionPane.YES_NO_OPTION;
} else if (cmd.equals("Yes-No-Cancel")) {
optionType = JOptionPane.YES_NO_CANCEL_OPTION;
} else if (cmd.equals("Ok-Cancel")) {
optionType = JOptionPane.OK_CANCEL_OPTION;
} else if (cmd.equals("Show")) {
JOptionPane.showConfirmDialog(myFrame,
"Confirmation dialog box text message.",
"Confirmation Dialog Box", optionType, messageType);
private void setMyConstraints(GridBagConstraints c,
int gridx, int gridy, int anchor) {
c.anchor =
If you run this example, select an option type and a message type,
then click the "Show" button,
you will see a confirmation dialog box showing up like this:
Interesting notes about this tutorial example:
I used several panels and layouts to organize the settings area.
An action listener has been added to all radio buttons and the "Show" button.
The actionPerformed() method in the action listener is implemented to handle all changes.
What is missing in this example is how to catch input on option buttons on the confirmation dialog box.
Sample programs listed in this section have been tested with JDK 1.6.0 to 1.8.0.
Last update: 2014.
Table of Contentsjava swing标准对话框具体实现
这篇文章介绍了swing标准对话框的具体实现方法,有需要的朋友可以参考一下
package test001;
import java.awt.event.ActionE
import java.awt.event.ActionL
import javax.swing.JB
import javax.swing.JF
import javax.swing.JOptionP
import javax.swing.JToolB
public class TestJOptionPane implements ActionListener{
private JFrame jf = new JFrame("标准对话框测试");
* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub
new TestJOptionPane().createUI();
public void createUI(){
JToolBar jtb = new JToolBar();
String[] s = {"错误", "退出确认1", "退出确认2", "警告", "输入", "选择"};
int size = s.
JButton[] button = new JButton[size];
for(int i = 0; i & i++){
button[i] = new JButton(s[i]);
button[i].addActionListener(this);
jtb.add(button[i]);
jf.add(jtb, "North");
jf.setSize(350, 150);
jf.setLocation(400, 200);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String s = e.getActionCommand();
if(s.equals("错误")){
JOptionPane.showMessageDialog(null, "要显示的错误信息---",
"错误提示",JOptionPane.ERROR_MESSAGE);
else if(s.equals("退出确认1")){
int result = JOptionPane.showConfirmDialog(null,
"推出前是否保存程序?");
if(result == JOptionPane.YES_OPTION){
System.out.println("保存程序---");
System.exit(0);
else if(result == JOptionPane.NO_OPTION){
System.exit(0);
else if(s.equals("退出确认2")){
int result = JOptionPane.showConfirmDialog(null, "退出前是否保存程序?");
if(result == JOptionPane.YES_OPTION){
System.out.println("保存程序---");
System.exit(0);
else if(result == JOptionPane.NO_OPTION){
System.exit(0);
else if(s.equals("警告")){
Object[] options = {"继续", "撤销"};
int result = JOptionPane.showOptionDialog(null,
"本操作可能导致数据丢失","Warning", JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE, null, options, options[0]);
if(result == 0){
System.out.println("继续操作---");
else if(s.equals("输入")){
String name = JOptionPane.showInputDialog("请输入您的姓名:");
if(name != null){
System.out.println("姓名:" + name);
else if(s.equals("选择")){
Object[] possibleValues = {"体育", "政治", "经济", "文化"};
Object selectedValue = JOptionPane.showInputDialog(null,
"Choose one","Input", RMATION_MESSAGE, null,
possibleValues, possibleValues[0]);
String choose = (String)selectedV
if(choose != null){
System.out.println("你选择的是:"+ choose);
Copyright (C) , All Rights Reserved.
版权所有 闽ICP备号
processed in 0.045 (s). 12 q(s)

我要回帖

更多关于 resulttype int 的文章

 

随机推荐