请高手给个源码 谢谢
就是点击退出 按钮 出现“提示:确认 取消”对话框
单击确认 实现退出我不知道这个事件的监听应该怎么写 还有怎么把确认事件与退出按钮联系到一起 呵呵
谢谢高手 给个源码 我自己看

解决方案 »

  1.   

    sizeDialog.dispose()不就实现了退出吗?
    --------------->
     public void actionPerformed(ActionEvent e) {
            sizeDialog.setVisible(false);
            sizeDialog.dispose();
          }
      

  2.   

    这是我做项目的时候自己写的一个类,你可以拿过去参考一下....
    (你点某一按纽的时候,直接new一个对话框就是的)
    package view.dialog;import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;import javax.swing.ButtonGroup;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JRadioButton;import view.com.CenterDialog;
    import view.frame.MainFrame;
    import action.implementclass.dialogaction.FaceSizeDialogActionImp;/**
     * 设定大小对话框
     * @author linfeng
     *
     */
    public class FaceSizeDialog extends JDialog {  /**
       * sizeDialog 大小对话框
       * bg 按钮组
       * extra_large 超大单选按钮
       * large 大单选按钮
       * medium 中单选按钮
       * small 小单选按钮
       * ok 确定按钮
       * cancel 取消按钮
       * topPanel 上面板
       * bottomPanel 下面板
       * bl 边界布局
       */
      public static JDialog sizeDialog;
      private ButtonGroup bg;
      public static JRadioButton extra_large, large, medium, small;
      private JButton ok, cancel;
      private JPanel topPanel, bottomPanel;
      private BorderLayout bl;  public FaceSizeDialog() {    sizeDialog = new JDialog();
        //设定对话框大小
        sizeDialog.setSize(400, 150);
        //让对话框居中显示
        sizeDialog = new CenterDialog().getCenterDialog(sizeDialog, true);
        sizeDialog.setTitle("大小设置");
        getTopPanel();
        getBottomPanel();
        bl = new BorderLayout();
        sizeDialog.add(new JLabel("请选择界面大小:"), bl.NORTH);
        sizeDialog.add(topPanel, bl.CENTER);
        sizeDialog.add(bottomPanel, bl.SOUTH);
        sizeDialog.setVisible(true);
      }  public void getTopPanel() {
        topPanel = new JPanel();
        bg = new ButtonGroup();
        extra_large = new JRadioButton("1024*768(默认)", true);
        large = new JRadioButton("800*600", false);
        medium = new JRadioButton("600*400", false);
        small = new JRadioButton("400*300", false);
        topPanel.setLayout(new FlowLayout());
        bg.add(extra_large);
        bg.add(large);
        bg.add(medium);
        bg.add(small);
        topPanel.add(extra_large);
        topPanel.add(large);
        topPanel.add(medium);
        topPanel.add(small);
      }  public void getBottomPanel() {
        bottomPanel = new JPanel();
        ok = new JButton("确定");
        cancel = new JButton("取消");
        bottomPanel.setLayout(new FlowLayout());
        bottomPanel.add(ok);
        bottomPanel.add(cancel);    ok.addActionListener(new FaceSizeDialogActionImp());    cancel.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            sizeDialog.setVisible(false);
            sizeDialog.dispose();
          }
        });
      }
    }
      

  3.   

    看下面这段代码吧:***.addMouseListener(new MouseAdapter() {             
    public void mouseClicked(MouseEvent evt) {
          int value = 0;    //默认不弹出提示
          
           value=JOptionPane.showConfirmDialog(null, "您确定要退出吗?", "提示信息!",JOptionPane.YES_NO_OPTION);
                 //0为确定,1为取消
                 if (value==0)
                 {
                    //点击确定将做的操作
                      yourDialog.dispose();
                 }
                 if (value==1)
                 {
                    //点击取消将做的操作----nothing now.
                 }
            }
        });其中***为要加入这个动作侦听的元件,比如按钮;
    yourDialog为你要关闭的那个视窗