Results 1 to 2 of 2
  1. #1
    shay2 is offline Member
    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Default help with java swt :)

    I wrote Gui code in java, using the lib of swt.
    help with java swt :)-t.png
    1. How can I insert user value to my variable?
    For example, user inset his age, and I want to restore this data. How can I do it?

    2. How can I organize the groups to be one under the other?

    3. When I execute the program the window is very small and I donít see the buttons, how can I change it?

    4. How the button of "about" can be in the left corner?

    5. I have "exit" function how I can connect it to the X button on the up-right corner of the window?


    this is my code..

    import java.io.IOException;

    import org.eclipse.swt.SWT;
    import org.eclipse.swt.layout.GridLayout;
    import org.eclipse.swt.widgets.Button;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Event;
    import org.eclipse.swt.widgets.FileDialog;
    import org.eclipse.swt.widgets.Group;
    import org.eclipse.swt.widgets.Label;
    import org.eclipse.swt.widgets.Listener;
    import org.eclipse.swt.widgets.MessageBox;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.widgets.Text;



    public class GUI2
    {
    public static void main(String[] args)
    {
    Display display = new Display();

    Shell shell = new Shell(display);
    shell.setText("my progream");
    shell.open();

    /**************************group1****************** *****************************/

    Group group1 = new Group(shell, SWT.SHADOW_OUT);
    group1.setText("Step 1: Choose:");
    group1.setLayout(new GridLayout(1, true));

    //buttonCsv
    final Button button1=new Button(group1, SWT.RADIO);
    button1.setText("choice 1 ");
    //buttonTxt
    final Button button2=new Button(group1, SWT.RADIO);
    button2.setText("choice 2 ");

    Listener listener1 = new Listener()
    {
    public void handleEvent(Event event)
    {
    int user_choice;

    if(event.widget==button1)
    {
    user_choice=1;
    System.out.println(user_choice);
    }
    else if(event.widget==button2)
    {
    user_choice=2;
    System.out.println(user_choice);
    }

    }
    };
    button1.addListener(SWT.Selection, listener1);
    button2.addListener(SWT.Selection, listener1);


    /**********************group2********************** *****************************/

    Group group2 = new Group(shell, SWT.SHADOW_OUT);
    group2.setText("Step 2: Insert your age ");
    group2.setLayout(new GridLayout(1, true));
    Text textRow=new Text(group2, SWT.BORDER);
    textRow.setText(" ");



    /************************group3******************** *****************************/

    Group group3 = new Group(shell, SWT.SHADOW_OUT);
    group3.setText("Step 3: Insert your id ");
    group3.setLayout(new GridLayout(1, true));
    new Text(group3, SWT.BORDER).setText(" ");

    /************************group4******************** *****************************/

    Group group4 = new Group(shell, SWT.SHADOW_OUT);
    group4.setText("Step 4:");
    group4.setLayout(new GridLayout(1, true));

    final Button buttonGen=new Button(group4, SWT.PUSH);
    buttonGen.setText("Generate Data");

    Listener listener3 = new Listener()
    {
    public void handleEvent(Event event)
    {
    if(event.widget==buttonGen)
    {
    int user_choice=1;
    System.out.println("user_choice " + user_choice);

    }
    }
    };
    buttonGen.addListener(SWT.Selection, listener3);

    /************************buttonAbout*************** **********************************/


    final Button buttonAbout=new Button(shell, SWT.PUSH);
    buttonAbout.setText("About");

    /************************************************** ***********************/

    shell.setSize(600, 300);
    shell.pack();
    shell.setLayout(new GridLayout(2,true));


    // Set up the event loop.
    while (!shell.isDisposed()) {
    if (!display.readAndDispatch())
    {
    // If no more entries in the event queue
    display.sleep();
    }
    }
    display.dispose();
    }

    /************************************************** ********/

    public void saveFileLocation(Shell shell)
    {
    FileDialog fd=new FileDialog(shell,SWT.OPEN);
    fd.setText("open");
    fd.setFilterPath("E:/workspace/89210 part3");
    String[] filterExt = { "*.txt", "*.java", ".xml", "*.*" };
    fd.setFilterExtensions(filterExt);
    String selected = fd.open();

    }

    /************************************************** ********/

    public void exit(Shell shell)
    {
    MessageBox messageBox = new MessageBox(shell, SWT.ICON_QUESTION| SWT.YES | SWT.NO);
    messageBox.setMessage("Do you really want to exit?");
    messageBox.setText("Exiting Application");
    int response = messageBox.open();
    if (response == SWT.YES)
    System.exit(0);

    }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: help with java swt :)

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Posting Permissions

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