package cg; //------------------------------------------------------------------------------------------ import com.jogamp.opengl.GLProfile; import com.jogamp.opengl.GLCapabilities; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.util.FPSAnimator; import java.io.File; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.event.KeyListener; import com.jogamp.newt.event.WindowAdapter; import com.jogamp.newt.event.WindowEvent; //------------------------------------------------------------------------------------------ public class Main implements KeyListener { static Clip clip; static String[] datei = {"blaster.wav","boom.wav","harley-davidson.wav"}; //------------------------------------------------------------------------------------------ public static void main(String[] args) { GLProfile glp = GLProfile.getDefault(); GLCapabilities caps = new GLCapabilities(glp); GLWindow window = GLWindow.create(caps); window.setSize(640, 480); window.setTitle("NEWT Fenster"); window.setVisible(true); window.addKeyListener(new Main()); window.addWindowListener(new WindowAdapter() { public void windowDestroyNotify(WindowEvent e) { System.exit(0); }; }); final FPSAnimator animator = new FPSAnimator(window, 60, true); animator.start(); } //------------------------------------------------------------------------------------------ public static void soundStart(String datei) { try { File file = new File("src/res/" + datei); AudioInputStream audioIn = AudioSystem.getAudioInputStream(file); clip = AudioSystem.getClip(); clip.open(audioIn); clip.start(); } catch (Exception e) {e.printStackTrace();} } public static void soundStop() { clip.stop(); } //------------------------------------------------------------------------------------------ public void keyPressed(KeyEvent e) { int keyCode = e.getKeyCode(); if(keyCode == KeyEvent.VK_A) {soundStart(datei[0]);} if(keyCode == KeyEvent.VK_S) {soundStart(datei[1]);} if(keyCode == KeyEvent.VK_D) {soundStart(datei[2]);} if(keyCode == KeyEvent.VK_SPACE) {soundStop();} } public void keyReleased(KeyEvent e) {/*...*/} }