Win a copy of Functional Design and Architecture this week in the Functional programming 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Graphic 2d: differentiating between objects

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7089
165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3244
30
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
You showed up just in time for the waffles! And this 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