Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Message passing between subcomponents.

Status
Not open for further replies.

hottimbo

Programmer
May 10, 2002
6
0
0
GB
Hi,

I've got a JApplet class with a JPanel object as the content pane. The content pane Panel has a BorderLayout, with one one JPanel derived class in NORTH, and one JPanel derived class in CENTER.

The center panel is a map on which places can be selected. I want the NORTH panel to display info on the place selected, but can't figure out a way for the center panel to notify the north panel that something has changed in the state of the center panel, and to pass the data and update the screen.

Do I need to create a thread in the north panel which constantly monitors the state of the center panel ?

Thanks,
Tim
 
If you add use the
Code:
JPanel
Code:
addMouseListener
and or
Code:
addMouseMotionListener
methods inherited from
Code:
java.awt.Component
, you can listen for mouse movements and clicks - which when the user clicks on the specific panel - you can catch the event, and do stuff with it (ie update the other panel).

Check out the documentation :

Ben
 
Thanks, that makes sense. I'll do that.

I currently have a mouse listener in the center panel doing this, so I can't seem to trap those mouse messages in the main JApplet.
I guess I'll handle all the mouse stuff in the main applet like you suggest, and not in the individual components.

I've also moved the animation thread from the center panel to the main applet, which has raised a new problem.

I'm calling the JApplet's overridden paint() every 50ms or so. Inside that paint() I do some data handling then call super.paint(), which (should) then go and paint the other sub components. This works, except that occasionally (once every couple of seconds) it renders the center panel from the north position and causes it to appear to jump every so often.

Am I doing this wrong too ?

Thanks,
Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top