Chinaunix首页 | 论坛 | 博客
  • 博客访问: 593488
  • 博文数量: 98
  • 博客积分: 4045
  • 博客等级: 上校
  • 技术积分: 1157
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-31 16:56
文章分类

全部博文(98)

文章存档

2010年(7)

2009年(15)

2007年(73)

2006年(3)

我的朋友

分类: Java

2007-06-26 16:29:58


class SWTPane extends JPanel {
    DisplayThread displayThread;

    Browser browser;

    String ipAddress;

    private Canvas canvas;

    Display dis;
    
    public SWTPane(String ipAddress) {
        this.ipAddress = ipAddress;
        displayThread = new DisplayThread();

        displayThread.start();

        canvas = new Canvas();
        setLayout(new BorderLayout());
        add(canvas, BorderLayout.CENTER);
    }

    public void addNotify() {
        super.addNotify();

        dis = displayThread.getDisplay();

        dis.syncExec(new Runnable() {
            public void run() {
                final Shell shell = SWT_AWT.new_Shell(displayThread.getDisplay(),
                        canvas);

                shell.setLayout(new FillLayout());

                browser = new Browser(shell, SWT.NONE);

                browser.setLayoutData(BorderLayout.CENTER);

                browser.setUrl(ipAddress);
            }
        });
    }
}

class DisplayThread extends Thread {
    private Display display;

    Object sem = new Object();

    public void run() {
        synchronized (sem) {
            display = new Display();
            sem.notifyAll();
        }
        swtEventLoop();
    }

    private void swtEventLoop() {
        while (true) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }

    public synchronized Display getDisplay() {
        try {
            synchronized (sem) {
                while (display == null)
                    sem.wait();
                return display;
            }
        } catch (Exception e) {
            return null;
        }
    }

}

阅读(4334) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

wkl172014-06-22 13:35:15

不带 import *** ..
挺好奇你们最初都是如何学Java的?做什么具体例子/项目 吗?