geting value from paintComponent
i have got a class that extends JPanel called viewPanel and in there, there is paint method.
in the paint method there is a oval point drawn on it. the coordinates x and y for the point are generated by using math.random so when the program executes the point is randomly placed on the screen and after small time interval new random coordinates are set for x and y of the point.
i have a different class which also extends JPanel called controlsPanel what i want to get is the x and y values of the point and set is as a label.
i tried creating method in the viewPanel that returns x and y but once i create an object of the viewPanel in controlsPanel and i call the method it just returns me zero.
i have also tried creating object of the controlsPanel in the viewPanel and set the x and y values as the parameters of one of the methods in the controlsPanel but i received an "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException "
it is so frustrating that i cant solve this i hope you will be able to help me.
any suggestions will be greatly appreciated thank you