aboutwnd.java

来自「Java语言编写的一段测试源码」· Java 代码 · 共 91 行

JAVA
91
字号
/*
 * Created on 2003-9-10
 *
 * Zilin Du
 */
package org.zilin.gui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

/**
 * @author D6VAA1
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class AboutWnd {
	Shell shell;
	Display display;
	/**
	 * 
	 */
	public AboutWnd(Shell parent) {
		display = parent.getDisplay();
		shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
		initWindow();	
	}

	private Image loadImage(String name) {
		ImageData imageData = new ImageData(name);
		if (imageData.transparentPixel >= 0) {
			ImageData maskData = imageData.getTransparencyMask();
			return new Image(Display.getCurrent(), imageData, maskData);
		} else
			return new Image(Display.getCurrent(), imageData);
	}
	
	public void initWindow() {
		shell.setText("About SWT JavaZip 1.0");
		GridLayout gl = new GridLayout();
		shell.setLayout(gl);
		final Label logo = new Label(shell, SWT.BORDER);
		logo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		logo.setImage(loadImage("images/smile_angel.gif"));

		final Label copyright = new Label(shell, SWT.CENTER);
		copyright.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		copyright.setText("SWT Java Zip 1.0\nCopyright (C) 2003 Zilin Du (zilin@cs.nyu.edu)\nAll Rights Reserved");
		
		final Button okBtn = new Button(shell, SWT.PUSH);
		GridData gd = new GridData();
		gd.horizontalAlignment = GridData.CENTER; 
		gd.widthHint = 80;
		okBtn.setLayoutData(gd);
		okBtn.setText("OK");
		
		okBtn.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event e) {
				shell.close();
			}
		});
	}
	
	public void run() {
		shell.pack();
		
		// centerize
		Rectangle parentRect = shell.getParent().getBounds();
		Point size = shell.getSize();
		shell.setLocation(parentRect.x+(parentRect.width-size.x)/2, parentRect.y+(parentRect.height-size.y)/2);
		
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}
	
}

⌨️ 快捷键说明

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