diff options
author | Grant Gayed <ggayed> | 2010-03-10 16:54:53 +0000 |
---|---|---|
committer | Grant Gayed <ggayed> | 2010-03-10 16:54:53 +0000 |
commit | 86966a73db67de79833a8050a98054210c5b57c9 (patch) | |
tree | 7f75c9666f9094ed3096c34c2acc13c0fb3a08cc | |
parent | ddab55728bb20ca4ddddda20424d7417f0683e8f (diff) | |
download | eclipse.platform.swt-86966a73db67de79833a8050a98054210c5b57c9.tar.gz eclipse.platform.swt-86966a73db67de79833a8050a98054210c5b57c9.tar.xz eclipse.platform.swt-86966a73db67de79833a8050a98054210c5b57c9.zip |
initial
-rw-r--r-- | examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet337.java | 104 |
1 files changed, 47 insertions, 57 deletions
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet337.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet337.java index e718f12cee..ba78a70663 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet337.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet337.java @@ -1,6 +1,11 @@ package org.eclipse.swt.snippets; -// IN PROGRESS +/* + * SWT_AWT example snippet: launch SWT from AWT and keep both active + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ import java.awt.BorderLayout; import java.awt.Canvas; @@ -8,7 +13,6 @@ import java.awt.EventQueue; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; - import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; @@ -18,65 +22,51 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.awt.SWT_AWT; import org.eclipse.swt.browser.Browser; import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.*; public class Snippet337 { - static Display display; - - static boolean exit; - - public Snippet337() { - JFrame frame = new JFrame("Main Window"); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - JPanel mainPanel = new JPanel(); - mainPanel.setLayout(new FlowLayout()); - - JButton launchBrowserButton = new JButton("Launch Browser"); - launchBrowserButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - JFrame f = new JFrame(); - f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - final Canvas canvas = new Canvas(); - f.setSize(850, 650); - f.getContentPane().add(canvas); - f.setVisible(true); - display.asyncExec(new Runnable() { - public void run() { - Shell shell = SWT_AWT.new_Shell(display, canvas); - shell.setSize(800, 600); - Browser browser = new Browser(shell, SWT.NONE); - browser.setLayoutData(new GridData(GridData.FILL_BOTH)); - browser.setSize(800, 600); - browser.setUrl("http://www.google.com"); - shell.open(); - } - }); - } - }); - launchBrowserButton.setActionCommand("launchbrowser"); +public static void main(String args[]) { + final Display display = new Display(); - mainPanel.add(new JTextField(15)); - mainPanel.add(launchBrowserButton); + EventQueue.invokeLater(new Runnable() { + public void run() { + JFrame mainFrame = new JFrame("Main Window"); + mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + JPanel mainPanel = new JPanel(); + mainPanel.setLayout(new FlowLayout()); + JButton launchBrowserButton = new JButton("Launch Browser"); + launchBrowserButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + JFrame childFrame = new JFrame(); + final Canvas canvas = new Canvas(); + childFrame.setSize(850, 650); + childFrame.getContentPane().add(canvas); + childFrame.setVisible(true); + display.asyncExec(new Runnable() { + public void run() { + Shell shell = SWT_AWT.new_Shell(display, canvas); + shell.setSize(800, 600); + Browser browser = new Browser(shell, SWT.NONE); + browser.setLayoutData(new GridData(GridData.FILL_BOTH)); + browser.setSize(800, 600); + browser.setUrl("http://www.eclipse.org"); + shell.open(); + } + }); + } + }); - frame.getContentPane().add(mainPanel, BorderLayout.CENTER); - frame.pack(); - frame.setVisible(true); - } - - - public static void main(String args[]) { - display = new Display(); - EventQueue.invokeLater(new Runnable() { - public void run() { - new Snippet337(); - } - }); - while (!exit) { - if (!display.readAndDispatch()) display.sleep(); + mainPanel.add(new JTextField("a JTextField")); + mainPanel.add(launchBrowserButton); + mainFrame.getContentPane().add(mainPanel, BorderLayout.CENTER); + mainFrame.pack(); + mainFrame.setVisible(true); } - display.dispose(); + }); + while (true) { + if (!display.readAndDispatch()) display.sleep(); } -}
\ No newline at end of file +} + +} |