Results 1 to 2 of 2
  1. #1
    i4ba1 is offline Member
    Join Date
    Aug 2008
    Posts
    13
    Rep Power
    0

    Question how to link first form to second form?

    Hai all,

    i use swt framework. i create to form using swt in eclipse. in my first form i have a button. when the button is clicked, i want the second form is show and the first form is disposed. can you help me please??.

    First Class

    public class Swtapp {
    private Shell shell;
    SecondForm form;

    public Swtapp(Display display) {
    shell = new Shell(display);
    shell.setText("Button");

    initUI();

    shell.setSize(250, 200);
    shell.setLocation(300, 300);

    shell.open();

    while (!shell.isDisposed()) {
    if (!display.readAndDispatch()) {
    display.sleep();
    }
    }
    }

    public void initUI() {
    Button quit = new Button(shell, SWT.PUSH);
    quit.setText("Quit");
    quit.setBounds(50, 50, 80, 30);

    quit.addSelectionListener(new SelectionAdapter() {
    @Override
    public void widgetSelected(SelectionEvent e) {
    form.display.sleep();
    shell.getDisplay().dispose();
    //System.exit(0);
    }
    });
    }

    public static void main(String[] args) {
    Display display = new Display();
    new Swtapp(display);
    display.dispose();
    }
    }

    second class

    public class SecondForm {
    public Shell shell;
    public static Display display;

    public SecondForm()
    {

    }

    public SecondForm(Display display) {
    shell = new Shell(display);
    shell.setText("Button");

    shell.setSize(250, 200);
    shell.setLocation(300, 300);

    shell.open();

    while (!shell.isDisposed()) {
    if (!display.readAndDispatch()) {
    display.sleep();
    }
    }
    }

    public static void main(String[] args)
    {
    display = new Display();
    new SecondForm(display);
    }
    }
    Last edited by i4ba1; 11-25-2009 at 07:02 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Replies: 0
    Last Post: 10-31-2009, 10:24 AM
  2. Dynamic fields in form using Form Bean
    By janu.c in forum Java Software
    Replies: 1
    Last Post: 09-23-2009, 05:26 AM
  3. Replies: 10
    Last Post: 08-12-2009, 05:02 PM
  4. Replies: 6
    Last Post: 11-28-2008, 07:55 AM
  5. Jtree link to JFrame Form
    By daniel50096230 in forum NetBeans
    Replies: 4
    Last Post: 09-16-2008, 07:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •