一,控件封装 import java.io.File; import org.eclipse.swt.SWT; import org.eclipse.swt.SWTError; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.ole.win32.OLE; import org.eclipse.swt.ole.win32.OleAutomation; import org.eclipse.swt.ole.win32.OleControlSite; import org.eclipse.swt.ole.win32.OleFrame; import org.eclipse.swt.ole.win32.Variant; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import com.swtdesigner.SWTResourceManager; import swing2swt.layout.BorderLayout; public class SWF extends Composite { private OleAutomation player; /** * Create the composite * @param parent * @param style */ public SWF(Composite parent, int style) { super(parent, style); final FillLayout fillLayout = new FillLayout(); setLayout(fillLayout); setSize(649, 60); setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); createContents(); } protected void createContents() { OleControlSite controlSite; try { OleFrame frame = new OleFrame(this, SWT.NO_TRIM); frame.setLayout(new FillLayout()); //frame.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); controlSite = new OleControlSite(frame, SWT.NO_TRIM, “{D27CDB6E-AE6D-11cf-96B8-444553540000}”); controlSite.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); controlSite.setRedraw(true); controlSite.setLayoutDeferred(true); controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); controlSite.pack(); } catch (SWTError e) { System.out.println(”Unable to open activeX control”); return; } player = new OleAutomation(controlSite); setFocus(); // prevents vm from crashing on shutdown. pack(); //loadFile(Application.getConfigAsString(”media.list”)); loadMove( new File(”ad.swf”)); setQuality2(”high”); setScale(”ExactFit”); setWMode(”Transparent”); setLoop(true); play(true); // } public void setWMode(String s) { int ids[] = player.getIDsOfNames(new String[] { “WMode” }); if (ids != null) { player.setProperty(ids[0], new Variant(s)); } } public void setScaleMode(String s) { int ids[] = player.getIDsOfNames(new String[] { “ScaleMode” }); if (ids != null) { player.setProperty(ids[0], new Variant(s)); } } public void setScale(String s) { int ids[] = player.getIDsOfNames(new String[] { “Scale” }); if (ids != null) { player.setProperty(ids[0], new Variant(s)); } } public void setQuality2(String s) { int ids[] = player.getIDsOfNames(new String[] { “Quality2″ }); if (ids != null) { player.setProperty(ids[0], new Variant(s)); } } public void play(boolean s) { int ids[] = player.getIDsOfNames(new String[] { “Playing” }); if (ids != null) { System.out.println(”playing”); player.setProperty(ids[0], new Variant(s)); } } public void loadMove(File url) { int ids[] = player.getIDsOfNames(new String[] { “Movie” }); if (ids != null) { player.setProperty(ids[0], new Variant(url.getAbsolutePath())); } } public void setLoop(boolean b) { int ids[] = player.getIDsOfNames(new String[] { “Loop” }); if (ids != null) { player.setProperty(ids[0], new Variant(b)); } } @Override protected void checkSubclass() { // Disable the check that prevents subclassing of SWT components } } 二。调用 import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import com.cnt.happytime.SWF; public class SwfPlayer extends Shell { /** * Launch the application * @param args */ public static void main(String args[]) { try { Display display = Display.getDefault(); SwfPlayer shell = new SwfPlayer(display, SWT.SHELL_TRIM); shell.open(); shell.layout(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } } catch (Exception e) { e.printStackTrace(); } } /** * Create the shell * @param display * @param style */ public SwfPlayer(Display display, int style) { super(display, style); createContents(); } /** * Create contents of the window */ protected void createContents() { setText(”SWT Application”); setSize(500, 102); setLayout(new FillLayout()); final SWF wF = new SWF(this, SWT.NONE); wF.setLayout(new FillLayout()); // } @Override protected void checkSubclass() { // Disable the check that prevents subclassing of SWT components } }