FileDocCategorySizeDatePackage
LimitedFlicker.javaAPI DocExample1538Mon May 01 14:42:02 BST 2000None

LimitedFlicker

public class LimitedFlicker extends TerribleFlicker

Fields Summary
int
oldX
int
oldY
Constructors Summary
public LimitedFlicker(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];
    Image i = Toolkit.getDefaultToolkit(  ).getImage(
        TerribleFlicker.class.getResource(imageFile));
    JFrame f = new JFrame("LimitedFlicker");
    Container content = new Panel(new BorderLayout(  )) {
        public void update(Graphics g) { paint(g); }
    };
    content.add(new LimitedFlicker(i), BorderLayout.CENTER);
    f.setContentPane(content);
    f.setSize(300, 300);
    f.setLocation(100, 100);
    f.addWindowListener(new WindowAdapter(  ) {
      public void windowClosing(WindowEvent e) { System.exit(0); }
    });
    f.setVisible(true);
  
public voidmouseDragged(java.awt.event.MouseEvent e)

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