import javax.swing.*; 
import java.awt.event.*;
class Win extends JFrame implements ActionListener{
    JTextField jTextField1;
    JTextArea jTextArea1; public Win(){
        setLayout(null);
        setTitle("确认对话框应用");
        jTextField1 = new JTextField();
        jTextArea1 = new JTextArea();
        jTextArea1.setBounds(25, 84, 137, 54);
        jTextField1.setBounds(26, 33, 135, 26);
        jTextField1.addActionListener(this);
        add(jTextField1);
        add(jTextArea1);
        setBounds(200, 300, 250, 200);
        validate();
        setVisible(true);
    }
    public void actionPerformed(ActionEvent e){
       String s = jTextField1.getText();
       int n = JOptionPane.showConfirmDialog(this, "确认正确吗 ", "确认对话框",JOptionPane.YES_NO_OPTION);
       if (n == JOptionPane.YES_OPTION){
           jTextArea1.append("\n" + s);
       } 
       else if (n == JOptionPane.NO_OPTION){
           jTextField1.setText(null);
       }
    }
}
class JOptionPane_Test{
    public static void main(String args[]){
       Win ta = new Win(); 
    }
}

