boxlayoutframe.java
来自「java2参考大全上的例子的源码和自己的理解.」· Java 代码 · 共 50 行
JAVA
50 行
package boxlayoutframe;//BoxLayoutFrame.javaimport java.awt.*;import javax.swing.*;public class BoxLayoutFrame extends JFrame { BoxLayoutTest panel = new BoxLayoutTest(); public BoxLayoutFrame() { //Returns the contentPane object for this frame. this.getContentPane().add(panel); this.setSize(500,220); //设置程序的标题 this.setTitle("BoxLayoutDemo"); //Sets the operation that will happen by default when the user initiates a "close" on this frame. //You must specify one of the following choices //EXIT_ON_CLOSE (defined in JFrame): Exit the application using the System exit method. Use this only in applications. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Makes the Window visible. If the Window and/or its owner are not yet displayable, both are made displayable. The Window will be validated prior to being made visible. //If the Window is already visible, this will bring the Window to the front. this.show(); } public static void main(String[] args) { BoxLayoutFrame frame = new BoxLayoutFrame(); }}class BoxLayoutTest extends JPanel { BoxLayoutTest() { // Set the layout to a y-axis BoxLayout //Y_AXIS - Components are laid out vertically from top to bottom. setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); // Create three components TextField textField = new TextField();//textField相当于edit控件 TextArea textArea = new TextArea(4, 20);//textArea类似于ListView JButton button = new JButton( "Click me!"); // Add the three components to the BoxLayout add(new JLabel("TextField")); add(textField); add(new JLabel("TextArea")); add(textArea); add(new JLabel("Button")); add(button); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?