• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Drawing circle in Java

Bluga

Banned

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);
}



}
 
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);
}

}
 
Back
Top