首页javajoptionpaneJava Swing - 如何覆盖JOptionPane操作事件值

Java Swing - 如何覆盖JOptionPane操作事件值

我们想知道如何覆盖JOptionPane操作事件值。
import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

public class Main {
  public static void main(String[] args) {
    final JFrame frame = new JFrame();
    JOptionPane pane = new JOptionPane("Some message",
        JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION) {
      @Override
      public void setValue(Object newValue) {
        super.setValue(newValue);
        JOptionPane.showMessageDialog(frame.getContentPane(), "You have hit "
            + newValue);
      }
    };
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(new JLabel("Some panel in the middle"), BorderLayout.CENTER);
    frame.add(pane, BorderLayout.SOUTH);
    frame.pack();
    frame.setVisible(true);
  }
}