Link to home
Start Free TrialLog in
Avatar of DaisyWang
DaisyWang

asked on

How to communicate between two components in both direction?

On my applet, I have a 200*200 canvas (say CanvasA), and a scrollPane contains another 2000*2000 canvas (say CanvasB) on it.  Now I want to two direction communication like this:
1. when I click on CanvasA's position (x, y), I want the scrollPane's scroll position to be adjusted to (10*x, 10*y).
I can implement this by put the scrollPane in CanvasA's constructor;
2. however, when I drag or click on scrollPane's scroll bar, I can get a scroll position (x, y) form scrollPane, I also want a rectangle defined by (x/10, y/10, 30, 30) reflected on CanvasA.

also, here applet, CanvasA, CanvasB are three different class, while scrollPane is just a component on applet.

Hope I have made myself clear.

Looking for your answer, thanks,

Daisy
Avatar of sgoms
sgoms

you cannot add a listener to the scrollbars in a scrollpane.
either you can go in for Scrollbar or JScrollPane.

wud swing be ok? or r u particulat abt java 1.1x??
Avatar of DaisyWang

ASKER

To: sqoms

I mean I have successfully add a listener to scrollpane (not scrollbar).  However, what I want is whenever I click on the scrollbar of scrollPane, I want the CanvasA to reflect the proper area of CanvasB shown on scrollPane.

Thanks.

Daisy
'applet, CanvasA, CanvasB are three different class, while scrollPane is just a component on applet.'

do you have problem in implementing some functionality or you just can't access some object methods from other objects ?

generally speakig, you can always use these methods
addAdjustmentListener()
setScrollPosition()

(maybe it's better to post your code ?)
ASKER CERTIFIED SOLUTION
Avatar of sgoms
sgoms

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ya, it works!  thank you a lot!