Java 7 for Absolute Beginners

(nextflipdebug5) #1

CHAPTER 13 ■ GARBAGE COLLECTION


public class TargetClickPanel extends JPanel implements MouseListener{

private static final long serialVersionUID = 1L;

private Target targets[] = new Target[5];

public TargetClickPanel() {
addMouseListener(this);
for (int i = 0; i < targets.length; i++) {
targets[i] = null;
}
}

public void paint (Graphics g) {
super.paintComponent(g);
for (int i = 0; i < targets.length; i++) {
if (targets[i] == null) {
targets[i] = new Target(this);
}
if (!targets[i].isDone()) {
targets[i].draw(g);
} else {
targets[i] = new Target(this);
}
}
}

@Override
public void mouseClicked(MouseEvent e) {
}

@Override
public void mouseEntered(MouseEvent e) {
}

@Override
public void mouseExited(MouseEvent e) {
}

@Override
public void mousePressed(MouseEvent e) {
}

@Override
public void mouseReleased(MouseEvent e) {
for (int i = 0; i < targets.length; i++) {
targets[i].pointInTarget(e.getX(), e.getY());
}
}
}
Free download pdf