为什么这个"重置"的按钮事件无法响应啊??
----------------解决方案--------------------------------------------------------
自己顶!
----------------解决方案--------------------------------------------------------
还没有人?再顶!
----------------解决方案--------------------------------------------------------
你应该把你的代码帖出来,还有,不要用JB自己生成代码的功能,
所有事件处理应该自己心里清楚.并且自己为之编码
----------------解决方案--------------------------------------------------------
我在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());
}
}
----------------解决方案--------------------------------------------------------
不是吧!斑竹看一下啊!
----------------解决方案--------------------------------------------------------
写的太多了吧,不用导入那么多包。
用记事本写,JB弄的东西太多
----------------解决方案--------------------------------------------------------
不是吧!我上面重写的代码是用JC写的啊!这个还乱吗?
----------------解决方案--------------------------------------------------------
我在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());
}
}
像你这种代码风格比较差
还有,你想要实现什么功能,我写个简单的给你看看
----------------解决方案--------------------------------------------------------
啊!是这样啊!我只是想实现点"重置"按钮后jTextField1和jTextField2里的内容清空!这个事件我会实现,只是想用这种方法试试!看样子是不行啊!不过冰封可以告诉我为什么这么写点击按钮后会没有反应吗?
----------------解决方案--------------------------------------------------------