Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calling paint from another class

 
Vinod Venugopal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ..
});
}
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On Tony Alicea's Java Page you'll find a demonstration of Inter-Applet Communication.
Good Luck.
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Regards,
Manfred.
 
Vinod Venugopal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vinod Venugopal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops sorry , I would like to correct the message above, commponparent is a Panel like MyPanel...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic