When I run this program, it complies fine, but gives me this errorwhen it runs:
ID: 3618140 • Letter: W
Question
When I run this program, it complies fine, but gives me this errorwhen it runs:java.lang.NoSuchMethodError: MovingCircle.<init>(DIIDD)V
atFallingCircle.<init>(FallingCircle.java:40)
at FallingCircle.main(FallingCircle.java:28)
Here are the Codes:
MovingCircle:
import java.awt.*;
public class MovingCircle {
private double xposition; // position of center ofcircle
private double yposition; // position of center ofcircle
private double move_x; //amount circle moves in Xdirection
private double move_y; //amount circle moves in Ydirection
private int Diameter; //size of circle
public MovingCircle (double xposition, int yposition, intdiameter, double deltax, double deltay)
{
xposition = xposition;
yposition = yposition;
move_x = deltax;
move_y = deltay;
Diameter = diameter;
}
public void move()
{
xposition = move_x + xposition;
yposition = move_y + yposition;
}
public void paint(Graphics g)
{
g.drawOval((int) xposition,(int) yposition, (int) Diameter, (int) Diameter);
}
}
FallingCircle:
//
// This program displays falling circles in a window.
// The user can optionally specify:
// 1. x and y position of window
// 2. width and height of window
// 3. diameter of circles,
// number of millisecondsto sleep between drawings,
// probability ofcreating circle at each re-draw
//
import java.awt.*;
public class FallingCircle extends Frame
{
private MovingCircle circle;
// constants, including default values for the instancevariables
private static final int DEFAULT_WINDOW_XPOS =0;
private static final int DEFAULT_WINDOW_YPOS =0;
private static final int DEFAULT_WINDOW_WIDTH =400;
private static final int DEFAULT_WINDOW_HEIGHT =300;
private static final int DEFAULT_CIRCLE_DIAMETER= 20;
private static final int DEFAULT_SLEEP_TIME =100;
public static void main(String[] args)
{
FallingCircle frame =new FallingCircle();
frame.run();
}
/*
* Constructor for the animation.
*
* Sets up the window: location, size, color, title.
*/
private FallingCircle()
{
circle= newMovingCircle((double)DEFAULT_WINDOW_WIDTH * Math.random(),
(int)0,
DEFAULT_CIRCLE_DIAMETER,
(double)10 * Math.random() - 5,
(double)3 * Math.random() + 3);
this.setTitle("LoneFalling Circle");
this.setLocation(DEFAULT_WINDOW_XPOS,
DEFAULT_WINDOW_YPOS);
this.setSize(DEFAULT_WINDOW_WIDTH,
DEFAULT_WINDOW_HEIGHT);
this.setBackground(Color.white);
this.setVisible(true);
}
/*
* Run the animation.
*
* This must be an instance method because it callsrepaint(), which is
* an inherited instance method.
*/
private void run()
{
while (true)
{
// move the circle
circle.move();
// tell Java to call mypaint() method
repaint();
// sleep for a while
try
{
Thread.sleep(DEFAULT_SLEEP_TIME);
}
catch (InterruptedException e)
{
System.out.println("Sleep interrupted: " + e.getMessage());
System.exit(0);
}
}
}
/**
* Paint all circles.
*
* @param g Graphicscontext for the window.
*/
public void paint(Graphics g)
{
circle.paint(g);
}
}
Explanation / Answer
please rate - thanks works fine for me it appears you don't have Moving circle compiled, because FallingCircle is saying it can't find MovingCircle Make sure they are in the same directory open MovingCircle CompileMovigCircle open FallingCircle CompileFallingCircle run FallingCircle
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.