import java.util.*; import javax.swing.*; import javax.swing.Timer; import java.awt.*; import java.awt.event.*; public class AntLand extends JPanel implements ActionListener, MouseListener { private ArrayList things; private String message; private Timer timer; private int ticks; public static final int WIDTH = 800; public static final int HEIGHT = 600; public void resetLand() { things = new ArrayList(); timer.restart(); ticks=0; repaint(); } public AntLand() // constructor { ArrayList things = new ArrayList(); addMouseListener(this); message = ""; timer = new Timer(10, this); ticks=0; timer.start(); resetLand(); } public void paintComponent(Graphics g) { Color bgColor = new Color (225, 200, 175); setBackground(bgColor); super.paintComponent(g); for (Active thing: things) thing.draw(g); g.setColor(Color.BLUE); g.drawString(message, 20, 20); } public static void main(String[] args) { JFrame window = new JFrame(); window.setSize(WIDTH, HEIGHT); Container c = window.getContentPane(); c.add(new AntLand()); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setVisible(true); } @Override public void actionPerformed(ActionEvent e) { ticks++; for (Active thing: things) thing.doSomething(); message = ""+ticks; repaint(); } @Override public void mouseClicked(MouseEvent e) { this.resetLand(); } @Override public void mousePressed(MouseEvent e) {} @Override public void mouseReleased(MouseEvent e) {} @Override public void mouseEntered(MouseEvent e) {} @Override public void mouseExited(MouseEvent e) {} }