贴一段simple example,自己留念一下 ^_^
package
TestJFace;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class SimpleAppWindow extends ApplicationWindow
{
public SimpleAppWindow()
{
super(null);
}
public void show()
{
setBlockOnOpen(true);
open();
}
protected Control createContents(final Composite parent)
{
Button b = new Button(parent , SWT.PUSH);
b.setText("button");
b.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent ex)
{
MessageDialog.openConfirm(parent.getShell(), "title", "button 1 pressed");
}
});
return parent;
}
protected void configureShell(Shell shell)
{
super.configureShell(shell);
shell.setText("练习");
}
}
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class SimpleAppWindow extends ApplicationWindow
{
public SimpleAppWindow()
{
super(null);
}
public void show()
{
setBlockOnOpen(true);
open();
}
protected Control createContents(final Composite parent)
{
Button b = new Button(parent , SWT.PUSH);
b.setText("button");
b.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent ex)
{
MessageDialog.openConfirm(parent.getShell(), "title", "button 1 pressed");
}
});
return parent;
}
protected void configureShell(Shell shell)
{
super.configureShell(shell);
shell.setText("练习");
}
}
package
TestJFace;
import org.eclipse.swt.widgets.Display;
public class AppMain
{
public static void main(String[] args)
{
new SimpleAppWindow().show();
Display.getCurrent().dispose();
}
}
import org.eclipse.swt.widgets.Display;
public class AppMain
{
public static void main(String[] args)
{
new SimpleAppWindow().show();
Display.getCurrent().dispose();
}
}
上面的代码,extends ApplicationWindow 后,创建一个Button 再给button增加一个监听 ,就差不多实现一个最简单的例子。继续jface的ApplicationWindow后,最明显的一个改观就是。不用我再去
while
(
!
shellTop.isDisposed())
{
if(!display.readAndDispatch())
display.sleep();
}
{
if(!display.readAndDispatch())
display.sleep();
}