Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
On the Wintel AWT with JDK 1.1.5 (not Solaris): If you move a Window on top of a MouseMotion source, the Window becomes the source of mouseDragged events. On Solaris, the events continue to come from the original source. The program that I've supplied demonstrates this. Here's how: 1. Launch the program on Windows 2. Click and drag from the magenta region. A blue "toolbar" will appear. 3. Click and drag from the magenta region again. This time the toolbar will move under the mouse and stop moving. The mouseDragged events start coming from the toolbar now, not the toolbar source. The behavior alternates. Once you see the problem, the next drag from the magenta region will work fine. The time after that, it will be broken again. The printlns give a little more evidence. When things stop working the printlns look like: Toolbar source got mouseDragged Toolbar got drag event Toolbar got drag event Toolbar got drag event The Toolbar shouldn't get any drag events until it received at least a mousePressed. tom.santos@eng 1998-03-19 import java.awt.*; import java.awt.event.*; public class AWTTest { public static void main( String[] argv ) { Frame frame = new Frame( "AWTTest" ); frame.setLayout( new BorderLayout() ); frame.add( BorderLayout.NORTH, new FakeToolBar( frame ) ); Panel fillerPanel = new Panel() { public Dimension getPreferredSize() { return new Dimension( 300, 300 ); } }; frame.add( BorderLayout.CENTER, fillerPanel ); frame.pack(); frame.show(); } } class FakeToolBar extends Panel { public FakeToolBar( Frame frame ) { setBackground( Color.magenta ); MouseReporter listener = new MouseReporter( frame ); addMouseMotionListener( listener ); } public Dimension getPreferredSize() { return new Dimension( 75, 75 ); } } class MouseReporter implements MouseMotionListener { Frame fFrame; Window fWindow; Point fStartOffset; public MouseReporter( Frame frame ) { fFrame = frame; } public void mouseMoved( MouseEvent e ) { System.out.println( "toolbar source got mouseMoved" ); } public void mouseDragged( MouseEvent e ) { System.out.println( "toolbar source got mouseDragged" ); if ( fWindow == null ) { fWindow = new Window( fFrame ); fWindow.addMouseListener( new MouseAdapter() { public void mousePressed( MouseEvent evt ) { System.out.println( "Mouse pressed in window" ); } public void mouseClicked( MouseEvent evt ) { System.out.println( "Mouse clicked in window" ); ((Window)evt.getSource()).dispose(); fWindow = null; } }); fWindow.addMouseMotionListener( new MouseMotionListener() { public void mouseMoved( MouseEvent e ) { System.out.println( "Toolbar got mouse moved event" ); } public void mouseDragged( MouseEvent e ) { System.out.println( "Toolbar got drag event" ); } }); Component source = (Component)e.getSource(); fStartOffset = e.getPoint(); int x = source.getLocation().x + fFrame.getLocation().x; int y = source.getLocation().y + fFrame.getLocation().y ; fWindow.setLocation( x, y ); fWindow.setSize( source.getSize() ); fWindow.setBackground( Color.blue ); fWindow.show(); } else { Component source = (Component)e.getSource(); int x = (e.getX() + source.getLocation().x + fFrame.getLocation().x) - fStartOffset.x; int y = (e.getY() + source.getLocation().y + fFrame.getLocation().y) - fStartOffset.y; fWindow.setLocation( x, y ); } } }
|