Results 1 to 3 of 3
  1. #1
    Join Date
    May 2012
    Posts
    10
    Rep Power
    0

    Default Graphics abstract class

    hi,

    I know that the Graphics class is an abstract class.
    For that reason, normally, we can not create an instace of this class.
    Why can i code this
    Java Code:
    public void paint(Graphics g) {
    
    .....
    }
    Where the g variable has to receive the adress of an instance of the Graphics class.

    Thanks a lot for explaining it to me.

    Regards.

    curious_programmer

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

    Default Re: Graphics abstract class

    You don't call painting methods directly. You call repaint() and the GUI toolkit supplies an appropriate concrete subclass of Graphics (actually, for more than 10 years, a subclass of Graphics2D).

    Read more about it in the Tutorial Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    In future, AWT/Swing questions should be posted in the AWT/Swing section. If your question is more about Java 2D, there's a section for that too.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

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

    Default Re: Graphics abstract class

    Quote Originally Posted by curious_programmer View Post
    ... the g variable has to receive the adress of an instance of the Graphics class.
    No, the parameter has to be a reference to a Graphics instance. Not an address.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. abstract method-abstract class
    By durgaprasad1407 in forum New To Java
    Replies: 1
    Last Post: 04-29-2011, 06:58 PM
  2. Replies: 4
    Last Post: 04-14-2011, 11:42 AM
  3. How can I call abstract class methods from another class
    By srinivas2828 in forum New To Java
    Replies: 13
    Last Post: 03-12-2010, 02:33 PM
  4. Replies: 6
    Last Post: 02-11-2009, 10:51 AM
  5. Replies: 0
    Last Post: 04-02-2008, 07:04 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
  •