Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualburnt_casadilla

Posted 07 August 2012 - 05:44 PM

alright i added this to the beginning of my program.

[source lang="java"]class Ball extends Ellipse2D.Float//class to store the ball { private int diameter = 20;//diameter of ball private int d; public Ball(int diameter) { super((int)(Math.random() * (400 - 20)+ 1), (int)(Math.random() * (400 - 20) + 1), diameter, diameter);//create random points to spawn the ball this.d = diameter; } } class PaintSurface extends JComponent//class to draw the ball { public ArrayList<Ball> Balls = new ArrayList<Ball>();//arraylist to store 10 balls public PaintSurface() { for (int i = 0; i < 10; i++) Balls.add(new Ball(20));//add new ball to the arraylist up to 10 } public void paintBalls (Graphics g) { Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.red); for (Ball Ball : Balls) { g2.fill(Ball);//supposed to draw balls on the screen } } }[/source]

still doesnt work....

with this im just trying to add 10 balls at random places on the screen. seems simple enough

#2burnt_casadilla

Posted 07 August 2012 - 05:40 PM

alright i added this to the beginning of my program.

[source lang="java"]class Ball extends Ellipse2D.Float { private int diameter = 20; private int d; public Ball(int diameter) { super((int)(Math.random() * (400 - 20)+ 1), (int)(Math.random() * (400 - 20) + 1), diameter, diameter); this.d = diameter; } } class PaintSurface extends JComponent { public ArrayList<Ball> Balls = new ArrayList<Ball>(); public PaintSurface() { for (int i = 0; i < 10; i++) Balls.add(new Ball(20)); } public void paintBalls (Graphics g) { Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.red); for (Ball Ball : Balls) { g2.fill(Ball); } } }[/source]

still doesnt work....

with this im just trying to add 10 balls at random places on the screen. seems simple enough

#1burnt_casadilla

Posted 07 August 2012 - 05:37 PM

alright i added this to the beginning of my program.

[source lang="java"]class Ball extends Ellipse2D.Float { private int diameter = 20; private int d; public Ball(int diameter) { super((int)(Math.random() * (400 - 20)+ 1), (int)(Math.random() * (400 - 20) + 1), diameter, diameter); this.d = diameter; } } class PaintSurface extends JComponent { public ArrayList<Ball> Balls = new ArrayList<Ball>(); public PaintSurface() { for (int i = 0; i < 10; i++) Balls.add(new Ball(20)); } public void paintBalls (Graphics g) { Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.red); for (Ball Ball : Balls) { g2.fill(Ball); } } }[/source]

still doesnt work....

PARTNERS