# Drawing a board using GUI

**URL:** <https://discourse.processing.org/t/drawing-a-board-using-gui/34276>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [December 24, 2021, 8:19am UTC](https://discourse.processing.org/t/drawing-a-board-using-gui/34276 "2021-12-24T08:19:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![f.y](https://avatars.discourse-cdn.com/v4/letter/f/90db22/32.png) [@f.y](https://discourse.processing.org/u/f.y)\
**Post date:** [December 24, 2021, 8:19am UTC](https://discourse.processing.org/t/drawing-a-board-using-gui/34276/1 "2021-12-24T08:19:31Z")

</div>

Hello, below is a code I wrote to draw a board using GUI. I want to locate the board in the center of my screen but I don`t know-how. Can someone help, please?  
And, can you tell me how can I get access to each of the cells in the grid?

import processing.core.\*;

import javax.swing.\*;

public class Problem05 extends PApplet {

```
float scale = height / 2f;
float size;
float x = width / 7f;
float y = height / 6f;
float r;
float c;

public void settings() {

    fullScreen();
}

public void setup() {
    try {

        String boardSize = JOptionPane.showInputDialog("Enter the board`s size[4,12]: ");
        size = Float.parseFloat(boardSize);
    } catch (NumberFormatException e) {
        JOptionPane.showMessageDialog(null, "incorrect input");
        System.exit(1);

    }
    if (size < 4 || size > 12) {
        JOptionPane.showMessageDialog(null, "incorrect input");
        System.exit(1);

    }

}

public void draw() {
    background(0, 0, 0);

    for (int i = 0; i < size; i++) {
        for (int j = 0; j < size; j++) {
            x = i * scale;
            y = j * scale;

            if ((i % 2 == 0) == (j % 2 == 0)) {
                fill(24, 77, 51);
            } else {
                fill(255, 255, 255);
            }
            stroke(0, 70, 0);
            rect(x + width / 3f, y + height / 6f, scale, scale);
  }
    }
}

public static void main(String[] args) {
    PApplet.main("Problem05");
}

```

}

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [December 24, 2021, 10:58am UTC](https://discourse.processing.org/t/drawing-a-board-using-gui/34276/2 "2021-12-24T10:58:34Z")

</div>

Hello,

Your focus should be x and y offset here:

`rect(x + width / 3f, y + height / 6f, scale, scale);`

The offset will change with the variable `size`.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/7d4b0cbef3ad45e82b4a6305c22f8583f8b158fe.png) ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/834a0e36c27ec1fda9bae283635075839ed5436f.png)

Give it some thought and experiment a little.

`:)`

---

<div class="post-metadata">

**Author:** ![f.y](https://avatars.discourse-cdn.com/v4/letter/f/90db22/32.png) [@f.y](https://discourse.processing.org/u/f.y)\
**Post date:** [December 25, 2021, 1:42pm UTC](https://discourse.processing.org/t/drawing-a-board-using-gui/34276/3 "2021-12-25T13:42:05Z")

</div>

done thank you very much
