import java.applet.Applet; import java.applet.AudioClip; import java.awt.BorderLayout; import java.net.MalformedURLException; import java.net.URL; import javax.swing.JFrame; public class Game extends JFrame { Controller controller = null; Status status = null; Arena arena = null; AudioClip music = null; AudioClip ping = null; AudioClip pong = null; public Game() { super("My Bouncy Game"); loadSounds(); controller = new Controller(this); status = new Status(); arena = new Arena(this); getContentPane().setLayout(new BorderLayout()); getContentPane().add("Center", arena); getContentPane().add("South", status); validate(); pack(); setVisible(true); this.addKeyListener(controller); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setResizable(false); if (music != null) music.loop(); } public void loadSounds() { String preface = "file:" + System.getProperty("user.dir"); try { URL musicURL = new URL(preface + "/music.wav"); URL pingURL = new URL(preface + "/ping.wav"); URL pongURL = new URL(preface + "/pong.wav"); music = Applet.newAudioClip(musicURL); ping = Applet.newAudioClip(pingURL); pong = Applet.newAudioClip(pongURL); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void soundPing() { ping.play(); } public void soundPong() { pong.play(); } public void start() { arena.start(); } public void stop() { arena.stop(); } public void faster() { arena.faster(); } public void slower() { arena.slower(); } public void moveRight() { arena.moveRight(); } public void moveLeft() { arena.moveLeft(); } public void stopMoving() { arena.stopMoving(); } public void advanceCounter() { status.advanceCounter(); } public void resetCounter() { status.resetCounter(); } public void pause() { arena.pause(); } public void restart() { arena.restart(); } public static void main(String args[]) { Game game = new Game(); } }