Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Graphic 2d: differentiating between objects

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I try to use graphic2d to make objects .  How can we differentiate the variable between 2 object that we created. For example the below code;




from above code,i have 2 rectangle variable , which is r1 and r2, and i can differentiate between them and i can do
"if (r1.intersects(r2))" in the actionPerformed method.

So my question is;

how about below code when using Graphic2d, how can i differentiate between these 2 triangle,
so that it can fit into "if (r1.intersects(r2))", as only one variable "lukis" only exist and it is used to make 2 triangle.

How can i make it so that it can fit into(......intersects(.....) ), meaning what variable should i put into these 2 dots area?




Thank you.
 
Saloon Keeper
Posts: 6650
161
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create two java.awt.Polygon objects (you already have all the data structures you need for that), and then use the Graphics.drawPolygon(Polygon) method to draw them.
 
Rancher
Posts: 3210
29
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quit cross posting: https://stackoverflow.com/questions/63929497/java-how-to-differentiate-2d-object

You were given the same answer yesterday.

Its frustrating when we take the time to help and you completely ignore the advice given.

 
There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic