Button btnNewButton = new Button(shell, SWT.NONE);
btnNewButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
txtTest.setText("Hello World!");
JOptionPane.showConfirmDialog(null, "Hello Java World!");
}
});刚学习java,测试一段代码,不能弹出messagebox,哪位朋友给指点一下哪个地方有问题?多谢!
btnNewButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
txtTest.setText("Hello World!");
JOptionPane.showConfirmDialog(null, "Hello Java World!");
}
});刚学习java,测试一段代码,不能弹出messagebox,哪位朋友给指点一下哪个地方有问题?多谢!
则可以正常运行。有了上面这语句,运行时候出现的异常:
Exception in thread "Image Fetcher 0" java.lang.UnsatisfiedLinkError: sun.awt.image.BufImgSurfaceData.initIDs()V
at sun.awt.image.BufImgSurfaceData.initIDs(Native Method)
at sun.awt.image.BufImgSurfaceData.<clinit>(Unknown Source)
at sun.awt.image.CachingSurfaceManager.<init>(Unknown Source)
at sun.java2d.d3d.D3DCachingSurfaceManager.<init>(Unknown Source)
at sun.java2d.SurfaceManagerFactory.createCachingManager(Unknown Source)
at sun.awt.image.SurfaceManager.getManager(Unknown Source)
at sun.awt.image.CachingSurfaceManager.restoreLocalAcceleration(Unknown Source)
at sun.awt.image.ImageRepresentation.getOpaqueRGBImage(Unknown Source)
at sun.awt.image.ImageRepresentation.imageComplete(Unknown Source)
at sun.awt.image.ImageDecoder.imageComplete(Unknown Source)
at sun.awt.image.PNGImageDecoder.produceImage(Unknown Source)
at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source)
at sun.awt.image.ImageFetcher.fetchloop(Unknown Source)
at sun.awt.image.ImageFetcher.run(Unknown Source)
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
public class rrrrrr { protected Shell shell;
private Text txtTest; /**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
rrrrrr window = new rrrrrr();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
} /**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
} /**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");
Button btnNewButton = new Button(shell, SWT.NONE);
btnNewButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
txtTest.setText("Hello World!");
//JOptionPane.showConfirmDialog(null, "Hello Java World!");
}
});
btnNewButton.setBounds(54, 10, 72, 22);
btnNewButton.setText("New Button");
txtTest = new Text(shell, SWT.BORDER);
txtTest.setText("test");
txtTest.setBounds(92, 74, 70, 18); }
}