我是一个 Eclipse 新手,我正在尝试构建一个混合的 AWT/SWT 应用程序。这是我的代码:
public class HelloWorldSWT {
public static void main(String[] args) {
Frame frame = new Frame("My AWT Frame"); // java.awt.Frame
frame.setLayout( new BorderLayout() );
Canvas canvas = new Canvas(); // java.awt.Canvas
frame.add(canvas, BorderLayout.CENTER);
frame.setVisible(true);
Display display = new Display(); // display object to manage SWT lifecycle.
Shell swtShell = SWT_AWT.new_Shell(display, canvas);
Button m_button = new Button(swtShell, SWT.PUSH);
m_button.setText( "button" );
// invoke the AWT frame rendering by making the frame visible
// This starts the EDT
frame.setVisible(true);
// standard SWT dispatch loop
while(!swtShell.isDisposed())
{
if(!display.readAndDispatch())
display.sleep();
}
swtShell.dispose();
}
}
这编译得很好,但是当我在 Eclipse 中将它作为应用程序运行时,我收到以下错误:
线程“主”java.lang.UnsatisfiedLinkError 中的异常:sun.awt.SunToolkit.getAppContext(Ljava/lang/Object;)Lsun/awt/AppContext; 在 sun.awt.SunToolkit.getAppContext(Native Method) 在 sun.awt.SunToolkit.targetToAppContext(Unknown Source) 在 sun.awt.windows.WComponentPeer.postEvent(Unknown Source) 在 sun.awt.windows.WComponentPeer.postPaintIfNecessary(Unknown源) 在 sun.awt.windows.WComponentPeer.handlePaint(Unknown Source) 在 sun.java2d.d3d.D3DScreenUpdateManager.repaintPeerTarget(Unknown Source) 在 sun.java2d.d3d.D3DScreenUpdateManager.createScreenSurface(Unknown Source) 在 sun.awt.windows sun.awt.windows.WComponentPeer.replaceSurfaceData(Unknown Source) 处 sun.awt.windows.WComponentPeer 处的 .WComponentPeer.replaceSurfaceData(Unknown Source)。
我究竟做错了什么?