⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.java

📁 swing 教程,与大家分享一下,哈哈,希望大家多多指教
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;

public class Test extends JApplet {
	Component strut = Box.createHorizontalStrut(50);

	public Test() {
		Container contentPane = getContentPane();
		//Box box = new Box(BoxLayout.X_AXIS);
		JPanel box = new JPanel();

		box.setLayout(new GridLayout(2,1));
		box.add(new JButton("button 1"));
		box.add(strut);
		box.add(new JButton("button 2"));

		contentPane.setLayout(new FlowLayout());
		contentPane.add(box);
	}
	public void paint(Graphics g) {
		super.paint(g);
		System.out.println("strut width:  " + 
							strut.getSize().width);
	}
	public static void main(String args[]) {
		final JFrame f = new JFrame();
		JApplet applet = new Test();

		applet.init();

		f.setContentPane(applet.getContentPane());
		f.setBounds(100,100,308,199);
		f.setTitle("An Application");
		f.setVisible(true);

		f.setDefaultCloseOperation(
			WindowConstants.DISPOSE_ON_CLOSE);

		f.addWindowListener(new WindowAdapter() {
			public void windowClosed(WindowEvent e) {
				System.exit(0);
			}
		});
	}
}

⌨️ 快捷键说明

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