ComponentEventTestFrame

package ch.usi.inf.sape.gui.test.app;
 
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
 
import javax.swing.JFrame;
 
 
/**
 * Test GUI capture and replay tools for their ability to handle component events.
 * 
 * See our AST'10 paper "Automating Performance Testing of Interactive Java Applications".
 * 
 * Copyright (c) 2010 - Sape Research Group, University of Lugano
 */
public final class ComponentEventTestFrame extends JFrame {
 
	public ComponentEventTestFrame() {
		super("WindowEventTestFrame");
 
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
 
		addComponentListener(new ComponentListener() {
			public void componentHidden(final ComponentEvent ev) {
				System.out.println("Window has been hidden");
			}
			public void componentMoved(final ComponentEvent ev) {
				System.out.println("Window has been moved to ("
						+ ev.getComponent().getLocation().x + ";"
						+ ev.getComponent().getLocation().y + ")");
			}
			public void componentResized(final ComponentEvent ev) {
				System.out.println("Window has been resized to ("
						+ ev.getComponent().getSize().width + ";"
						+ ev.getComponent().getSize().height + ")");
			}
			public void componentShown(final ComponentEvent ev) {
				System.out.println("Window has been shown");
			};
		});
 
		addKeyListener(new KeyAdapter() {
			public void keyPressed(final KeyEvent ev) {
				// allow key press to hide and show window
				setVisible(false);
				try {
					Thread.sleep(500);
				} catch (final InterruptedException ex) {
					ex.printStackTrace();
				}
				setVisible(true);
			}
		});
 
		setSize(300, 300);
		setVisible(true);
	}
 
	public static void main(final String[] args) {
		new ComponentEventTestFrame();
	}
 
}