Page 2 of 2 FirstFirst 12
Results 21 to 29 of 29
Like Tree5Likes

Thread: Null Pointer Exception in awt interface

  1. #21
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    5

    Default Re: Null Pointer Exception in awt interface

    In reality I just wanted to launch this code -- and use it as the pattern-- so I think it is betetr to
    start from the scratch almost -- In reality I need to draw the Rectangle with different diension, colour, and thickness.
    So I want to use not abstract Rectangle2D but Rectangle2D.dounle. So I would like to create the Rectangle class,
    then create Mainview for entering inputing, then Rectangle view for the diplaying rectangle, and controler that is most unknown for me.
    In this light I think I need to use (double) type cast for input, but how should user enter the colour -- simply --blue or "blue"?
    I think I create this rectangle class with 4 main fileds. X1, Y1, X2 (we find width by X2-X1), Y2. Then create View, then I need the controlelr to unite it, and main app. In this case I will put all classes in one folder(pakket). And It will be easy then to search not mine code.

  2. #22
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    5

    Default Re: Null Pointer Exception in awt interface

    "You set a Graphics object g to null" -- so what is correct way to set it not to null?

  3. #23
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Null Pointer Exception in awt interface

    Read Jos' latest response (reply #21) :)

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #24
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    5

    Default Re: Null Pointer Exception in awt interface

    But it is improbably to extends the Rectangle2D.Double, just simply Rectangle2D and I need to override the banch of not needed methods?
    And this Fill Rectangle2D.Double and Ellipse2D.Double : Shape¬*¬ę¬*2D Graphics GUI¬*¬ę¬*Java link is the pattern and the source for the decomposition for model, view and controller classes. Except the difficulties of abstract classes. Or there are alternatives?

  5. #25
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    5

    Default Re: Null Pointer Exception in awt interface

    Realy there are a lot of different methods should I override all ones?
    Should I extend my class (f.e. Recty) on Rectangle2D? O maybe I simply use Recty rrr=new Rectangle2D.Double(x1, y1, x2, y2);

  6. #26
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    5

    Default Re: Null Pointer Exception in awt interface

    Yes it is possible to extend the Rectangle2d.Double so I could absolve of overriding the whole list of methods. So was the mistake of my co-student, as there is Line2D.double class.
    But, I need some assistance just even now. If I create the MainView class for entering the coordinates and filling of Rectangle, should I create particular class for the view of rectangule (i.e. the lineview in aforementioned example).
    That was probably main issue in precedent example.

  7. #27
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Null Pointer Exception in awt interface

    Look, it's quite simple.
    As Darryl says, read the tutorial he posted.

    The key point for custom painting is to override paintComponent (which you have done), but you call repaint() (which has no parameters) when you want to redraw that component. That tells Swing to queue up a redraw. You do not call paintComponent directly. That's not your job. That's Swings job.
    gimbal2 likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #28
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Null Pointer Exception in awt interface

    Quote Originally Posted by Tolls View Post
    Look, it's quite simple.
    As Darryl says, read the tutorial he posted.

    The key point for custom painting is to override paintComponent (which you have done), but you call repaint() (which has no parameters) when you want to redraw that component. That tells Swing to queue up a redraw. You do not call paintComponent directly. That's not your job. That's Swings job.
    I'm getting a feeling of deja vu.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  9. #29
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Null Pointer Exception in awt interface

    Quote Originally Posted by jim829 View Post
    I'm getting a feeling of deja vu.

    Regards,
    Jim
    Again?

    (ho ho)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Page 2 of 2 FirstFirst 12

Similar Threads

  1. null pointer exception
    By raymasuku in forum Enterprise JavaBeans (EJB)
    Replies: 6
    Last Post: 11-28-2013, 10:57 AM
  2. Null Pointer Exception
    By jameshl2008 in forum New To Java
    Replies: 6
    Last Post: 10-22-2013, 02:56 PM
  3. Why I am getting null pointer exception?
    By ashvini in forum New To Java
    Replies: 6
    Last Post: 04-03-2013, 06:02 PM
  4. Null Pointer Exception
    By jonytek in forum New To Java
    Replies: 5
    Last Post: 03-02-2011, 07:16 AM
  5. null pointer exception
    By jyothi.priyanka in forum New To Java
    Replies: 12
    Last Post: 03-11-2009, 05:04 PM

Tags for this Thread

Posting Permissions

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