Hello, does anyone know how i can draw a small handle (square) on the edge of the circle at each quadrant( for e.g at the north,east,west and south quadrants) I used general path to draw the circle, now I'm having difficulties to draw the handles. Here is my code:

``````//class1

import javax.swing.*;
import java.awt.*;
import java.awt.geom.GeneralPath;
import java.awt.geom.PathIterator;
import java.awt.geom.Rectangle2D;

public class RoundShape {

Point[] points;
GeneralPath circle;
final int INC = 5;

public RoundShape(){
initPoints();
initCircle();
}

private void initPoints()
{
int numberOfPoints = 360/INC;
points = new Point[numberOfPoints];
double x = 175.0;
double y = 175.0;
double r = 50.0;
int count = 0;
for(int theta = 0; theta < 360; theta+=INC)
{
int xpt = (int)(x + r * Math.cos(Math.toRadians(theta)));
int ypt = (int)(y + r * Math.sin(Math.toRadians(theta)));
points[count++] = new Point(xpt, ypt);
}
}

private void initCircle()
{
circle = new GeneralPath();
for(int j = 0; j < points.length; j++)
{
if(j == 0)
circle.moveTo(points[j].x, points[j].y);
else
circle.lineTo(points[j].x, points[j].y);
}
circle.closePath();
}

public void paintRound(Graphics2D g2d){

Shape round=getroundShape();
g2d.draw(round);

}

private Shape getSPointRectangle(int x, int y) {
return new Rectangle2D.Double(x - 3, y - 3, 6, 6);
}

public Shape getroundShape(){
Shape s=circle;
return s;

}

}

//class2

import javax.swing.*;
import java.awt.*;

public class MainRound extends JPanel {

RoundShape rs=new RoundShape();

public MainRound(){

}

public void paintComponent(Graphics g){

super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);

g2d.setPaint(Color.black);
g2d.setStroke(new BasicStroke(15));

rs.paintRound(g2d);

}

public static void main(String args[]){

MainRound mr=new MainRound();
JFrame frame=new JFrame();
frame.setContentPane(mr);
frame.setVisible(true);
frame.setSize(300,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

}
``````

You could generalize the point generation you have in `initPoints` to a method that takes an angle and returns the point at that angle; it would look something like `Point CreatePoint(double theta)`, and would make use of the code inside your `for(int theta...` loop. Then get points for 45, 235, 225, and 315 degrees and draw little rectangles centered on those points.

Does that sounds like what you're looking for?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.