文本框
package com.Hailin.lesson05;
import javax.swing.*;
import java.awt.*;
public class TestTestDemo01 extends JFrame {
public TestTestDemo01() {
Container container = this.getContentPane();
JTextField jTextField1 = new JTextField("hello");
JTextField jTextField2 = new JTextField("world",20);
container.add(jTextField1,BorderLayout.SOUTH);
container.add(jTextField2,BorderLayout.NORTH);
setVisible(true);
setBounds(300,300,500,400);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestTestDemo01();
}
}
密码框
package com.Hailin.lesson05;
import javax.swing.*;
import java.awt.*;
public class TestTestDemo02 extends JFrame {
public TestTestDemo02() {
Container container = this.getContentPane();
JPasswordField passwordField = new JPasswordField();
passwordField.setEchoChar('*');
container.add(passwordField);
setVisible(true);
setBounds(300,300,500,400);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestTestDemo02();
}
}
文本域
package com.Hailin.lesson05;
import com.Hailin.lesson04.JFrameDemo;
import javax.swing.*;
import java.awt.*;
public class JScrollDemo extends JFrame {
public JScrollDemo() {
Container container = this.getContentPane();
JTextArea textArea = new JTextArea(20, 50);
textArea.setText("欢迎学习文本域");
JScrollPane scrollPane = new JScrollPane(textArea);
container.add(scrollPane);
this.setVisible(true);
this.setBounds(300,300,300,300);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new JFrameDemo();
}
}