manualdisplaypopup.java

来自「The Definitive Guide to Java Swing, Thir」· Java 代码 · 共 32 行

JAVA
32
字号
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class ManualDisplayPopup {
  public static void main(String args[]) {
    Runnable runner = new Runnable() {
      public void run() {

        JFrame frame = new JFrame("NoButton Popup");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JButton button = new JButton ("Ask");
        ActionListener actionListener = new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            Component source = (Component)actionEvent.getSource();
            JOptionPane optionPane = new JOptionPane("Continue printing?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
            JDialog dialog = optionPane.createDialog(source, "Manual Creation");
            dialog.setVisible(true);
            int selection = OptionPaneUtils.getSelection(optionPane);
            System.out.println (selection);
          }
        };
        button.addActionListener(actionListener);
        frame.add(button, BorderLayout.SOUTH);
        frame.setSize(300, 200);
        frame.setVisible(true);
      }
    };
    EventQueue.invokeLater(runner);
  }
}

⌨️ 快捷键说明

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