Article View: borland.public.jbuilder.java.language
Article #17828Re: dynamic components, matching events?
From: Tad Frysinger
Date: Sun, 27 Sep 1998 00:00
Date: Sun, 27 Sep 1998 00:00
75 lines
2628 bytes
2628 bytes
In article <360DCAE7.ABB78C37@xnote.com>, vernon@xnote.com says...
> I've got a question that I need some help on.
>
> I've created a Panel, and dynamically added what are basically canvas'.
> How do I create an even that will allow me to click on the canvas? I
> can't figure out how to create the actionevents when I dynamically
> create the canvas'.
>
> Anyone got any ideas?
>
>
What I've done is to code a method that takes a component as an argument,
and sets up delegating the various events I'm interested in to a single
handler, which determines the work. i.e.
private void setAdapters( Component c ) {
c.addMouseListener( new MouseAdapter() {
public void mousePressed(MouseEvent event) {
handleMouseEvent( event );
}
public void mouseEntered(MouseEvent event) {
handleMouseEvent( event );
}
public void mouseExited(MouseEvent event) {
handleMouseEvent( event );
}
public void mouseReleased(MouseEvent event) {
handleMouseEvent( event );
}
public void mouseClicked(MouseEvent event) {
handleMouseEvent( event );
}
});
c.addMouseMotionListener( new MouseMotionAdapter() {
public void mouseMoved(MouseEvent event) {
handleMouseEvent( event );
}
public void mouseDragged(MouseEvent event) {
handleMouseEvent( event );
}
});
}
Then:
void handleMouseEvent(MouseEvent e ) {
((DesignerPanel)getParent()).handleChildMouseEvent( e, this );
}
Then in the master handler for the dynamically added components that
resides in the parent:
public void handleChildMouseEvent( MouseEvent e, DPComponent dp ) {
Object source = e.getSource();
switch(e.getID()) {
case MouseEvent.MOUSE_ENTERED:
if (bBatchMove ) {
dp.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
break;
}
etc.
etc.
You might make a subclass of Canvas that contains enough info so that the
master handler knows which one it is dealing with, if that is important
for you.
Tad Frysinger
[TeamB]
Technical Details
Message-ID:
<MPG.10785b7b8a683590989908@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<360DCAE7.ABB78C37@xnote.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,91f8bf77ef927875 X-Google-Attributes: gidf74b3,public From: tfrysinger@uswest.net (Tad Frysinger) Subject: Re: dynamic components, matching events? Date: 1998/09/27 Message-ID: <MPG.10785b7b8a683590989908@forums.borland.com> X-Deja-AN: 395414173 References: <360DCAE7.ABB78C37@xnote.com> Organization: FreeZone Enterprises Newsgroups: borland.public.jbuilder.java.language