FileDocCategorySizeDatePackage
ClippedDragImage.javaAPI DocExample1458Sat Apr 23 22:35:40 BST 2005None

ClippedDragImage

public class ClippedDragImage extends DragImage

Fields Summary
int
oldX
int
oldY
Constructors Summary
public ClippedDragImage(Image i)

 super(i); 
Methods Summary
private java.awt.RectanglegetAffectedArea(int oldx, int oldy, int newx, int newy, int width, int height)

    int x = Math.min(oldx, newx);
    int y = Math.min(oldy, newy);
    int w = (Math.max(oldx, newx) + width) - x;
    int h = (Math.max(oldy, newy) + height) - y;
    return new Rectangle(x, y, w, h);
  
public static voidmain(java.lang.String[] args)

    String imageFile = "L1-Light.jpg";
    if (args.length > 0)
      imageFile = args[0];

	// Turn off double buffering
	//RepaintManager.currentManager(null).setDoubleBufferingEnabled(false);

    Image image = Toolkit.getDefaultToolkit().getImage(
        ClippedDragImage.class.getResource(imageFile));
	image = image.getScaledInstance(imageWidth,imageHeight,Image.SCALE_DEFAULT);
    JFrame frame = new JFrame("ClippedDragImage");
    frame.getContentPane().add( new ClippedDragImage(image) );
    frame.setSize(300, 300);
	frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    frame.setVisible(true);
  
public voidmouseDragged(java.awt.event.MouseEvent e)

    imageX = e.getX();
    imageY = e.getY();
    Rectangle r = getAffectedArea(
		oldX, oldY, imageX, imageY, imageWidth, imageHeight);
    repaint(r);  // repaint just the affected part of the component
    oldX = imageX;
    oldY = imageY;