JOptionPane.showConfirmDialog例…

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

public class jjfrom extends JFrame {
 
private static final long serialVersionUID = 1L;

public jjfrom() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getContentPane().add(new JLabel("Placeholder label"));
    pack();
    setSize(200, 200);
    setVisible(true);

    int replaced = JOptionPane.showConfirmDialog(this,
        "Replace existing selection?");

    String result = "?";
    switch (replaced) {
    case JOptionPane.CANCEL_OPTION:
      result = "Canceled";
      break;
    case JOptionPane.CLOSED_OPTION:
      result = "Closed";
      break;
    case JOptionPane.NO_OPTION:
      result = "No";
      break;
    case JOptionPane.YES_OPTION:
      result = "Yes";
      break;
    default:
      ;
    }
    System.out.println("Replace? " + result);
  }

  public static void main(String[] args) {
    new jjfrom();
  }
}

你可能感兴趣的:(JAVA)