java - Accessing values from within a method -
the goal of program generate random centers circles , find length between centers of circles.
issue in getd1() method of values 0 (before having 50 added, length ends being 0), center1x, center1y, etc.
however in code have omitted centers assigned circles indeed drawn in random locations, know values center coordinates cannot 0.
i did try assigning values center1x, etc. initialized , error "n must positive number" suspect because there no width nor height before jframe created. suggestions appreciated.
public class draw extends jframe { public class circle extends jpanel { int center1x; int center1y; int center2x; int center2y; @override protected void paintcomponent(graphics g) { super.paintcomponent(g); random rand = new random(); center1x=rand.nextint(getwidth()-100); center1y=rand.nextint(getheight()-100); center2x=rand.nextint(getwidth()-100); center2y=rand.nextint(getheight()-100); //these coordinates of circles } public double getd1() { //distance method has been omitted, functions , not part of issue double d1 = distance(center1x+50,center1y+50,center2x+50,center2y+50); return d1; } } } ps: distance() function has been omitted since not part of issue, uses distance formula.
Comments
Post a Comment