Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
SunnyDee
Posts: 75
Registered: ‎01-28-2009
My Device: Not Specified
Accepted Solution

drawing a circle

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!

Please use plain text.
Developer
bneeman
Posts: 132
Registered: ‎02-11-2009
My Device: Not Specified

Re: drawing a circle

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.

 

 

Please use plain text.
Developer
Zeeshan0581
Posts: 86
Registered: ‎01-09-2009
My Device: Not Specified

Re: drawing a circle

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

Please use plain text.
Developer
Rajat_10Sep
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: drawing a circle

[ Edited ]

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

Message Edited by Rajat_10Sep on 02-26-2009 08:03 AM
Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Please use plain text.
Developer
bbman
Posts: 16
Registered: ‎06-01-2009
My Device: Not Specified

Re: drawing a circle

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){
           
            protected void paint(Graphics _g){
              
                int x = getWidth()/2;
                int y = getHeight()/2;
                _g.setColor(Color.RED);
                _g.fillEllipse(x,y,x + 20,y,x,y + 20,0,360); 
                _g.setColor(Color.RED);
                _g.drawEllipse(x,y,x + 20,y,x,y + 20,0,360);            
                super.paint(_g);
            }
    };
Please use plain text.
Developer
Rajat_10Sep
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: drawing a circle

Hi,

 

I think you are trying to make a button field which is circular in shape.

 

Have a look at this link

 http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800345/...

 

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Please use plain text.
Developer
bbman
Posts: 16
Registered: ‎06-01-2009
My Device: Not Specified

Re: drawing a circle

Yes exactly, I want to make a button field in a circular shape and in color red. Are you saying that I can't instantiate a button field and try to make it circular by overriding its paint method? So I have to make my own custom field, and only then the paint method that I describe there will work to draw a circular shape field. Could you tell me if that paint method is correct to make a circle, though? It's just that the link you gave me doesn't really tell me if my method is correct or not. Thank you very much
Please use plain text.
Developer
Rajat_10Sep
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: drawing a circle

Hi,

 

Yes that code will draw the the circle.

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Please use plain text.
Developer
bbman
Posts: 16
Registered: ‎06-01-2009
My Device: Not Specified

Re: drawing a circle

Yes!! I extended a field, and then pasted that paint method in it and it drew me a nice red circle :smileyhappy: Thanks so much Rajat
Please use plain text.