import
java.awt.event.*;
import
java.awt.*;
import
javax.swing.*;
class
text
extends
JFrame
implements
ActionListener, FocusListener {
static
JTextField t;
static
JPasswordField pass;
static
JFrame f;
static
JButton b;
static
JLabel l;
text()
{
}
public
static
void
main(String[] args)
{
f =
new
JFrame(
"textfield"
);
l =
new
JLabel(
"nothing entered"
);
b =
new
JButton(
"submit"
);
text te =
new
text();
b.addActionListener(te);
t =
new
JTextField(
"enter name"
,
16
);
pass =
new
JPasswordField(
16
);
pass.addFocusListener(te);
pass.setEchoChar((
char
)
0
);
pass.setText(
"enter password"
);
Font fo =
new
Font(
"Serif"
, Font.ITALIC,
20
);
t.setFont(fo);
JPanel p =
new
JPanel();
p.add(t);
p.add(pass);
p.add(b);
p.add(l);
f.add(p);
f.setSize(
300
,
300
);
f.show();
}
boolean
flag =
true
;
public
void
focusGained(FocusEvent e)
{
if
(flag) {
pass.setEchoChar(
'*'
);
pass.setText(
""
);
flag =
false
;
}
}
public
void
focusLost(FocusEvent e)
{
}
public
void
actionPerformed(ActionEvent e)
{
String s = e.getActionCommand();
if
(s.equals(
"submit"
)) {
l.setText(
"name = "
+ t.getText() +
"\t, Password = "
+ pass.getText());
t.setText(
" "
);
pass.setText(
""
);
}
}
}