[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] open a SWT form from another SWT form

Hi all

I created two SWT forms, using the VE editor class. But I did not see anywhere a place where the explain how to open a form from another form.

I have two forms:
- "one" that has only a button,
- "two", that has a lable that says "Hell World!!!"

How do I open form "two", from form "one"?

Am I missing something?

Is there any simple tutorial that explains this things, I was not able to find an explanation on the net.


Here is the source code:


------------------------------------------------ form "one" package first; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.SWT;

public class one {

	private Shell sShell = null;
	private Button btnOpen = null;

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
/* Before this is run, be sure to set up the launch configuration (Arguments->VM Arguments)
* for the correct SWT library path in order to run with the SWT dlls. * The dlls are located in the SWT plugin jar. * For example, on Windows the Eclipse SWT 3.1 plugin jar is:
* installation_directory\plugins\org.eclipse.swt.win32_3.1.0.jar
*/
Display display = Display.getDefault();
one thisClass = new one();
thisClass.createSShell();
thisClass.sShell.open();


		while (!thisClass.sShell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}

/**
* This method initializes sShell
*/
private void createSShell() {
sShell = new Shell();
sShell.setText("Shell");
sShell.setSize(new Point(300, 200));
btnOpen = new Button(sShell, SWT.NONE);
btnOpen.setBounds(new org.eclipse.swt.graphics.Rectangle(94,31,103,33));
btnOpen.setText("Open Form");
btnOpen.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
System.out.println("widgetSelected()"); // TODO Auto-generated Event stub widgetSelected()


}
});
}


}




--------------------------------------- form "two" package first;

import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Display;

public class two {

	private Shell sShell = null;
	private Label lblTwo = null;

	public two() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * This method initializes sShell
	 */
	private void createSShell() {
		sShell = new Shell();
		sShell.setText("Shell");
		sShell.setSize(new Point(300, 200));
		lblTwo = new Label(sShell, SWT.NONE);
		lblTwo.setBounds(new org.eclipse.swt.graphics.Rectangle(55,21,186,44));
		lblTwo.setFont(new Font(Display.getDefault(), "Tahoma", 18, SWT.NORMAL));
		lblTwo.setText("Hello World!!!!");
	}

}