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,哪位朋友给指点一下哪个地方有问题?多谢!

解决方案 »

  1.   

    JOptionPane.showConfirmDialog(null, "Hello Java World!");是不是你的第一个参数有问题啊,null?应该是个Component吧,哈哈 新手就上手SWT啦  不错不错
      

  2.   

    测试下,看是否已经在监听!!如果监听到了,那么你这个类是否继承了JFrame
      

  3.   

    如果没有这句:JOptionPane.showConfirmDialog(null, "Hello Java World!");
    则可以正常运行。有了上面这语句,运行时候出现的异常:
    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)
      

  4.   

    import javax.swing.JOptionPane;import org.eclipse.swt.widgets.Display;
    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); }
    }
      

  5.   

    因为SWT是调用本地的.dll库文件 绘制UI 的  所以可能是dll文件缺失吧
      

  6.   

    为了加速图片的加载,JAVA为每个请求都提供 了一个线程,在这个线程(Image Fetcher 0)出现了问题,应该是图片没有找到,加载不上吧。确认你有最新的显卡驱动么?你的代码在我的系统是没问题的
      

  7.   

    或者你的JRE有问题,就是处理图片的部分出现问题了,实在不行的话重装JAVA试试?