zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然JAVA图形界面编程学习笔记:文本组件JTextComponent

    import java.awt.GridLayout ;
    import javax.swing.JFrame ;
    import javax.swing.JPasswordField ;
    import javax.swing.JLabel ;
    public class JPasswordDemo01{
        public static void main(String args[]){
            JFrame frame = new JFrame("Welcome To MLDN") ;
            JPasswordField jpf1 = new JPasswordField() ;
            JPasswordField jpf2 = new JPasswordField() ;
            jpf2.setEchoChar('#') ;    // 设置回显
            JLabel lab1 = new JLabel("默认的回显:") ;
            JLabel lab2 = new JLabel("回显设置“#”:") ;
    
            lab1.setBounds(10,10,100,20) ;
            lab2.setBounds(10,40,100,20) ;
            jpf1.setBounds(110,10,80,20) ;
            jpf2.setBounds(110,40,50,20) ;
    
            frame.setLayout(null) ;
            frame.add(lab1) ;
            frame.add(jpf1) ;
            frame.add(lab2) ;
            frame.add(jpf2) ;
            frame.setSize(300,100) ;
            frame.setLocation(300,200) ;
            frame.setVisible(true) ;
        }
    };
    import java.awt.GridLayout ;
    import javax.swing.JFrame ;
    import javax.swing.JTextArea ;
    import javax.swing.JLabel ;
    public class JTextAreaDemo01{
        public static void main(String args[]){
            JFrame frame = new JFrame("Welcome To MLDN") ;
            JTextArea jta = new JTextArea(3,10) ;    // 设置大小
            JLabel lab = new JLabel("多行文本域:") ;
            lab.setBounds(10,10,120,20) ; 
            jta.setBounds(130,10,150,100) ; 
            frame.setLayout(null) ;    // 取消布局管理器
            frame.add(lab) ;
            frame.add(jta) ;
            frame.setSize(300,150) ;
            frame.setLocation(300,200) ;
            frame.setVisible(true) ;
        }
    };
    import java.awt.GridLayout ;
    import javax.swing.JFrame ;
    import javax.swing.JTextArea ;
    import javax.swing.JScrollPane ;
    import javax.swing.JLabel ;
    public class JTextAreaDemo02{
        public static void main(String args[]){
            JFrame frame = new JFrame("Welcome To MLDN") ;
            JTextArea jta = new JTextArea(3,10) ;    // 设置大小
            JLabel lab = new JLabel("多行文本域:") ;
            JScrollPane scr = new JScrollPane(jta,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS ,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS ) ;
            frame.setLayout(new GridLayout(2,1)) ;    // 取消布局管理器
            frame.add(lab) ;
            frame.add(scr) ;
            frame.setSize(300,150) ;
            frame.setLocation(300,200) ;
            frame.setVisible(true) ;
        }
    };
    import java.awt.GridLayout ;
    import javax.swing.JFrame ;
    import javax.swing.JTextField ;
    import javax.swing.JLabel ;
    public class JTextDemo01{
        public static void main(String args[]){
            JFrame frame = new JFrame("Welcome To MLDN") ;
            JTextField name = new JTextField(30) ;
            JTextField noed = new JTextField("MLDN",10) ;
            JLabel nameLab = new JLabel("输入用户姓名:") ;
            JLabel noedLab = new JLabel("不可编辑文本:") ;
            name.setColumns(30) ;
            noed.setColumns(10) ;
            noed.setEnabled(false) ;    // 表示不可编辑
            frame.setLayout(new GridLayout(2,2)) ;
            frame.add(nameLab) ;
            frame.add(name) ;
            frame.add(noedLab) ;
            frame.add(noed) ;
            frame.setSize(300,100) ;
            frame.setLocation(300,200) ;
            frame.setVisible(true) ;
        }
    };
    import java.awt.GridLayout ;
    import javax.swing.JFrame ;
    import javax.swing.JTextField ;
    import javax.swing.JLabel ;
    public class JTextDemo02{
        public static void main(String args[]){
            JFrame frame = new JFrame("Welcome To MLDN") ;
            JTextField name = new JTextField(30) ;
            JTextField noed = new JTextField("MLDN",10) ;
            JLabel nameLab = new JLabel("输入用户姓名:") ;
            JLabel noedLab = new JLabel("不可编辑文本:") ;
            name.setColumns(30) ;
            noed.setColumns(10) ;
            noed.setEnabled(false) ;    // 表示不可编辑
    
            nameLab.setBounds(10,10,100,20) ;
            noedLab.setBounds(10,40,100,20) ;
            name.setBounds(110,10,80,20) ;
            noed.setBounds(110,40,50,20) ;
    
            frame.setLayout(null) ;
            frame.add(nameLab) ;
            frame.add(name) ;
            frame.add(noedLab) ;
            frame.add(noed) ;
            frame.setSize(300,100) ;
            frame.setLocation(300,200) ;
            frame.setVisible(true) ;
        }
    };
  • 相关阅读:
    [RTT例程练习] 3.1 动态内存管理之rt_malloc和rt_free
    [RTT例程练习] 3.3 静态内存管理,内存池mempool
    [RTT例程练习] 6.2 在 Finsh 中运行自定义函数
    [RTT例程练习] 2.9 事件机制event
    [SCons 有点翻译的scons学习] 3. 生成和使用库
    [RTT例程练习] 3.2 动态内存管理之rt_realloc和free
    vim 启动 python的自动补全
    [RTT例程练习] 6.1 Finsh 的基本使用
    ELF文件重定位
    [RTT例程练习] 4.2 动态定时器
  • 原文地址:https://www.cnblogs.com/tszr/p/12398848.html
Copyright © 2011-2022 走看看