test.java

来自「《Java2图形设计卷II:Swing》配套光盘源码」· Java 代码 · 共 34 行

JAVA
34
字号
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Test extends JApplet {
	public Test() {
		Container contentPane = getContentPane();
		ContainerWithBoxLayout yaxis = 
					new ContainerWithBoxLayout(BoxLayout.Y_AXIS);

		ContainerWithBoxLayout xaxis = 
					new ContainerWithBoxLayout(BoxLayout.X_AXIS);

		contentPane.setLayout(new FlowLayout());

		xaxis.add(new JButton(new ImageIcon("reach.gif")));
		xaxis.add(new JButton(new ImageIcon("punch.gif")));
		xaxis.add(new JButton(new ImageIcon("open_hand.gif")));

		yaxis.add(new JButton(new ImageIcon("ladybug.gif")));
		yaxis.add(new JButton(new ImageIcon("crab.gif")));
		yaxis.add(new JButton(new ImageIcon("frog.gif")));
		yaxis.add(new JButton(new ImageIcon("snail.gif")));

		contentPane.add(xaxis);
		contentPane.add(yaxis);
	}
}
class ContainerWithBoxLayout extends JPanel { 
	public ContainerWithBoxLayout(int orientation) {
		setLayout(new BoxLayout(this, orientation));
	}
}

⌨️ 快捷键说明

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