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
Contributor
mrdialect2012
Posts: 27
Registered: ‎05-10-2012
My Device: bold 9700
Accepted Solution

Drawing a circle to the main screen?

Hi Guys,

 

Pretty quick one here,

 

I am looking to draw a circle on the main screen of a phone app i am creating.

 

So far on the main screen I have drawn 9 rectangles. But on  a keypress event I want

to paint on top of these rectangles my circle.

 

I've used java before to do this op using repaint but am not sure how to 

repaint/refresh so i can draw on top of an already drawn shape which happens onload.

 

 

Darren

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Drawing a circle to the main screen?

welcome to the support forums.

everything on the screen is drawn in paint (or paintBackground).
you will have to redraw your rectangles and add the circle.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
mrdialect2012
Posts: 27
Registered: ‎05-10-2012
My Device: bold 9700

Re: Drawing a circle to the main screen?

how would I redraw, repaint doesnt seem to call the paint method again and dopaint doesnt either when I call it. 

 

 public MyScreen()
    {        
        super( MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR );        
        setTitle("MyTitle"); 

    }
    
     public boolean keyChar(char key, int status, int time) {
    	if(key == 'e')
    	{
         	
         // Here I want to draw a new circle
        
    	} 
    	else 
    	{
    	
    	}
    	return true;
    	}

    protected void paint(Graphics g)
    {	
    	g1 = (Graphics) g;
    	super.paint(g1);
    	drawBoard(g1); 
    }
    
    public void drawBoard(Graphics g)
    {
    	int y = 0;
    	int z =0;
    	for (int i =0; i<= rectangles.length; i++)
    	{
    		if(i >= 0 && i <=2)
    		{
    		g.drawRect(160+ i * 90 , 100, 90, 90);
    		
    		} 
    		else if(i >= 3 && i <=5)
    		{	
    		g.drawRect(160+ y * 90, 190, 90, 90);
    		y++;
    		}
    		else if(i >= 6 && i <=8)
    		{
    		g.drawRect(160 + z *90 , 280, 90, 90);
    		z++;
    		}
    	}    	
    }

 

 

The above code draws a set of rectangles on the main screen but drawing on top of this how is this done, normally i would just use a repaint on a boolean setting but this does not work

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Drawing a circle to the main screen?

you add the drawCircle in the paint method resp the drawBoard method, just add a condition that you can modify.
you can issue a repaint using invalidate().
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
mrdialect2012
Posts: 27
Registered: ‎05-10-2012
My Device: bold 9700

Re: Drawing a circle to the main screen?

Thanks, works a charm