package com.test;
import java.awt.BorderLayout;
import java.awt.Canvas;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.ole.win32.OleClientSite;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Sword extends JFrame {
private static final long serialVersionUID = -7511601547609623217L;
private static OleFrame oleFrame1;
public static void main(String[] args) {
final JFrame frame = new JFrame();
//关键 使用 canvas 进行交互
Canvas canvas = new Canvas();
JPanel jp = new JPanel();
// jp.setBounds(0, 0, 3, 340);
frame.getContentPane().add(jp);
jp.add(canvas,BorderLayout.CENTER);
jp.getParent().add(canvas,BorderLayout.CENTER);
// frame.getContentPane().add(canvas,BorderLayout.CENTER);
frame.setVisible(true);
frame.setSize(600, 600);
final Display display = new Display();
//利用SWT_AWT.new_Shell 交互
final Shell shell = SWT_AWT.new_Shell(display,canvas);
shell.setLayout(new FillLayout());
shell.layout();
shell.setSize(800, 600);
initGUI(shell);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
private static void initGUI(Shell shell) {
try {
// FillLayout thisLayout = new FillLayout(org.eclipse.swt.SWT.HORIZONTAL);
// shell.setLayout(thisLayout);
// shell.setSize(229, 54);
oleFrame1 = new OleFrame(shell, SWT.NONE);
try {
OleClientSite site = new org.eclipse.swt.ole.win32.OleClientSite(
oleFrame1, org.eclipse.swt.SWT.NONE,
// "Excel.Sheet");
"Word.Document");
// site.setBounds(0, 0, 104, 54);
// site.setBounds(0, 0, 1800, 800);
site.doVerb(org.eclipse.swt.ole.win32.OLE.OLEIVERB_SHOW);
} catch (org.eclipse.swt.SWTException e) {
String str = "Create OleClientSite Error"
+ e.toString();
System.out.println(str);
return;
}
shell.layout();
} catch (Exception e) {
e.printStackTrace();
}
}
public Sword() {
super();
}
}
- 1
- 2
- 3
- 4
- 5
- 6
前往页