首页javajoptionpaneJava Swing - 如何将特定操作分配给JOptionPane.showInputDialog中的“取消”按钮

Java Swing - 如何将特定操作分配给JOptionPane.showInputDialog中的“取消”按钮

我们想知道如何将特定操作分配给JOptionPane.showInputDialog中的“取消”按钮。
import java.text.ParseException;

import javax.swing.JOptionPane;

public class Main {

  public static void main(String[] args) throws ParseException {
    String input = JOptionPane.showInputDialog("Enter Input:");
    if (input == null) {
      System.out.println("Calcel pressed");
    } else {
      System.out.println("OK pressed");
    }

  }
}