想在输入密码时用*键来代替,要怎么做,求大神帮忙
JPasswordField jpf=new JPasswordField();输入的显示为*
在接收的时候,要转成String ,转换方法. String passwd= new String(jpf.getPassword())
可以给我发一下具体执行的代码吗,我弄的还是不对。
@遮天-斩天:
import javax.swing.*; public class demo1 extends JFrame{ JFrame frame ; JPanel panel; JLabel label_name; JLabel label_pass; JTextField nameField; JPasswordField passField; public demo1(){ frame = new JFrame(); panel = new JPanel(); label_name = new JLabel("用户名"); label_pass = new JLabel("密码 "); nameField = new JTextField("name "); passField = new JPasswordField("pass "); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 400); frame.setVisible(true); frame.add(panel); panel.add(label_name); panel.add(nameField); panel.add(label_pass); panel.add(passField); } public static void main(String agrs[]) { //new demo1().launchFrame(); new demo1(); } }
1.在哪里输入,web还是app
老乡你好