在JFrame里面扩展此dialog类,覆盖其按钮方法即可
比如:我更新数据,弹出“是否确定更新”对话框,dialog如下:
package omt;
import javax.swing.*;
import java.awt.*;
import com.borland.jbcl.layout.*;
import javax.swing.border.*;
import java.awt.event.*;
/**
 * 作者:alphazhao
 * 日期:2002-5-29
 * 描述:确定修改时,弹出此确定窗口
 * */public class ShowUpdateMsg extends JDialog {
  private TitledBorder titledBorder1;
  private String strMsg;
private Font font14 = new Font("Dialog", 0, 14);
  private JPanel jPanel1 = new JPanel();
  private XYLayout xYLayout1 = new XYLayout();
  private JLabel jLabel1 = new JLabel();
  private JButton jButton1 = new JButton();
  private JButton jButton2 = new JButton();//  public ShowUpdateMsg(Frame owner, boolean modal) {
  public ShowUpdateMsg(Dialog owner, boolean modal) {
    super(owner,modal);
    try {
      this.setTitle("系统提示");
      this.setResizable(false);
//      this.setBackground(color);
      //NewLineMsg nlm = new NewLineMsg();
      //strMsg = nlm.newLineMsgWay(msg);//组织换行处理      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  private void jbInit() throws Exception {
    jPanel1.setLayout(xYLayout1);
    jLabel1.setFont(font14);
//    jLabel1.setForeground(colorTxt);
    jLabel1.setText("是否确定要修改此条记录?");//    jButton1.setBackground(color);
    jButton1.setFont(font14);
    //jButton1.setBorder(BorderFactory.createEtchedBorder());
    jButton1.setText("确  定");
    /*//
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton1_actionPerformed(e);
      }
    });
    //*///    jButton2.setBackground(color);
    jButton2.setFont(font14);
    //jButton2.setBorder(BorderFactory.createEtchedBorder());
    jButton2.setText("取  消");
    /*//
    jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton2_actionPerformed(e);
      }
    });
    //*/
    this.setSize(350,130);
//    jPanel1.setBackground(color);    this.getContentPane().add(jPanel1, BorderLayout.CENTER);
    jPanel1.add(jLabel1,    new XYConstraints(94, 22, 221, 35));
    jPanel1.add(jButton1, new XYConstraints(91, 65, 75, 25));
    jPanel1.add(jButton2, new XYConstraints(180, 65, 75, 25));    //Center the window
    CenterShowDialog csf = new CenterShowDialog(this);    ///
    SymListener symListener = new SymListener();
    jButton1.addActionListener(symListener);
    jButton2.addActionListener(symListener);
    //设置快捷键
    jButton1.registerKeyboardAction(symListener,
      KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
        JComponent.WHEN_IN_FOCUSED_WINDOW);
    //确定按钮为回车键"ENTER"
    jButton2.registerKeyboardAction(symListener,
      KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
        JComponent.WHEN_IN_FOCUSED_WINDOW);
    //取消按钮为退出键"Escape"
    //*/
  }  void jButton1_actionPerformed(ActionEvent e) {
    //调用时此方法须重写
    //this.dispose();
  }
  void jButton2_actionPerformed(ActionEvent e) {
    this.dispose();
  }  ///设置快捷键
  class SymListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
      Object obj = e.getSource();
      if (obj == jButton1) {
        jButton1_actionPerformed(e);
      }
      else if (obj == jButton2) {
        jButton2_actionPerformed(e);
      }
    }
  }
  //*/
}

解决方案 »

  1.   

    在JFrame里面,扩展此对话框如下(即写成inner class):
    private String backInfo;//按钮返回值
      public void youmethod() {
        //*****************
        //调用对话框
        backInfo = "NO";
        ShowUpdateMsgInfo sumi = new ShowUpdateMsgInfo(this, true);
        sumi.show();
        //System.out.println(backInfo);
        if (backInfo.equals("UPOK")) {
          //System.out.println("修改");
          ……
          //确定修改返回处理
        }
      }
      
      //显示确定修改事件处理
      class ShowUpdateMsgInfo extends ShowUpdateMsg{
        public ShowUpdateMsgInfo(Dialog owner, boolean modal) {
          super(owner, modal);
        }
        void jButton1_actionPerformed(ActionEvent e) {
          backInfo = "UPOK";//覆盖ok按钮事件,用于判断
          this.dispose();
        }
      }
    understand?
      

  2.   

    不好意思,对话框的代码没有去掉垃圾代码(曾改动过)
    改正:
    package omt;
    import javax.swing.*;
    import java.awt.*;
    import com.borland.jbcl.layout.*;
    import javax.swing.border.*;
    import java.awt.event.*;
    /**
     * 作者:alphazhao
     * 日期:2002-5-29
     * 描述:确定修改备注时,弹出此确定窗口
     * 其它:相关注释说明同ShowSelectByName.java
     * */public class ShowUpdateMsg extends JDialog {
      private TitledBorder titledBorder1;
      private String strMsg;
      private Font font14 = new Font("Dialog", 0, 14);
      private JPanel jPanel1 = new JPanel();
      private XYLayout xYLayout1 = new XYLayout();
      private JLabel jLabel1 = new JLabel();
      private JButton jButton1 = new JButton();
      private JButton jButton2 = new JButton();  public ShowUpdateMsg(Dialog owner, boolean modal) {
        super(owner,modal);
        try {
          this.setTitle("系统提示");
          this.setResizable(false);
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      private void jbInit() throws Exception {
        jPanel1.setLayout(xYLayout1);
        jLabel1.setFont(font14);
        jLabel1.setText("是否确定要修改此条记录?");    jButton1.setFont(font14);
        jButton1.setText("确  定");
        jButton2.setFont(font14);
        jButton2.setText("取  消");    this.setSize(350,130);
        this.getContentPane().add(jPanel1, BorderLayout.CENTER);
        jPanel1.add(jLabel1,    new XYConstraints(94, 22, 221, 35));
        jPanel1.add(jButton1, new XYConstraints(91, 65, 75, 25));
        jPanel1.add(jButton2, new XYConstraints(180, 65, 75, 25));
        //Center the window
        //CenterShowDialog csf = new CenterShowDialog(this);    SymListener symListener = new SymListener();
        jButton1.addActionListener(symListener);
        jButton2.addActionListener(symListener);
        //设置快捷键
        jButton1.registerKeyboardAction(symListener,
          KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);
        //确定按钮为回车键"ENTER"
        jButton2.registerKeyboardAction(symListener,
          KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);
        //取消按钮为退出键"Escape"
      }  void jButton1_actionPerformed(ActionEvent e) {
        //调用时此方法须重写
        //this.dispose();
      }
      void jButton2_actionPerformed(ActionEvent e) {
        this.dispose();
      }  ///设置快捷键
      class SymListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
          Object obj = e.getSource();
          if (obj == jButton1) {
            jButton1_actionPerformed(e);
          }
          else if (obj == jButton2) {
            jButton2_actionPerformed(e);
          }
        }
      }
    }
    //end
      

  3.   

    搞定了,谢谢alphazhao(绿色咖啡),不知道还有没有简单一点的方法。