applet - Java: Parallel moving balls -


I have created a program in Java that is considered to be 10 balls appearing and running randomly, ball-threads Is considered to run in parallel, unfortunately the program does not compile. Does anyone know why? I get the following error for each thread:

  package movement; Import java.applet.Applet; Import java.awt. *; Import java.util.ArrayList; Import java.util.Iterator; Import java.util.Random; Public class ball {int x; Int y; Int radius = 10; Public graphics; Int DX, DI, N = 0; Ball (int x, int y) {this.x = x; this. Y = y; } Public Zero Step () {Random randomX = New Random (); Random random Y = new random (); Random randomN = new random (); Colour(); Try {Thread.sleep (10); } Grip (Interrupted E) E. {// TODO Auto-Generated Catch Block e.printStackTrace (); } X = x + dx; Y = y + dy; Dx = (int) (Math.pow (-1, n) * randomX.nextInt (5)); Dy = (int) (Math.pow (-1, n) * randomY.nextInt (5)); N = randomN.nextInt (10) + 1; } Public zero color () {g.setColor (Color.black); Gifil (x + 100, y + 100, radius, radius); }}   
  package movement; Class BallMovement Runnabel {Private Final Ball Ball; Ball movement (ball ball) {this.ball = ball; } @ Override Public Wide Run (While {true} {ball.move (); Try {Thread.sleep (20); } Grip (Interrupted E) E. {// TODO Auto-Generated Catch Block e.printStackTrace (); }}}}   
  package movement; Import java.applet.Applet; Import java.awt.color; Import java.awt.Graphics; Import java.util.Iterator; Import java.util.list; Import java.util.ArrayList; Import java.util.Random; Public Class introduction company extends applet {public Inc. startX, startY; Personal fixed final end nbBalles = 10; Private static last long serial VERSIONUID = 1 L; ArrayList & LT; Ball & gt; Balllist = new arrelisted & lt; Ball & gt; (); @ Override Public White Invite (for (Int i = 0; I & lt; nbBalles; i ++) {Random RandX = New Random (Random); Random RandY = New Random (); StartX = randX.nextInt (500 ) + 1; StartY = randY.nextInt (500) + 1; BallList.add (new ball (startx, start));} @ Override public zero start () {Etherator  gt = this = balllist. Director (); while (this haas next ()) {ball ball = it.next (); thread thread = new thread (new ballmov (ball)); thread.start ();}} @ override public void stop () {// TODO itself generated and Exemptions: Thread-5 "Java.lang.NullPointerException movement.Ball.paint (Ball.java 40) ) In the movement. Ball in movement. Ball (ball. Java 23). BallMovement.java.1 java.lang. Thread.run (Thread.java:695)    

zero color (graphics g) from the graphics object applet .

  applet launching public class {public Inc. startX, startY; Personal fixed final end nbBalles = 10; Private static last long serial VERSIONUID = 1 L; ArrayList & LT; Ball & gt; Balllist = new arrelisted & lt; Ball & gt; (); ... @ Override Public Wide Paint (Graphics G) {for (Ball Ball: BallList) {ball.paint (g); }}}   

and in the ball, change the color () method to paint (graphics g) . Do not call move () from and color () , and graphics to The ball is not in the class.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -