Java/SWT JFace Eclipse/Application Window
Содержание
First JFace application
<source lang="java">
import org.eclipse.jface.window.ApplicationWindow; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.*; /**
* Your first JFace application */
public class HelloWorld extends ApplicationWindow {
/** * HelloWorld constructor */ public HelloWorld() { super(null); } /** * Runs the application */ public void run() { // Don"t return from open() until window closes setBlockOnOpen(true); // Open the main window open(); // Dispose the display Display.getCurrent().dispose(); } /** * Creates the main window"s contents * * @param parent the main window * @return Control */ protected Control createContents(Composite parent) { // Create a Hello, World label Label label = new Label(parent, SWT.CENTER); label.setText("Hello, World"); return label; } /** * The application entry point * * @param args the command line arguments */ public static void main(String[] args) { new HelloWorld().run(); }
}
</source>
Jface ApplicationWindow
<source lang="java">
/* SWT/JFace in Action GUI Design with Eclipse 3.0 Matthew Scarpino, Stephen Holder, Stanford Ng, and Laurent Mihalkovic ISBN: 1932394273 Publisher: Manning
- /
import org.eclipse.jface.window.ApplicationWindow; import org.eclipse.swt.widgets.ruposite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; public class WidgetWindow extends ApplicationWindow {
public WidgetWindow() { super(null); } protected Control createContents(Composite parent) { getShell().setText("Widget Window"); parent.setSize(400,250); return parent; } public static void main(String[] args) { WidgetWindow wwin = new WidgetWindow(); wwin.setBlockOnOpen(true); wwin.open(); Display.getCurrent().dispose(); }
}
</source>
JFace Window
<source lang="java">
/******************************************************************************
* All Right Reserved. * Copyright (c) 1998, 2004 Jackwind Li Guojie * * Created on 2004-5-13 14:30:36 by JACK * $Id$ * *****************************************************************************/
import org.eclipse.jface.window.ApplicationWindow; import org.eclipse.jface.window.Window; public class DummyWindow {
public static void main(String[] args) { Window window = new ApplicationWindow(null); window.setBlockOnOpen(true); int returnStatus = window.open(); }
}
</source>
Simplest ApplicationWindow
<source lang="java">
/* SWT/JFace in Action GUI Design with Eclipse 3.0 Matthew Scarpino, Stephen Holder, Stanford Ng, and Laurent Mihalkovic ISBN: 1932394273 Publisher: Manning
- /
import org.eclipse.jface.window.ApplicationWindow; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.ruposite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Text; public class HelloSWT_JFace extends ApplicationWindow {
public HelloSWT_JFace() { super(null); } protected Control createContents(Composite parent) { Text helloText = new Text(parent, SWT.CENTER); helloText.setText("Hello SWT and JFace!"); parent.pack(); return parent; } public static void main(String[] args) { HelloSWT_JFace awin = new HelloSWT_JFace(); awin.setBlockOnOpen(true); awin.open(); Display.getCurrent().dispose(); }
}
</source>
Simplest SWT application
<source lang="java">
/******************************************************************************
* Copyright (c) 1998, 2004 Jackwind Li Guojie * All right reserved. * * Created on Oct 25, 2003 2:02:04 PM by JACK * $Id: HelloWorld.java,v 1.1 2003/12/22 12:07:54 jackwind Exp $ * * visit: http://www.asprise.ru/swt *****************************************************************************/
import org.eclipse.jface.window.ApplicationWindow; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; /**
* HelloWorld is the simplest SWT application, which displays a Shell with a title. */
public class HelloWorldApplicationWindow {
public static void main2(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Hello, world!"); shell.open(); while(! shell.isDisposed()) { if(! display.readAndDispatch()) {// If no more entries in event queue display.sleep(); } } display.dispose(); } public static void main(String[] args) { ApplicationWindow aw = new ApplicationWindow(null); aw.setBlockOnOpen(true); aw.open(); }
}
</source>