• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

calling paint from another class

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ..
});
}
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On Tony Alicea's Java Page you'll find a demonstration of Inter-Applet Communication.
Good Luck.
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops sorry , I would like to correct the message above, commponparent is a Panel like MyPanel...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic