3个回答
展开全部
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class C {
public static void main( String[] args ) {
JFrame f = new JFrame( );
f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
f.setSize( 300, 140 );
f.setLocation( 250, 250 );
Container c = f.getContentPane( );
c.setLayout( new FlowLayout( ) );
// JPasswordField
c.add( new JLabel( "Enter your password into this JPasswordField: " ) );
JPasswordField jpf = new JPasswordField( 10 );
jpf.addActionListener(
new ActionListener( ) {
public void actionPerformed( ActionEvent e ) {
Object pwd =
new String( ( ( JPasswordField ) e.getSource( ) ).getPassword( ) );
JOptionPane.showMessageDialog( null, "Your password is " + pwd );
}
}
);
c.add( jpf );
// TextField
c.add( new JLabel( "Or enter your password into this TextField: " ) );
TextField tf = new TextField( 12 );
tf.setEchoChar( '*' );
tf.addActionListener(
new ActionListener( ) {
public void actionPerformed( ActionEvent e ) {
Object pwd = ( ( ( TextField ) e.getSource( ) ).getText( ) );
JOptionPane.showMessageDialog( null, "Your password is " + pwd );
}
}
);
c.add( tf );
f.setVisible( true );
}
}
import java.awt.*;
import java.awt.event.*;
class C {
public static void main( String[] args ) {
JFrame f = new JFrame( );
f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
f.setSize( 300, 140 );
f.setLocation( 250, 250 );
Container c = f.getContentPane( );
c.setLayout( new FlowLayout( ) );
// JPasswordField
c.add( new JLabel( "Enter your password into this JPasswordField: " ) );
JPasswordField jpf = new JPasswordField( 10 );
jpf.addActionListener(
new ActionListener( ) {
public void actionPerformed( ActionEvent e ) {
Object pwd =
new String( ( ( JPasswordField ) e.getSource( ) ).getPassword( ) );
JOptionPane.showMessageDialog( null, "Your password is " + pwd );
}
}
);
c.add( jpf );
// TextField
c.add( new JLabel( "Or enter your password into this TextField: " ) );
TextField tf = new TextField( 12 );
tf.setEchoChar( '*' );
tf.addActionListener(
new ActionListener( ) {
public void actionPerformed( ActionEvent e ) {
Object pwd = ( ( ( TextField ) e.getSource( ) ).getText( ) );
JOptionPane.showMessageDialog( null, "Your password is " + pwd );
}
}
);
c.add( tf );
f.setVisible( true );
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
javax.swing下有个PasswordField类`这个就是提供密码筐的用法和TextFiled一样`文本是TextField 密码筐就是PasswordField简单好记`
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<input type="password" name="psd">
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询