Results 1 to 6 of 6
  1. #1
    rdjava's Avatar
    rdjava is offline Member
    Join Date
    Jan 2011
    Posts
    38
    Rep Power
    0

    Default Graphics with floating points instead of Integers

    I think i forgot to actually post this last time but anyways my question is I want to know if there is a way to use some kind of graphics where I don't have to use integers, for example

    g.fillOval(int w, int h, int x, int y);

    I want to know if there is someway to be able to use say doubles or floating point integers. Is there some special package for this? would OpenGL be good to use?

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    See the API for shape: Shape (Java Platform SE 6)
    In particular, the classes which implement the interface, many of which take double or float values and since they implement the Shape interface, can be drawn using Graphics2D.draw or fill methods

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default

    Read the API for Graphics2D and go through the tutorial:
    Trail: 2D Graphics (The Java™ Tutorials)

    Wherever a method (such as paintComponent) is passed a Graphics reference, you can safely cast the reference to Graphics2D. In all current Java versions (and some obsolete versions too) every Graphics object is a Graphics2D.

    Just remember that screen rendering is always integral, there's nothing like painting half a pixel. The illusion of fractional resolution can be created by anti-aliasing.

    db

  4. #4
    rdjava's Avatar
    rdjava is offline Member
    Join Date
    Jan 2011
    Posts
    38
    Rep Power
    0

    Default

    Quote Originally Posted by DarrylBurke View Post
    Just remember that screen rendering is always integral, there's nothing like painting half a pixel. The illusion of fractional resolution can be created by anti-aliasing.

    db
    Is there a way to use anti-aliasing with Graphics2D?

  5. #5
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    Quote Originally Posted by rdjava View Post
    Is there a way to use anti-aliasing with Graphics2D?
    Did you try google? Dozens if not hundreds of demonstrations...plus one more:
    Java Code:
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);
    //where g2d is a Graphics2D reference

  6. #6
    rdjava's Avatar
    rdjava is offline Member
    Join Date
    Jan 2011
    Posts
    38
    Rep Power
    0

    Default

    Quote Originally Posted by doWhile View Post
    Did you try google? Dozens if not hundreds of demonstrations...plus one more:
    Java Code:
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);
    //where g2d is a Graphics2D reference
    Its ok i found some good resources to work off. Thanks!

Similar Threads

  1. floating point errors
    By mikele83 in forum New To Java
    Replies: 8
    Last Post: 04-24-2011, 03:52 PM
  2. Displaying floating point value
    By NuxlyStardust in forum New To Java
    Replies: 11
    Last Post: 04-14-2011, 06:40 PM
  3. if it is floating point number
    By Stephen Douglas in forum New To Java
    Replies: 26
    Last Post: 07-06-2010, 09:17 AM
  4. a navigation bar that has floating images
    By shayz in forum Advanced Java
    Replies: 3
    Last Post: 02-07-2009, 01:52 PM
  5. Replies: 2
    Last Post: 08-24-2008, 12:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •