package com.kk;
//JPasswordField类的使用
import java.awt.Color;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
public class Panel {
public static void main(String[] args) {
JFrame frame = new JFrame();
JPasswordField pass = new JPasswordField(23);// 密码文本框必须设置列数。大小值,否则显示不出来
JPanel panel = new JPanel();// 创建一个panel类
JLabel label = new JLabel("请输入密码:");// 标签
frame.setTitle("阳光的小女孩");
label.setBackground(Color.pink);
pass.setBackground(Color.green);
// 添加面板
panel.add(label);// 将文字信息
panel.add(pass);// 添加密码框
frame.add(panel);
frame.setBackground(Color.pink);
frame.setBounds(543, 533, 533, 533);// 设置框的尺寸大小值
frame.setLayout(new FlowLayout());
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
总结: