突然写了些Swing方面的代码。很郁闷,有些方法“名不副实”啊!先看代码片段:
loginView.java中的代码片段private JTextField txtName;
private JPasswordField pfPswd;... ...public final void addListener(){
LoginHandler handler = new LoginHandler(this);
bttnOK.addActionListener(
EventHandler.create(ActionListener.class, handler, "checUser", "")
);
bttnReset.addActionListener(
EventHandler.create(ActionListener.class, handler, "resetMessage", "")
);
}... ...
public final JTextField getTxtName() {
return txtName;
}
public final JPasswordField getPfPswd() {
return pfPswd;
}LoginHandler.java中的代码块,LoginHandler类resetMessage方法用来处理View中2个文本TxtName和PfPswd的清空.
[code=Java]public void resetMessage(ActionEvent event){
loginView.getTxtName().setText("");
loginView.getPfPswd().setText("");
}
问题:
在这里使用setText("")是没有效果的。同样使用seletAll()方法选中所有文本也是没有效果的。
loginView.java中的代码片段private JTextField txtName;
private JPasswordField pfPswd;... ...public final void addListener(){
LoginHandler handler = new LoginHandler(this);
bttnOK.addActionListener(
EventHandler.create(ActionListener.class, handler, "checUser", "")
);
bttnReset.addActionListener(
EventHandler.create(ActionListener.class, handler, "resetMessage", "")
);
}... ...
public final JTextField getTxtName() {
return txtName;
}
public final JPasswordField getPfPswd() {
return pfPswd;
}LoginHandler.java中的代码块,LoginHandler类resetMessage方法用来处理View中2个文本TxtName和PfPswd的清空.
[code=Java]public void resetMessage(ActionEvent event){
loginView.getTxtName().setText("");
loginView.getPfPswd().setText("");
}
问题:
在这里使用setText("")是没有效果的。同样使用seletAll()方法选中所有文本也是没有效果的。
楼主【qfs_v】截止到2008-07-27 00:10:58的历史汇总数据(不包括此帖):
发帖的总数量:15 发帖的总分数:210 每贴平均分数:14
回帖的总数量:210 得分贴总数量:81 回帖的得分率:38%
结贴的总数量:14 结贴的总分数:190
无满意结贴数:0 无满意结贴分:0
未结的帖子数:1 未结的总分数:20
结贴的百分比:93.33 % 结分的百分比:90.48 %
无满意结贴率:0.00 % 无满意结分率:0.00 %
值得尊敬
我的代码是这样的//窗口类 GU.java
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.beans.EventHandler;public class GU extends JFrame
{
private JTextField jtx ;
private JPasswordField pwd;
private JButton restB ;
public GU()
{
setSize(300,300);
setLayout(new GridLayout(3,1));
jtx = new JTextField("MMMMMMMMMMMMMMMMMM");
pwd = new JPasswordField("****************");
restB = new JButton("Reset");
Test handler = new Test(this);
restB.addActionListener( (ActionListener)EventHandler.create(ActionListener.class, handler, "ResetMessage", ""));
add(jtx);
add(pwd);
add(restB);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} public final JTextField getTxtName()
{
return jtx;
}
public final JPasswordField getPfPswd()
{
return pwd;
}
public static void main(String args[])
{
GU gu = new GU();
}
}
//事件处理类 Test.java
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Test
{
GU gu ;
public Test(GU gu)
{
this.gu = gu;
}
public void ResetMessage(ActionEvent event)
{
(gu.getTxtName()).setText("");
(gu.getPfPswd()).setText("");
}
}
private JTextField txtName = new JTextField(15);
private JPasswordField pfPswd = new JPasswordField(15);... ...public final void addListener(){
LoginHandler handler = new LoginHandler(this);
bttnOK.addActionListener(
EventHandler.create(ActionListener.class, handler, "checUser", "")
);
bttnReset.addActionListener(
EventHandler.create(ActionListener.class, handler, "resetMessage", "")
);
}... ...
public final void clearTxtName() {
txtName.setText("");
}
public final void clearPfPswd() {
pfPswd.setText("");
}LoginHandler.java中的代码块,LoginHandler类resetMessage方法用来处理View中2个文本TxtName和PfPswd的清空.
[code=Java]public void resetMessage(ActionEvent event){
loginView.clearTxtName;
loginView.clearPfPswd();
}