wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Applet to draw Ellipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Applet to draw Ellipse" Watch "Applet to draw Ellipse" New topic
Author

Applet to draw Ellipse

Stephanie Maven
Greenhorn

Joined: Oct 15, 2005
Posts: 6
I am taking a beginner course and just started today to read about applets and graphics. This is not homework, I am creating this for practice as I read the chapter. I followed an example of an applet to draw a rectangle:

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;

/**
An applet that draws two rectangles.
*/
public class RectangleApplet extends Applet
{
public void paint(Graphics g)
{

Graphics2D g2 = (Graphics2D)g;


Rectangle cerealBox = new Rectangle(5, 10, 20, 30);
g2.draw(cerealBox);
}
}

and created one to draw an Ellipse:

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;

/**
An applet that draws an ellipse.
*/

public class Ellipse2D.DoubleApplet extends Applet

{
public void paint(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;

Ellipse2D.Double easterEgg = new Ellipse2D.Double(5, 10, 15, 20);

g2.draw(easterEgg);
}
}

but it doesn't compile. I imagine the error is very simple! But I am totally new to this so I apologize for such a basic question. Is my class worng? Thanks for any help.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
What error message(s) do you get?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Stephanie Maven
Greenhorn

Joined: Oct 15, 2005
Posts: 6
the error mess age is - '{' expected

on this line

public class Ellipse2D.DoubleApplet extends Applet

and even though I am so new! I am pretty sure I don't put a bracket before or at the end of that line, the other examples don't have one.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Try removing the dot "." from the class name.
Stephanie Maven
Greenhorn

Joined: Oct 15, 2005
Posts: 6
Wow, that worked, thanks! I drew and ecllipse!

I don't understand why it worked, however, both the textbook and the API documentation shows it with a dot.

I'll carry on - I am sure I will be back. Thanks for the help. This is very frustrating to learn!
Stephanie Maven
Greenhorn

Joined: Oct 15, 2005
Posts: 6
If anyone can tell me why I needed to remove the dot, it might help me in the future too, thanks
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
The dot is already used to separate packages. "Ellipse2D.DoubleApplet" means "the DoubleApplet in the Ellipse2D package. That's why it isn't allowed to use the dot in a class name. Don't know why the error message is so strange, though...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Applet to draw Ellipse