import java.awt.*; import java.awt.event.*; import java.util.Date; import physics2D.*; class Pool extends Frame implements KeyListener, MouseListener, WindowListener { public static void main(String[] args) { Pool poolGame = new Pool(); } // -------------------------------------------------------------------------------- // Data Members // -------------------------------------------------------------------------------- private PoolTable table; private Insets insets; private int windowWidth = 800, windowHeight = 600, increment = 1, maxIncrement = 100, gameWidth, gameHeight; private boolean loop; private Graphics2D graphics2D; private Date startTime, endTime; // -------------------------------------------------------------------------------- // Constructor // -------------------------------------------------------------------------------- public Pool() { // call parent constructor super("Pool v0.000000001"); // set frame properties insets = getInsets(); gameWidth = windowWidth - insets.left - insets.right; gameHeight = windowHeight - insets.top - insets.bottom; setSize(windowWidth, windowHeight); setResizable(false); Toolkit toolkit = Toolkit.getDefaultToolkit(); int xLocation = (toolkit.getScreenSize().width - windowWidth) / 2; int yLocation = (toolkit.getScreenSize().height - windowHeight) / 2; setLocation(xLocation,yLocation); setBackground(Color.black); show(); graphics2D = (Graphics2D) getGraphics(); validate(); reset(); // regester this frame as its own key and window listener addWindowListener(this); addKeyListener(this); // start infinate loop startTime = new Date(); run(); } // -------------------------------------------------------------------------------- // Methods // -------------------------------------------------------------------------------- public void run() { loop = true; while (true) while (loop) { table.advanceTime(increment); graphics2D.drawImage(table.getImage(), insets.left, insets.top, this); endTime = new Date(); System.out.println(increment + " " + (int) (endTime.getTime() - startTime.getTime())); increment = (int) (increment + endTime.getTime() - startTime.getTime()) / 2; if (increment > maxIncrement) { increment = maxIncrement; } startTime.setTime(endTime.getTime()); } } private void reset() { table = new PoolTable(gameWidth, gameHeight, createImage(gameWidth, gameHeight)); } // implementation of mouse listener public void mouseClicked(MouseEvent event) {} public void mouseEntered(MouseEvent event) {} public void mouseExited(MouseEvent event) {} public void mousePressed(MouseEvent event) {} public void mouseReleased(MouseEvent event) {} // implementation of key listener public void keyTyped(KeyEvent event) {} public void keyReleased(KeyEvent event) {} public void keyPressed(KeyEvent event) {} // implementation of window listener to activate close button public void windowClosing(WindowEvent event) { loop = false; dispose(); System.exit(0); } public void windowActivated(WindowEvent event) {} public void windowClosed(WindowEvent event) {} public void windowDeactivated(WindowEvent event) {} public void windowDeiconified(WindowEvent event) {} public void windowIconified(WindowEvent event) {} public void windowOpened(WindowEvent event) {} }