GraphicNumbers

GraphicNumbers - // Create a new label GLabel lab = new...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * File: GraphicNumbers.java * ------------------------- * This program shows an example of using ArrayLists with * objects. */ import acm.program.*; import acm.graphics.*; import java.util.*; import java.awt.event.*; public class GraphicNumbers extends GraphicsProgram { private static final double START_X = 50; private static final double START_Y = 100; public void init() { addMouseListeners(); } public void mouseClicked(MouseEvent e) {
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // Create a new label GLabel lab = new GLabel("#" + labels.size()); lab.setFont("Courier New-18-Bold"); // Move all existing labels down one row double dy = lab.getHeight(); for(int i = 0; i < labels.size(); i++) { labels.get(i).move(0, dy); } add(lab, START_X, START_Y); // Add new label to canvas labels.add(lab); // Add new label to ArrayList } private ArrayList<GLabel> labels = new ArrayList<GLabel>(); }...
View Full Document

This note was uploaded on 02/18/2010 for the course CS 106A taught by Professor Sahami,m during the Fall '08 term at Stanford.

Ask a homework question - tutors are online