FileDocCategorySizeDatePackage
SwingAWTClass.javaAPI DocExample1200Tue Mar 09 12:56:06 GMT 2004org.cookbook.ch09

SwingAWTClass.java

package org.cookbook.ch09;

import java.awt.event.*;

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.awt.SWT_AWT;

public class SwingAWTClass {

	public static void main(String[] args) {
		final Display display = new Display();
		final Shell shell = new Shell(display);
		shell.setText("Using Swing and AWT");
		shell.setSize(350, 280);
		
		Composite composite = new Composite(shell, SWT.EMBEDDED);
		composite.setBounds(20, 20, 300, 200);
		composite.setLayout(new RowLayout());

		java.awt.Frame frame = SWT_AWT.new_Frame(composite);
		java.awt.Panel panel = new java.awt.Panel();
		frame.add(panel);

	    final javax.swing.JButton button = new javax.swing.JButton("Click Me");
	    final javax.swing.JTextField text = new javax.swing.JTextField(20);

	    panel.add(button);
	    panel.add(text);

		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				text.setText("Yep, it works.");
			}
		});
	    
		shell.open();
		while(!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep();
		}
		display.dispose();
	}
}