JOptionPane.showConfirmDialog例…

来源:互联网 发布:电脑内存优化软件 编辑:程序博客网 时间:2024/06/01 18:10
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(newJLabel("Placeholder label"));
    pack();
    setSize(200, 200);
    setVisible(true);

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

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

  public static void main(String[] args){
    new jjfrom();
  }
}
0 0
原创粉丝点击