BasicMouseInteraction
Retired DISLab
import acm.program.*; import acm.graphics.*; import java.awt.event.*; public class BasicMouseInteraction extends GraphicsProgram { private GLabel label; // this is an instance variable public void run() { label = new GLabel("Mouse Interactions"); label.setFont("SansSerif-24"); this.add(label, 50, 50); addMouseListeners(); } public void mouseClicked(MouseEvent e) { label.setLabel("Mouse Clicked at (" + e.getX() + "," + e.getY() + ")"); } public static void main(String[] args) { String[] newArgs = new String[args.length + 1]; System.arraycopy(args, 0, newArgs, 0, args.length); newArgs[args.length] = "code=" + new SecurityManager(){ public String className() { return this.getClassContext()[1].getCanonicalName(); } }.className(); GraphicsProgram.main(newArgs); } }