# \[SOLVED\] How to add ID to a shape (Java)?

**URL:** <https://discourse.processing.org/t/solved-how-to-add-id-to-a-shape-java/12155>\
**Category:** Coding Questions\
**Created:** [June 18, 2019, 3:10pm UTC](https://discourse.processing.org/t/solved-how-to-add-id-to-a-shape-java/12155 "2019-06-18T15:10:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![NadeW](https://avatars.discourse-cdn.com/v4/letter/n/ac8455/32.png) [@NadeW](https://discourse.processing.org/u/NadeW)\
**Post date:** [June 18, 2019, 3:10pm UTC](https://discourse.processing.org/t/solved-how-to-add-id-to-a-shape-java/12155/1 "2019-06-18T15:10:34Z")

</div>

Hello I am unsure how to assign an ID to a specific shape. The idea is that every mousePressed will draw a circle in a grid, and I want to be able to tell which circle was drawn 1st, 2nd, 3rd etc. This is because I want to draw a line segment between 2 specific circles I choose. But I’m not sure how to do this.

Perhaps someone could refer me to a handy library to use, or some other method of doing this? I had a thought of using images instead of shapes, but i still don’t know how to assign unique IDs.

For reference, this is an idea of the grid:

 ![qweqweq](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/b65b58af2ca48330b0938c9f37252e794cc046b5.png)

Much thanks!

Update: Problem solved with reference to [https://processing.org/tutorials/arrays/](https://processing.org/tutorials/arrays/). 🙂

---

<div class="post-metadata">

**Author:** ![humayung](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humayung/32/6089_2.png) [@humayung](https://discourse.processing.org/u/humayung)\
**Post date:** [June 18, 2019, 4:02pm UTC](https://discourse.processing.org/t/solved-how-to-add-id-to-a-shape-java/12155/2 "2019-06-18T16:02:42Z")

</div>

have you tried working with class?

---

<div class="post-metadata">

**Author:** ![NadeW](https://avatars.discourse-cdn.com/v4/letter/n/ac8455/32.png) [@NadeW](https://discourse.processing.org/u/NadeW)\
**Post date:** [June 19, 2019, 1:51am UTC](https://discourse.processing.org/t/solved-how-to-add-id-to-a-shape-java/12155/3 "2019-06-19T01:51:03Z")

</div>

Nope. How would I go about using it to assign unique IDs?

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [June 19, 2019, 3:42am UTC](https://discourse.processing.org/t/solved-how-to-add-id-to-a-shape-java/12155/4 "2019-06-19T03:42:54Z")

</div>

how about:  
on each mouse click store the position info as  
[https://processing.org/reference/PVector.html](https://processing.org/reference/PVector.html)  
to a array  
[https://processing.org/reference/Array.html](https://processing.org/reference/Array.html)

the pointer to the array is your ID?

* * *

that array you can use to draw for example: shapes…  
[https://processing.org/reference/PShape\_beginShape\_.html](https://processing.org/reference/PShape_beginShape_.html)

* * *

in this version you would not need a CLASS ( if that is unwanted )

---

<div class="post-metadata">

**Author:** ![NadeW](https://avatars.discourse-cdn.com/v4/letter/n/ac8455/32.png) [@NadeW](https://discourse.processing.org/u/NadeW)\
**Post date:** [June 19, 2019, 5:09am UTC](https://discourse.processing.org/t/solved-how-to-add-id-to-a-shape-java/12155/5 "2019-06-19T05:09:12Z")

</div>

Interesting suggestion, I’ll try it out. Thanks!
