Results 1 to 2 of 2
  1. #1
    alpvii is offline Member
    Join Date
    Apr 2010
    Posts
    1
    Rep Power
    0

    Default Tic-Tac-Toe in SWT

    How do I create the buttons with an array? I am going to do a Tic-Tac-Toe game in SWT. I guess this way is wrong?:

    import org.eclipse.swt.layout.*;
    import org.eclipse.swt.widgets.*;
    import org.eclipse.swt.events.*;
    import org.eclipse.swt.graphics.*;
    import org.eclipse.swt.*;
    import org.eclipse.swt.layout.GridData;
    import org.eclipse.swt.layout.GridLayout;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.events.SelectionEvent;
    import org.eclipse.swt.events.SelectionListener;
    import org.eclipse.swt.widgets.*;


    public class Application {

    public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Tic-Tac-Toe");

    // creates the gridlayout
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    gridLayout.marginWidth = 50;
    gridLayout.marginHeight = 50;
    gridLayout.horizontalSpacing = 10;
    gridLayout.verticalSpacing = 10;
    gridLayout.makeColumnsEqualWidth = true;
    shell.setLayout(gridLayout);

    // creates the buttons
    Button[][] button = new Button[3][3];

    shell.pack();
    shell.open();
    shell.setSize(700, 700);
    while (!shell.isDisposed()) {
    if (!display.readAndDispatch())
    display.sleep();
    }
    display.dispose();
    }
    }

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    for the button[0][0] to [0][3] you can use this example

    Java Code:
    		for (int i = 0; i < 3; i++) {
    			button[0][i] = new Button("0" + i);
    		}

Posting Permissions

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