MouseDragTestFrame

package ch.usi.inf.sape.gui.test.app;
 
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
 
import javax.swing.JComponent;
import javax.swing.JFrame;
 
 
/**
 * Test GUI capture and replay tools for their ability to handle mouse drags.
 * 
 * See our AST'10 paper "Automating Performance Testing of Interactive Java Applications".
 * 
 * Copyright (c) 2010 - Sape Research Group, University of Lugano
 */
public final class MouseDragTestFrame extends JFrame {
 
	public MouseDragTestFrame() {
		super("MouseDragTestFrame");
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		add(new JComponent() {
			int x;
			int y;
			{
				addMouseMotionListener(new MouseMotionAdapter() {
					public void mouseDragged(final MouseEvent ev) {
						x = ev.getX();
						y = ev.getY();
						repaint();
					}
				});
			}
			public void paint(final Graphics g) {
				final int width = getWidth();
				final int height = getHeight();
				g.setColor(Color.WHITE);
				g.fillRect(0, 0, width, height);
				g.setColor(Color.RED);
				g.fillOval(x-5, y-5, 10, 10);
			}
		});
		setSize(300, 300);
		setVisible(true);
	}
 
	public static void main(final String[] args) {
		new MouseDragTestFrame();
	}
 
}