yesnodemo.java

来自「Java学习源代码检索系统免费版」· Java 代码 · 共 58 行

JAVA
58
字号
//==============================================================
// YesNoDemo.java - Demonstrate confirmation dialogs
//
// Java学习源代码检索系统 Ver 1.0 20031015 免费正式版
// 版权所有: 中国IT认证实验室(www.ChinaITLab.com)
// 程序制作: ChinaITLab网校教研中心
// 主页地址: www.ChinaITLab.com    中国IT认证实验室
// 论坛地址: bbs.chinaitlab.com  
// 电子邮件: Java@ChinaITLab.com
//==============================================================

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class YesNoDemo extends JFrame {

// Constructor does all the setup work
 public YesNoDemo() {

  // Select local system look and feel
  try {
   UIManager.setLookAndFeel(
    UIManager.getSystemLookAndFeelClassName());
  } catch (Exception e) { }

  // End program when window closes
  addWindowListener(new WindowAdapter() {
   public void windowClosing(WindowEvent e) {
    System.exit(0);
   }
  });

  JButton optionButton = new JButton("Click Me!");
  optionButton.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent e) {
    int result = 
     JOptionPane.showConfirmDialog(null,
      "Exit this program now?",
      "Please answer",
      JOptionPane.YES_NO_OPTION);
    if (result == JOptionPane.YES_OPTION)
     System.exit(0);
   }   
  });

  Container content = getContentPane();
  content.add(optionButton);
 }

 public static void main(String[] args) {
  YesNoDemo app = new YesNoDemo();
  app.setTitle("Confirm Dialog Demonstration");
  app.setSize(320, 240);
  app.show();
 }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?