hi , simple problem but cant rack my brains enuf :-) Ok, now I have 2 classes which extends from JPanel each, one of them ( p1) has a button draw, once I click on draw I should be able to draw a line in the other panel ( p2) but without creating an object of p2, how do I do it? for eg. class p1 extends JPanel { } class p2 extends JPanel { draw.addAction... { //draw line in p1 .. }); }
Hi Vinod, If you have common parents the problem is quite easy. You can just get the parent and then use the sibling object array to get a handle on the other panel. The code below shows an example.
If you don't have a common parent, you will need to pass a reference to the first panel into the constructor of the second in order to have a handle on the component you want to paint into.
Thanx guys for the feedback, ..Manfred, mine is something similar to the commonparent types except that commonparent is a frame itself, also I just dont need to repaint, based on values obtained from some table based operation in p1 I have to drawrect in p2..& this is dynamic..that means the Graphics context object needs to be active all the time.. Just doing drawrect was creating problems so I tried with adding JLabels with borders & empty text so it looks like rectangles, works out somewhat ok, but it would be gr8 to use graphics object & tinker with drawRect.