wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes swing & awt: drawing based on pixels? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "swing & awt: drawing based on pixels?" Watch "swing & awt: drawing based on pixels?" New topic
Author

swing & awt: drawing based on pixels?

Castor Tack
Ranch Hand

Joined: Dec 06, 2010
Posts: 31
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.


The BEST user interface design I've ever seen? --- A flush toilet.
Castor Tack
Ranch Hand

Joined: Dec 06, 2010
Posts: 31
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

Joined: Dec 01, 2009
Posts: 53
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

Joined: Dec 06, 2010
Posts: 31
Ok, I think I'll first try int-based graphics, and if it doesn't work out, I'll consider switching.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: swing & awt: drawing based on pixels?