Graphics g = null

Discussion in 'Java' started by bob8000, Mar 17, 2007.

  1. bob8000

    bob8000 Guest

    Hello to All

    Could someone tell me why

    Graphics g = getGraphics();

    would equal zero

    I know it should equal something like

    sun.java2d.SunGraphics2D[some other stuff in here]


    I am completly stumped on this one


    BOB8000
     
    bob8000, Mar 17, 2007
    #1
    1. Advertising

  2. bob8000

    Efi Merdler Guest

    bob8000 wrote:
    > Hello to All
    >
    > Could someone tell me why
    >
    > Graphics g = getGraphics();
    >
    > would equal zero
    >
    > I know it should equal something like
    >
    > sun.java2d.SunGraphics2D[some other stuff in here]
    >
    >
    > I am completly stumped on this one
    >
    >
    > BOB8000


    Hi,
    Make sure you are calling getGraphics after the form was initialized
    and displayed.

    Efi
     
    Efi Merdler, Mar 17, 2007
    #2
    1. Advertising

  3. bob8000 wrote:
    > Hello to All
    >
    > Could someone tell me why
    >
    > Graphics g = getGraphics();
    >
    > would equal zero
    >
    > I know it should equal something like
    >
    > sun.java2d.SunGraphics2D[some other stuff in here]
    >
    >
    > I am completly stumped on this one
    >
    >
    > BOB8000
    >


    Are you calling getGraphics() on a Component? Is it visible? Do you
    know where to find the API documentation?

    --

    Knute Johnson
    email s/nospam/knute/
     
    Knute Johnson, Mar 17, 2007
    #3
  4. bob8000

    Nigel Wade Guest

    bob8000 wrote:

    > Hello to All
    >
    > Could someone tell me why
    >
    > Graphics g = getGraphics();


    Called on what?
    Has whatever you are invoking the method on been realized? A component which
    hasn't yet been realized has no Graphics, and getGraphics() will return null.

    >
    > would equal zero


    zero, or null? It should never be zero.

    >
    > I know it should equal something like
    >
    > sun.java2d.SunGraphics2D[some other stuff in here]



    --
    Nigel Wade, System Administrator, Space Plasma Physics Group,
    University of Leicester, Leicester, LE1 7RH, UK
    E-mail :
    Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
     
    Nigel Wade, Mar 19, 2007
    #4
  5. PÃ¥ Sat, 17 Mar 2007 17:08:37 +0100, skrev bob8000 <>:

    > Could someone tell me why
    >
    > Graphics g = getGraphics();
    >
    > would equal zero


    You mean null? getGraphics() returns null until the component has a
    "peer". If you need to pick it up for some code, either do so in
    addNotify() or in paint()/paintComponent(), though the latter might be
    "too late" for your needs.
     
    Tor Iver Wilhelmsen, Mar 22, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kivak Wolf
    Replies:
    2
    Views:
    10,094
    Kivak Wolf
    Jun 28, 2005
  2. vizlab
    Replies:
    3
    Views:
    4,233
    Michael Bar-Sinai
    Oct 17, 2007
  3. Replies:
    16
    Views:
    7,368
    Mike Schilling
    Oct 12, 2005
  4. Martijn Mulder

    graphics.setClip(null)

    Martijn Mulder, Mar 1, 2006, in forum: Java
    Replies:
    4
    Views:
    904
    Monique Y. Mudama
    Mar 1, 2006
  5. Replies:
    5
    Views:
    26,906
    Mike Schilling
    Mar 29, 2006
Loading...

Share This Page