Results 1 to 9 of 9

Thread: abstract method

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    222

    abstract method

    I found that abstract method can't be implemented in the same class it defined.
    But I see in java.awt.Graphics the following functions

    fillOval....

  2. #2
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: abstract method

    Abstract classes CAN and most often do have concrete methods like that. Just because it's an abstract class doesn't mean it has to have only abstract methods.

  3. #3
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: abstract method

    I don't get the question here.


    Yes Graphics is an abstract class, and fillOval is an abstaract method. So you can not make an instance of the Graphics file your self. But widgets can make it for you, like in the paint method.


    - ØØ -

  4. #4
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: abstract method

    Hmm, so fillOval() IS an abstract method...That's confusing to me. Somewhere along the line this method is made concrete, and is given the code to perform it's operation, but where? It's not in the Graphics class? And you surely aren't required to come up with your own implementation.

  5. #5
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: abstract method

    The graphics in Java and it events is the two things that bugs me the most except the speed with Java. I am not sure if it is me never taking the time to understand it, or if it is just very weird.


    I guess there is some casting or some trick there that I have never looked into. But at least you can't make your own instance of the graphics object. At least not straight forward.


    [Edit] As a wild guess without looking into it any furuther, I guess they do something like this. Lets say A is a base class, and B inheriths from A. Then they do something like:

    A g = new B();

    and then send you g. That is a pointer of type a (or a graphics object) but actualy is an object furuther down the hierarchy.

    - ØØ -
    Last edited by NoteMe; Jul 22nd, 2005 at 02:34 AM.

  6. #6
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: abstract method

    You can always grab a graphics contecxt via getGraphics() if you want. Pretty sure it's defined in java.awt.Component

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: abstract method

    The paint() method gives you a Graphics reference, but the actual type is probably com.sun.awt.graphics.Graphics or whatever - the thing is, you just don't care as long as it works.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    222

    Re: abstract method

    I see java.awt.Graphics only extends Java.lang.Object.
    And it is defined there procedures like
    public abstract void fillOval()
    then where are the implements of the procedures?

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: abstract method

    In classes you'll never know about. I believe the Sun JRE implements them in, for example, com.sun.awt.win32.Graphics2d. The Kaffee project elsewhere, as does the GNU Classpath project. But that's not your concern. Your concern is that, upon calling Component.getGraphics(), you receive an instance of a subclass of Graphics, which you can do stuff with.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width