Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Visual Editor (VE) » VE open a form from another form
VE open a form from another form [message #109483] Thu, 13 October 2005 19:08 Go to next message
Jose is currently offline JoseFriend
Messages: 51
Registered: July 2009
Member
Hello everyone.

I am trying to understand how SWT and VE work. I created two SWT forms,
using the VE editor class, the first one has the main includes, and the
second one without main.

My goal is to call the second form, from the first one. I did not see
anywhere a place where it is explained how to open a SWT form from another
SWT 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.j ar
*/
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

// WHAT DO I NEED TO ADD HERE

}

}




--------------------------------------- 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!!!!");
}

}
Re: VE open a form from another form [message #109541 is a reply to message #109483] Thu, 13 October 2005 20:10 Go to previous message
Jeff Myers is currently offline Jeff MyersFriend
Messages: 489
Registered: July 2009
Senior Member
Jose,

See the modified versions of your classes below:


> ------------------------------------------------ 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.j ar
> */
> 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
two hello = new two();
hello.openShell();
> }
>
> }
>
>
>
>
> --------------------------------------- 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!!!!");
> }

public void openShell() {
if (sShell == null) {
createSShell();
}
sShell.open();
}

>
> }
>
>
Re: VE open a form from another form [message #611195 is a reply to message #109483] Thu, 13 October 2005 20:10 Go to previous message
Jeff Myers is currently offline Jeff MyersFriend
Messages: 489
Registered: July 2009
Senior Member
Jose,

See the modified versions of your classes below:


> ------------------------------------------------ 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.j ar
> */
> 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
two hello = new two();
hello.openShell();
> }
>
> }
>
>
>
>
> --------------------------------------- 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!!!!");
> }

public void openShell() {
if (sShell == null) {
createSShell();
}
sShell.open();
}

>
> }
>
>
Previous Topic:Mac Os X,, VE and SWT
Next Topic:VE problem with AMD 64 bits
Goto Forum:
  


Current Time: Thu Mar 28 20:10:15 GMT 2024

Powered by FUDForum. Page generated in 0.02554 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top