• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

drawing lines with mouse

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I still have the error of NullPointerException for the following code (to draw on the the panel just with mouse press and release). i have four classes, the error is at DrawPanel class when i create an object of class MyLine, i don't know why
the following is the main abstract class



the next is the class for drawing lines




the following is the panel class to draw on



finally is the test for the code

 
Rancher
Posts: 3265
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you create the DrawPanel class your Points array is empty.

 
Mohamad Samy
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but i first declared any array of points before the constructor as Point [] points = new Point[10000]; which will be initiated in the constructor when the mouse is pressed and released. please, indicate more am i right!!
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're allocating the array, but that array is empty as Rob said - there are no Point objects in it. You need to check for that before you try to use any array elements.
 
Mohamad Samy
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, i removed all this array and replaced it by integers for the coordintaes like integers x1, y1 and x2, y2 and the error is removed by still displaying the panel without the capablility for drawing lines, !!!
so, i replaced the line drawing using MyLline class object by the simple and it works but i want to use MyLine class object in my paint component method
 
Mohamad Samy
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks alot with your responses. i solved the problem which was in my MyLine class as i tried to use it directly where i should use it polymorphically as all the variables become a part of Shape class when i declared the the MyLine object in the DrawPanel class. i will convert the code then to use points instead of the exact integers. thanks again
 
Time flies like an arrow. Fruit flies like a banana. Steve flies like a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic