Name: rm29839 Date: 04/06/98
Mouse press on outer 2 pixels of a panel and drag
the mouse onto the frame. Start getting
mouseDragged events on the frame even though the
mousePressed event started on the outer 2 pixels of
the panel. MouseReleased is on the frame as well.
Shouldn't the component source for Drag and Release
be the same as the component originally pressed?
Here's the code. To test, be sure to press the
mouse on the outer 2 pixels of the panel before
dragging. The panel is 100 x 80.
Thanks so much for your help!
/*
Test component source for drag, press
*/
import java.awt.*;
import java.awt.event.*;
public class Frame1 extends Frame implements MouseListener, MouseMotionListener
{
public Frame1()
{
setLayout(null);
setVisible(false);
setSize(405, 305);
panel1 = new Panel();
panel1.setLayout(null);
panel1.setBounds(100,100,100,80);
panel1.setBackground(new Color(16711935));
add(panel1);
setTitle("Test Press and Drag Component");
addMouseMotionListener(this);
panel1.addMouseMotionListener(this);
addMouseListener(this);
panel1.addMouseListener(this);
WindowClose wc = new WindowClose();
this.addWindowListener(wc);
}
public Frame1(String title)
{
this();
setTitle(title);
}
static public void main(String args[])
{
(new Frame1()).show();
}
Panel panel1;
class WindowClose extends WindowAdapter
{
public void windowClosing(WindowEvent event)
{
Object object = event.getSource();
if (object == Frame1.this)
Frame1_WindowClosing(event);
}
}
void Frame1_WindowClosing(WindowEvent event)
{
hide();
dispose();
System.exit(0);
}
public void mouseClicked(MouseEvent e)
{
}
public void mousePressed(MouseEvent e)
{
System.out.println("Pressed: " + e.getComponent().toString());
System.out.println("Location: " + e.getX() + "," + e.getY());
}
public void mouseReleased(MouseEvent e)
{
System.out.println("Released: " + e.getComponent().toString());
}
public void mouseEntered(MouseEvent e)
{
System.out.println("Entered: " + e.getComponent().toString());
}
public void mouseExited(MouseEvent e)
{
}
public void mouseDragged(MouseEvent e)
{
System.out.println("Dragged: " + e.getComponent().toString());
}
public void mouseMoved(MouseEvent e)
{
}
}
(Review ID: 27107)
======================================================================