package day15; import javax.swing.*; import java.awt.*; public class TextField extends JFrame { public TextField() { Container container = this.getContentPane(); JTextField textField1 = new JTextField("xiao"); JTextField textField2 = new JTextField("ming", 30); container.add(textField1, BorderLayout.NORTH); container.add(textField2, BorderLayout.SOUTH); this.setVisible(true); this.setSize(200, 200); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } public static void main(String[] args) { new TextField(); } }
执行结果: