Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

swing & awt: drawing based on pixels?

 
Castor Tack
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all:

This is a simplified question about some gui details in Java. The background design pattern is mvc.

Assume that I need to draw a circle:


My question is: since this is just the domain model (I know this is like calling a paper bird "eagle", I just want to demonstrate the idea), I need to consider for later implementation of view and control. Do you think it makes sense to have an int variable as radius? By the way, MyPoint's x and y are also int variables.

I ask this question because I sort of recall that drawing in java is based on pixels, which are measured in int (like Dimension(int, int), drawString (int, int) ... etc). Does that mean it is better to declare radius as int variable so that I'll be able to pass radius directly to some drawing function?

Many thanks in advance.
 
Castor Tack
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something to add:
I've also found a version of drawString that takes float to indicate the locations:
Graphics2D --- drawString

So is swing/awt really based on pixels? If not, what is swing/awt base on? I'm confused.
 
Stanislav Lapitsky
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually you can use float based shapes e.g. Ellipse2D shape or define your own custom Shapes (see PathIterator interface). Just cast your Graphics to Graphics2D (normally screen graphics and printer graphics are Graphics2D) and call draw(yourShape) or fill(yourShape) or drawString() methods passing the shape.

Regards,
Stas
 
Castor Tack
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I think I'll first try int-based graphics, and if it doesn't work out, I'll consider switching.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic