boxlayoutexample.java

来自「java实验报告书:其中包括实验代码以及说明等」· Java 代码 · 共 23 行

JAVA
23
字号
import java.awt.*;  
import java.awt.event.*;
import javax.swing.*;
public class BoxLayoutExample{
  public static void main (String args[]) {
 JFrame frame_box = new JFrame ("BoxLayout示例");
 Container contentPane = frame_box.getContentPane();
 ContainerWithBoxLayout yaxis = new ContainerWithBoxLayout(BoxLayout.Y_AXIS);
 ContainerWithBoxLayout xaxis = new ContainerWithBoxLayout(BoxLayout.X_AXIS);
 contentPane.setLayout(new FlowLayout());
 xaxis.add(new JButton("one")); 
	xaxis.add(new JButton("two"));	xaxis.add(new JButton("three")); 
 yaxis.add(new JButton("four"));
	yaxis.add(new JButton("five")); yaxis.add(new JButton("six"));
 contentPane.add(xaxis); contentPane.add(yaxis);
 frame_box.pack(); frame_box.show();
 frame_box.addWindowListener(new WindowAdapter() {
  public void windowClosing(WindowEvent e) {
   System.exit(0);}});}}
class ContainerWithBoxLayout extends JPanel { 
 public ContainerWithBoxLayout(int orientation) {
  setLayout(new BoxLayout(this, orientation)); }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?