02-25-2009 04:39 PM
Hi,
I'm having trouble drawing a filled circle. Can anyone help? I'm trying to use graphics.fillEllipse(...) but I can't figure out what parameters will output a circle.
Thanks!
Solved! Go to Solution.
02-25-2009 05:00 PM
Assuming you have x,y for the circle's centre and r for radius.
The method takes 3 points, C, P, and Q.
Set C to the centre (x,y).
Offset P from the centre along the X-axis (x + r, y).
Offset Q from the centre along the Y-axis (x, y + r).
All together it should look something like this:
g.drawEclipse(x, y, x + r, y, x, y + r, 0, 360);
Cheers, Barak.
02-25-2009 07:19 PM
Center points: x, y
Radius: radius
to draw a filled circle:
Graphics.fillArc(x, y, radius, radius, 0, 360);
if you want to just draw circle use:
Graphics.drawArc(x, y, radius, radius, 0, 360);
02-26-2009 07:53 AM - edited 02-26-2009 08:03 AM
Hi,
Please find below for drawing circle
class TreeComponentScreen extends FullScreen{
TreeComponentScreen() {
drawComponent();
}
public void drawComponent(){
HorizontalFieldManager hfm1 = new HorizontalFieldManager();
add(hfm1);
}
protected void paint(Graphics graphics){
graphics.drawEllipse(getWidth()/2,getHeight()/2,50 + 30,50,50,50 + 30,0,360);
super.paint(graphics);
}
}
just alter the parameter 3,4,5,6 in the function drawEllipse() according to your requirement.
Let me know if you have any query.
Regards,
Rajat Gupta.
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
06-01-2009 08:37 PM
Hi, I tried the solutions posted above but it doesn't work for me. I really really need to make a record button that is a circle in order to live. I tried implementing all three replies, and I think the snippet of code below should work but it doesn't. I add the button to the manager, but all it displays is an empty rounded rectangle in the middle with black color. If I set a border to the button, then I'll have a small vertical strip constructed by the border, but still empty button. I also tried instantiating the button with a label, and I ended up having a rectangle button with a small cropped red dot in the corner.
Any help please, I don't know how the second reply is the solution... does it not work with ButtonField? Much much thanks in advance
private ButtonField _pushToRec = new ButtonField(ButtonField.FIELD_HCENTER | DrawStyle.ELLIPSIS){
06-01-2009 11:34 PM
Hi,
I think you are trying to make a button field which is circular in shape.
Have a look at this link
06-02-2009 12:07 AM
06-02-2009 12:32 AM
Hi,
Yes that code will draw the the circle.
06-02-2009 12:12 PM