import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class Border extends JFrame implements ActionListener{
JTextArea jTextArea;
JTextField jTextField;
Border(){
super("哈哈");
jTextField = new JTextField(12);
add(jTextField,BorderLayout.NORTH);
jTextField.addActionListener(this);
jTextArea = new JTextArea();
add(new JScrollPane(jTextArea),BorderLayout.CENTER);
setBounds(200, 200, 300, 400);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
Border border = new Border();
}
public void actionPerformed(ActionEvent e){
String string = jTextField.getText();
int n = JOptionPane.showConfirmDialog(this,"确认是否正确","确认对话框",
JOptionPane.YES_NO_OPTION );
if(n==JOptionPane.YES_OPTION) {
jTextArea.append("\n"+string);
jTextField.setText("");
}
else if(n==JOptionPane.NO_OPTION) {
jTextField.setText(null);
}
}
}
转载于:https://www.cnblogs.com/lgh1992314/archive/2013/01/14/5835215.html