import java.awt.*;
import java.awt.event.*;public class TFActionEvent {
public static void main(String[] args) {
new TFrame();
}
}class TFrame extends Frame {
TextField tf = new TextField();
//tf.setEchoChar('*');
TFrame() {
tf.setEchoChar('*');
tf.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.out.println(tf.getText());
tf.setText(" ");
}
}
);
add(tf);
pack();
setVisible(true);
}
}对于语句tf.setEchoChar('*'); ,为什么对于红色字体就会提示我 需要<标识符> 呢, 而写在TFrame构造方法里面就不会报错呢?
import java.awt.event.*;public class TFActionEvent {
public static void main(String[] args) {
new TFrame();
}
}class TFrame extends Frame {
TextField tf = new TextField();
//tf.setEchoChar('*');
TFrame() {
tf.setEchoChar('*');
tf.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.out.println(tf.getText());
tf.setText(" ");
}
}
);
add(tf);
pack();
setVisible(true);
}
}对于语句tf.setEchoChar('*'); ,为什么对于红色字体就会提示我 需要<标识符> 呢, 而写在TFrame构造方法里面就不会报错呢?
楼主【new_class】截止到2008-08-02 20:39:10的历史汇总数据(不包括此帖):
发帖的总数量:7 发帖的总分数:240 每贴平均分数:34
回帖的总数量:10 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:0 结贴的总分数:0
无满意结贴数:0 无满意结贴分:0
未结的帖子数:7 未结的总分数:240
结贴的百分比:0.00 % 结分的百分比:0.00 %
无满意结贴率:---------------------无满意结分率:---------------------
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
取消马甲机器人,请点这里:http://www.java2000.net/mycsdn/robotStop.jsp?usern=new_class
----------------------------
ps:在swing中有JPasswordField类,这个类有void setEchoChar(char c)方法.功能与TextField中该方法一致.