FileDocCategorySizeDatePackage
TerribleFlicker.javaAPI DocExample1669Mon May 01 14:42:02 BST 2000None

TerribleFlicker

public class TerribleFlicker extends JComponent implements MouseMotionListener

Fields Summary
int
grid
int
imageX
int
imageY
Image
image
int
imageWidth
int
imageHeight
Constructors Summary
public TerribleFlicker(Image i)


     
    image = i;
    addMouseMotionListener(this);
  
Methods Summary
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("TerribleFlicker");
    Container content = new Panel(new BorderLayout(  ));
    content.add(new TerribleFlicker(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(  );
    repaint(  );
  
public voidmouseMoved(java.awt.event.MouseEvent e)

public voidpaint(java.awt.Graphics g)

    Graphics2D g2 = (Graphics2D)g;

    int w = getSize(  ).width / grid;
    int h = getSize(  ).height / grid;
    boolean black = false;
    for (int y = 0; y <= grid; y++)
      for (int x = 0; x <= grid; x++) {
        g2.setPaint(black ? Color.black : Color.white);
        black = !black;
        g2.fillRect(x * w, y * h, w, h);
      }
    g2.drawImage(image, imageX, imageY,
                 imageWidth, imageHeight, this);