package game; import java.applet.Applet; import java.applet.AudioClip; import java.awt.BorderLayout; import java.net.MalformedURLException; import java.net.URL; import javax.swing.JFrame; import javax.swing.JOptionPane; public class Game extends JFrame { private GameArena arena = null; private GameStatus status = null; private GameController controller = null; private AudioClip music = null; private AudioClip splash = null; public Game() { super("My Game"); loadSounds(); arena = new GameArena(this); status = new GameStatus(this); controller = new GameController(this); getContentPane().setLayout(new BorderLayout()); getContentPane().add("Center", arena); getContentPane().add("South", status); this.addKeyListener(controller); validate(); pack(); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); if (music != null) music.loop(); } public void loadSounds() { String preface = "file:" + System.getProperty("user.dir"); try { URL musicURL = new URL(preface + "/game/music.wav"); music = Applet.newAudioClip(musicURL); } catch (MalformedURLException e) { JOptionPane.showMessageDialog(this, "Error loading sound(s)"); } } public void moveLeft() { arena.moveLeft(); } public void moveRight() { arena.moveRight(); } public static void main(String args[]) { Game game = new Game(); } }