Drawing circle in Java

Bluga

Banned
Nov 28, 2000
4,315
0
0

i'm given an interface below to implement :

package presentation;

public interface Drawable {

public void drawMe( java.awt.Graphics2D g );
}


When asked to draw itself, the beach ball draws a red circle in the bottom-right corner of the room. Is something wrong with my code below?

package contents;

import java.awt.*;
import presentation.*;

public class BeachBall implements presentation.Drawable{




public void drawMe( java.awt.Graphics2D g ){

setColor(red);
drawOval(10, 10, 9, 9);
}



}
 

Spydermag68

Platinum Member
Apr 5, 2002
2,615
98
91
Here is some code that I wrote to draw some circles.

import java.awt.*;

import javax.swing.*;

public class Circles extends JFrame
{
public Circles()
{
super("8 Circles");
setSize(300,300);
setVisible( true );
}

public void paint (Graphics g)
{
super.paint(g);

int pos = 100; // starting point for x and y position
int radius = 100; // starting radius for circle
int addRadius = 20; // increase radius of circle
int minusPos = 10; // move starting point back by half of radius increase

g.setColor(Color.blue);
for (int i = 0; i < 8; i++)
{
g.drawOval(pos, pos, radius, radius);
pos -= minusPos;
radius += addRadius;
}
}
public static void main(String args[])
{
Circles application = new Circles();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

}