注册 登录
编程论坛 JAVA论坛

如何让 输入的密码 变成*的形式出来呢

ch。浩 发布于 2016-04-14 22:04, 2849 次点击
这是 我做的 邮箱注册的界面
package com.Email;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Email extends JFrame {
    JLabel l1,l2,l3,l4,l5;
    JTextField t1,t2,t3,t4;
    JButton b;
    public Email(){
        JFrame j=new JFrame();
        JPanel p=new JPanel();
        p.setLayout(null);
        
        l1=new JLabel("邮件地址");
        l2=new JLabel("密          码");
        l3=new JLabel("确认密码");
        l4=new JLabel("手机号码");
        l5=new JLabel("");
        
        
        t1=new JTextField(3);
        t2=new JTextField(3);
        t3=new JTextField(3);
        t4=new JTextField(3);
        
        b=new JButton("立即注册");
        p.setBounds(0, 0, 400, 300);
        l1.setBounds(0, 0, 100, 20);
        t1.setBounds(150, 0, 150, 20);
        l2.setBounds(0,50, 100,20);
        t2.setBounds(150, 50, 150, 20);
        l3.setBounds(0,100, 100, 20);
        t3.setBounds(150, 100, 150, 20);
        l4.setBounds(0,150, 100,20);
        t4.setBounds(150, 150, 150, 20);
        b.setBounds(100, 200,100, 20);
        
        p.add(l1);
        p.add(t1);
        p.add(l2);
        p.add(t2);
        p.add(l3);
        p.add(t3);
        p.add(l4);
        p.add(t4);
        p.add(b);
        p.add(l5);
        
        j.setLayout(null);
        j.add(p);
        
        j.setTitle("E-mail注册");
        j.setVisible(true);
        j.setSize(400,300);
        j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
new Email();
    }

}
2 回复
#2
kid国际新生2016-04-15 12:26
之前刚好在课本上看到了.
passwordLabel =new JLabel(“密码”);
passwordField= new JPasswordField(23);
passwordField.setEchoChar(‘*’);
这是JPasswordField下的方法.
#3
ch。浩2016-04-18 21:34
回复 2楼 kid国际新生
谢谢谢谢  我试一下
1