• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet to draw Ellipse

 
Stephanie Maven
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What error message(s) do you get?
 
Stephanie Maven
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1535
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try removing the dot "." from the class name.
 
Stephanie Maven
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic