我在JC下重写了代码,就是不知道这个"重置"的按钮的功能为什么不能实现!
代码如下:
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Frame1 extends JFrame {
JPanel contentPane;
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JTextField jTextField1 = new JTextField();
JTextField jTextField2 = new JTextField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
public Frame1() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(400, 300));
setTitle("Frame Title");
jLabel1.setText("姓名:");
jLabel1.setBounds(new Rectangle(21, 41, 83, 32));
jLabel2.setText("年龄:");
jLabel2.setBounds(new Rectangle(19, 118, 78, 36));
jTextField1.setBounds(new Rectangle(178, 41, 109, 31));
jTextField2.setBounds(new Rectangle(178, 118, 108, 35));
jButton1.setBounds(new Rectangle(61, 224, 109, 43));
jButton1.setText("确定");
jButton2.setBounds(new Rectangle(216, 226, 109, 40));
jButton2.setText("重置");
jButton2.addActionListener(new jbt());
contentPane.add(jLabel1);
contentPane.add(jLabel2);
contentPane.add(jTextField1);
contentPane.add(jTextField2);
contentPane.add(jButton1);
contentPane.add(jButton2);
}
class jbt implements ActionListener{
public void actionPerformed(ActionEvent e) {
Replace replace =new Replace();
replace.re();
}
}
public static void main(String [] args){
Frame1 frame1=new Frame1();
frame1.setVisible(true);
}
}
import javax.swing.text.*;
public class Replace {
public Replace() {
}
public void re(){
Frame1 frame1=new Frame1();
frame1.jTextField1.setDocument(new PlainDocument());
frame1.jTextField2.setDocument(new PlainDocument());
}
}