This week's book giveaway is in the Spring forum.We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Tim Cooke
• Ron McLeod
• Jeanne Boyarsky
• Paul Clapham
Sheriffs:
• Liutauras Vilda
• Henry Wong
• Devaka Cooray
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Tim Holloway
• Al Hobbs
• Carey Brown
Bartenders:
• Piet Souris
• Mikalai Zaikin
• Himai Minh

# Applet to draw Ellipse

Greenhorn
Posts: 6
• Number of slices to send:
Optional 'thank-you' note:
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.

author
Posts: 14112
• Number of slices to send:
Optional 'thank-you' note:
What error message(s) do you get?

Stephanie Maven
Greenhorn
Posts: 6
• Number of slices to send:
Optional 'thank-you' note:
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.

Ranch Hand
Posts: 1535
• Number of slices to send:
Optional 'thank-you' note:
Try removing the dot "." from the class name.

Stephanie Maven
Greenhorn
Posts: 6
• Number of slices to send:
Optional 'thank-you' note:
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
Posts: 6
• Number of slices to send:
Optional 'thank-you' note:
If anyone can tell me why I needed to remove the dot, it might help me in the future too, thanks

Ilja Preuss
author
Posts: 14112
• Number of slices to send:
Optional 'thank-you' note:
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...

 Consider Paul's rocket mass heater.