abstractcomponents.java

来自「Swing入门必看 Swing Demo」· Java 代码 · 共 51 行

JAVA
51
字号
/*
 * @(#)AbstractComponents.java 2007-4-27
 * Copyright 2007 AIC. All rights reserved. 
 */
package components;

import java.awt.*;

import javax.swing.*;

/**
 * Common JFrame contained vertical box, and set default properties
 * 
 * Note: 
 * 		protected abstract void initComponents(Box box); 
 * 
 * @author Henry Zhu
 */
public abstract class AbstractComponents extends JFrame {

	private static final long serialVersionUID = 1L;

	protected abstract void initComponents(Box box); 
	
	/**
	 * set up common GUI
	 */
	public AbstractComponents(String title) {
		// invoke super constructor with the specified title
		super(title);

		// create Box containers with BoxLayout
		Box box = Box.createVerticalBox();
		box.add(Box.createVerticalStrut(10));
		
		// init compontents and add them into box
		initComponents(box);
		
		// get content pane and set its layout
		Container container = getContentPane();
		container.setLayout(new FlowLayout());
		container.add(box);

		// set size for the frame and show the frame
		setSize(300, 400);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
	}

}

⌨️ 快捷键说明

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