zoukankan      html  css  js  c++  java
  • 文本框JTextField,密码框JPasswordField

    1、文本框JTextField

    public class Demo extends JFrame {
        public Demo() {
            setBounds(100, 100, 200, 120);
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            Container c = getContentPane();
            c.setLayout(new FlowLayout());
            JTextField tf = new JTextField();//创建文本框
            tf.setColumns(15);//文本框长度
            tf.setText("黑体,加粗,20");
            tf.setFont(new Font("黑体", Font.BOLD, 20));
            c.add(tf);
            JButton btn = new JButton("打印");
            btn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println(tf.getText());
                    tf.setText("");//清空文本
                    tf.requestFocus();//获取焦点
                }
            });
            c.add(btn);
            setVisible(true);
        }
    
        public static void main(String[] args) {
            new Demo();
        }
    }

     2、密码框JPasswordField

    public class Demo extends JFrame {
        public Demo() {
            setBounds(100, 100, 200, 100);
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            Container c = getContentPane();
            c.setLayout(new FlowLayout());
            JPasswordField pf = new JPasswordField();//密码框
            pf.setColumns(15);
            pf.addActionListener(new ActionListener() {//添加动作监听,回车触发
                public void actionPerformed(ActionEvent e) {
                    System.out.println(pf.getPassword());
                }
            });
            c.add(pf);
            setVisible(true);
        }
    
        public static void main(String[] args) {
            new Demo();
        }
    }
  • 相关阅读:
    li float后IE下有空格
    [转]输入框对齐问题
    footer贴在底部的布局
    css3.0参考手册
    Java变量的命名规范
    刷题01
    前端面试题
    Cadence学习封装制作(焊盘)
    Cadence学习文档后缀简介
    Cadence学习PCB设计(序)
  • 原文地址:https://www.cnblogs.com/xixixing/p/9459885.html
Copyright © 2011-2022 走看看