Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

class who implement shape, paint, draw  RSS feed

 
mark smith
Ranch Hand
Posts: 258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

i created a class who implements Shape

i would like to know what method i need to implement to be able to display the shape

is it paint, draw, paintComponent?

thanks
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Shape isn't something that can be drawn - it's just a representation of 2D points. If this is supposed to be a reusable component, then it should extend Component or JComponent. Alternatively, and less work to implement, it could extend JPanel and override its paintComponent method.
 
Rob Camick
Ranch Hand
Posts: 2801
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:A Shape isn't something that can be drawn


You can use the Graphics2D draw(Shape) and fill(Shape) methods.
 
mark smith
Ranch Hand
Posts: 258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this class is abstract...


so she should extends JCompoment and implement Shape?

does i will need to add abstract draw(Shape) in this class?
 
Rob Camick
Ranch Hand
Posts: 2801
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does i will need to add abstract draw(Shape) in this class?


That method is NOT part of the Shape interface. You need to implement the methods of the interface. I have never done this before but I would guess the getPathIterator(...) is the important one related to actually drawing the shape. So look at the code from on of the classes the implements Shape to get an idea of what the code should look like. Maybe start with the Rectangle or Elipse2D classes as they might be the simplest to understand.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!