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

📄 demoshell.java

📁 一个swing窗体 很漂亮
💻 JAVA
字号:
package demo.swt;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class DemoShell extends Shell implements ControlListener, PaintListener {
	private Composite northwestPanel;

	private Composite northeastPanel;

	private Composite northPanel;

	private Composite southwestPanel;

	private Composite southeastPanel;

	private Composite southPanel;

	private Composite westPanel;

	private Composite eastPanel;

	private Composite contentPanel;

	// icon

	private Image northwestImage;

	private Image northeastImage;

	private Image northImage;

	private Image southwestImage;

	private Image southeastImage;

	private Image southImage;

	private Image westImage;

	private Image eastImage;

	// color
	private Color color1 = new Color(getDisplay(), 207, 227, 216);

	private Color color2 = new Color(getDisplay(), 255, 255, 254);

	/**
	 * Create the shell
	 * 
	 * @param display
	 * @param style
	 */
	public DemoShell(Display display) {
		super(display, SWT.NO_TRIM);
		createContents();
		addControlListener(this);
	}

	/**
	 * Create contents of the window
	 */
	private void createContents() {
		northwestPanel = new Composite(this, SWT.NONE);
		northwestImage = new Image(getDisplay(), "icon/northwest.jpg");
		northwestPanel.setBackgroundImage(northwestImage);
		northeastPanel = new Composite(this, SWT.NONE);
		northeastImage = new Image(getDisplay(), "icon/northeast.jpg");
		northeastPanel.setBackgroundImage(northeastImage);
		northPanel = new Composite(this, SWT.NONE);
		northImage = new Image(getDisplay(), "icon/north.jpg");
		northPanel.setBackgroundImage(northImage);
		southwestPanel = new Composite(this, SWT.NONE);
		southwestImage = new Image(getDisplay(), "icon/southwest.jpg");
		southwestPanel.setBackgroundImage(southwestImage);
		southeastPanel = new Composite(this, SWT.NONE);
		southeastImage = new Image(getDisplay(), "icon/southeast.jpg");
		southeastPanel.setBackgroundImage(southeastImage);
		southPanel = new Composite(this, SWT.NONE);
		southImage = new Image(getDisplay(), "icon/south.jpg");
		southPanel.setBackgroundImage(southImage);
		westPanel = new Composite(this, SWT.NONE);
		westImage = new Image(getDisplay(), "icon/west.jpg");
		westPanel.setBackgroundImage(westImage);
		eastPanel = new Composite(this, SWT.NONE);
		eastImage = new Image(getDisplay(), "icon/east.jpg");
		eastPanel.setBackgroundImage(eastImage);
		contentPanel = new Composite(this, SWT.NONE);
		contentPanel.setBackgroundMode(SWT.INHERIT_FORCE);
		contentPanel.addPaintListener(this);
		//
	}

	public void controlMoved(ControlEvent e) {
		// TODO 自动生成方法存根

	}

	public void controlResized(ControlEvent e) {
		int w = getSize().x;
		int h = getSize().y;
		northwestPanel.setBounds(0, 0, northwestImage.getBounds().width,
				northwestImage.getBounds().height);
		northeastPanel.setBounds(w - northeastImage.getBounds().width, 0,
				northeastImage.getBounds().width,
				northeastImage.getBounds().height);
		northPanel.setBounds(northwestImage.getBounds().width, 0, w
				- northwestImage.getBounds().width
				- northeastImage.getBounds().width,
				northImage.getBounds().height);
		southwestPanel.setBounds(0, h - southwestImage.getBounds().height,
				southwestImage.getBounds().width,
				southwestImage.getBounds().height);
		southeastPanel.setBounds(w - southeastImage.getBounds().width, h
				- southeastImage.getBounds().height,
				southeastImage.getBounds().width,
				southeastImage.getBounds().height);
		southPanel.setBounds(southwestImage.getBounds().width, h
				- southImage.getBounds().height, w
				- southwestImage.getBounds().width
				- southeastImage.getBounds().width,
				southImage.getBounds().height);
		westPanel.setBounds(0, northwestImage.getBounds().height, westImage
				.getBounds().width, h - northwestImage.getBounds().height
				- southwestImage.getBounds().height);
		eastPanel.setBounds(w - eastImage.getBounds().width, northeastImage
				.getBounds().height, eastImage.getBounds().width, h
				- northeastImage.getBounds().height
				- southeastImage.getBounds().height);
		contentPanel
				.setBounds(westImage.getBounds().width,
						northImage.getBounds().height, w
								- westImage.getBounds().width
								- eastImage.getBounds().width, h
								- northImage.getBounds().height
								- southImage.getBounds().height);
	}

	public void paintControl(PaintEvent e) {
		GC gc = e.gc;
		gc.setBackground(color2);
		gc.setForeground(color1);
		gc.fillGradientRectangle(0, 0, e.width, e.height, true);
		gc.dispose();
	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
}

⌨️ 快捷键说明

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