I made another question about two weeks ago with having trouble with the Circle class. I couldn't exactly pinpoint a direct code to put on here to show you guys but no matter what I do with the Circle class, or any thing similar to it, I can't get the code to compile.
I have tried copying directly out of my textbook to see if the code provided by my teacher and the book will work, and I still get a "Cannot find symbol" whenever I try to create a Circle or Rectangle. Here's some code from my book for example
import javax.swing.JApplet;
import java.awt.Color;
import java.awt.Graphics;
public class Week8_ExtraCredit extends JApplet
{
private int centerX = 200, centerY = 150;
private Color toggleColor = Color.BLACK;
private Circle circle;
public void paint( Graphics g )
{
super.paint( g );
for ( int diameter = 200; diameter >= 20; diameter -= 20 )
{
circle = new Circle( centerX - diameter / 2,
centerY - diameter / 2,
diameter, toggleColor );
circle.draw( g );
if ( toggleColor.equals( Color.BLACK ))
toggleColor = Color.RED;
else
toggleColor = Color.BLACK;
}
}
}
This code is pulled directly from my book which is supposed to create a circle of with black and red rings inside of it. But running it, I get this error
C:\Users\yardeen\Documents\JCreator LE\MyProjects\Week8_ExtraCredit\src\Week8_ExtraCredit.java:17: error: cannot find symbol
private Circle circle;
^
symbol: class Circle
location: class Week8_ExtraCredit
This is given for every instance the class Circle is called upon. If I could get any help as to why I'm getting this problem, that would be awesome. This has been the only thing stumping me in learning Java so far: :\
Assuming you didn't create a Circle class as your code and the above comments suggest, here's an alternate solution (unless you're required to create your own Circle class):
Make sure you have these imports:
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
And then create an Ellipse:
Shape circle = new Ellipse2D.Double(x, y, width, height);
This line will replace your "circle = new Circle" line. Make sure x, y, width, and height are doubles, and if you want further information check out this .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.