下面列出了java.awt.TextField#setEchoChar ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public LoginRequester(Frame parent, String title, String user_label, String password_label,
String posText_, String negText) {
super(parent, title, true);
setLayout(new GridBagLayout());
posText = posText_;
add(new Label(user_label), Awt.constraints(false, GridBagConstraints.HORIZONTAL));
u_text = new TextField(30);
try{u_text.setText(System.getProperty("user.name",""));}
catch(Exception e) {}
add(u_text, Awt.constraints(true, GridBagConstraints.HORIZONTAL));
add(new Label(password_label), Awt.constraints(false, GridBagConstraints.HORIZONTAL));
p_text = new TextField(30);
p_text.setEchoChar('*');
add(p_text, Awt.constraints(true, GridBagConstraints.HORIZONTAL));
Button pos = new Button(posText);
add(pos, Awt.constraints(false, 10, 4, GridBagConstraints.HORIZONTAL));
pos.addActionListener(this);
Button neg = new Button(negText);
add(neg, Awt.constraints(true, 10, 4, GridBagConstraints.HORIZONTAL));
neg.addActionListener(this);
pack();
}
public LoginGUI(){
// set title
super("EventHandling basics");
txtF1 = new TextField();
passF = new TextField();
label1 = new Label();
label2 = new Label();
panelLogin = new Panel();
buttonExit = new Button("close");
buttonLogin = new Button("login");
// explictely setting layout. default is Flow itself
setLayout(new FlowLayout());
// create a label for username
label1.setAlignment(Label.CENTER);
label1.setText("Username");
add(label1); // add the label to the Frame
// set initial width of the the TextFields
txtF1.setColumns(20);
passF.setColumns(20);
// changing echoing of characters typed in password field into *
passF.setEchoChar('*');
add(txtF1);
// create a label for password
label2.setAlignment(Label.CENTER);
label2.setText("Password");
add(label2);
add(passF);
// create an exit button
add(buttonExit);
// login button
panelLogin.add(buttonLogin);
add(panelLogin);
// create an listener object.
theHandler handler = new theHandler();
// add action listeners for both the buttons
buttonExit.addActionListener(handler);
buttonLogin.addActionListener(handler);
}