1 package com.kuang.lesson06; 2 3 import javax.swing.*; 4 import java.awt.*; 5 import java.util.Vector; 6 7 public class TestTextDemo01 extends JFrame { 8 9 //文本框 10 public TestTextDemo01(){ 11 Container container=this.getContentPane(); 12 13 JTextField textField=new JTextField("hello"); 14 JTextField textField2=new JTextField("world",20); 15 16 container.add(textField,BorderLayout.NORTH); 17 container.add(textField2,BorderLayout.SOUTH); 18 19 this.setVisible(true); 20 this.setSize(500,350); 21 this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 22 } 23 24 public static void main(String[] args) { 25 new TestTextDemo01(); 26 } 27 }
package com.kuang.lesson06; import javax.swing.*; import java.awt.*; public class TestTextDemo02 extends JFrame { //密码框 public TestTextDemo02(){ Container container=this.getContentPane(); JPasswordField passwordField=new JPasswordField(); passwordField.setEchoChar(‘*‘); container.add(passwordField); this.setVisible(true); this.setSize(500,350); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } public static void main(String[] args) { new TestTextDemo02(); } }
1 package com.kuang.lesson05; 2 3 import javax.swing.*; 4 import java.awt.*; 5 6 public class JScrollDemo extends JFrame { 7 8 public JScrollDemo(){ 9 Container container=this.getContentPane(); 10 11 //文本域 12 JTextArea textArea=new JTextArea(20,50); 13 textArea.setText("欢迎学习Java!"); 14 15 //Scroll面板 16 JScrollPane scrollPane=new JScrollPane(textArea); 17 container.add(scrollPane); 18 19 this.setVisible(true); 20 this.setBounds(100,100,300,350); 21 this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 22 } 23 24 public static void main(String[] args) { 25 new JScrollDemo(); 26 } 27 }
原文:https://www.cnblogs.com/clblogs/p/14667406.html