JOptionPane.showConfirmDialog(null, "error reading file.", "File input error", JOptionPane.YES_NO_CANCEL_OPTION, ERROR);像这个怎么用进一个类里面去啊?

解决方案 »

  1.   

    我来给你说说吧!
    举个例子你就知道了
       import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;public class net extends JFrame implements ActionListener { JButton confirm;
    public net()
    {
    Container con=this.getContentPane();
    con.setLayout(new FlowLayout());
    confirm=new JButton("弹出确认对话框");
    confirm.addActionListener(this);
    this.setBounds(10,10,200,200);
    this.setVisible(true);
    con.add(confirm);
    con.validate();
    this.validate();
    this.addWindowListener(new WindowAdapter()
    {
    public void windowClosing(WindowEvent e)
    {
    System.exit(0);
    }
    });
    }
    @Override
    public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub if(e.getSource()==confirm)
    {
    JOptionPane.showConfirmDialog(null, "error reading f" +
    "ile.", "File input error", JOptionPane.YES_NO_CANCEL_OPTION);

    }
    } /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub net ss=new net();
    }}
    请注意,你是理解错误了,确认对话框并没有你定的那种类型,即JOptionPane.YES_NO_CANCEL_OPTION, error只要册除后那个error就行了,我这个代码是完整的,你测试一下看看!
        
      

  2.   

    int r = JOptionPane.showConfirmDialog(null, "确认操作?", "请确认",JOptionPane.YES_NO_CANCEL_OPTION);
    选择不同的结果,返回值不一样,可以读JOptionPane的常量来进行判断就可以了