document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import java.awt.Color;
  2. import java.awt.Dimension;
  3. import java.awt.Font;
  4. import java.awt.Graphics;
  5. import java.awt.Graphics2D;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.KeyEvent;
  8. import java.awt.event.KeyListener;
  9. import java.awt.font.FontRenderContext;
  10. import java.awt.font.TextLayout;
  11. import java.awt.geom.Ellipse2D;
  12. import java.awt.geom.Point2D;
  13. import java.awt.geom.Rectangle2D;
  14. import java.io.File;
  15. import java.io.IOException;
  16. import java.util.prefs.Preferences;
  17. import javax.sound.sampled.AudioInputStream;
  18. import javax.sound.sampled.AudioSystem;
  19. import javax.sound.sampled.Clip;
  20. import javax.sound.sampled.LineUnavailableException;
  21. import javax.sound.sampled.UnsupportedAudioFileException;
  22. import javax.swing.AbstractAction;
  23. import javax.swing.Action;
  24. import javax.swing.JComponent;
  25. import javax.swing.JFrame;
  26. import javax.swing.Timer;
  27. import java.util.Random;
  28. /**
  29.  * Write a description of class BallBreaker here.
  30.  * Class Utama yang berisikan tentang Pemanggilan Class lain sehingga menjadi kompleks
  31.  * @author Fitrah Arie Ramadhan dan Ivan Muhammad Nizar
  32.  * @version Final Version, 8 Januari 2021
  33.  */
  34. public class BallBreaker {
  35.     private int height, width;
  36.     private static File soundFile = new File("impact1.wav");
  37.     private static File soundFile1 = new File("impact.wav");
  38.     public static boolean isSoundOn = true;
  39.     public static void main(String[] args) {
  40.         JFrame F = new JFrame("Penghancur Semesta");
  41.         final World w = new World();
  42.         F.add(w);
  43.         F.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  44.         F.setSize(800,600);
  45.         F.setResizable(false); // Frame not resizable
  46.         F.setLocationByPlatform(true); // Allow the platform to position the frame
  47.         KeyMon k = new KeyMon(w);
  48.         F.addKeyListener(k);
  49.         F.setVisible(true);
  50.         //initscene dipindah ke keymon
  51.         Action playAndUpdateAction = new AbstractAction() {
  52.             public void actionPerformed(ActionEvent e) {
  53.                 try {
  54.                     w.play();
  55.                 }catch(Exception ex) {
  56.                     ex.printStackTrace();
  57.                 }
  58.                 w.repaint();        
  59.             }
  60.         };
  61.         tmr = new Timer(20, playAndUpdateAction); // Fire the above action event every 20 ms
  62.         tmr.start();
  63.         }
  64.         public static Timer tmr;
  65.         public static void playClip() //Plays the sound clip
  66.         throws IOException, UnsupportedAudioFileException,
  67.                LineUnavailableException {
  68.                    AudioInputStream auIn = null;
  69.                    AudioInputStream auInL = null;
  70.                    Clip clip = null;
  71.                    Clip clip1 = null;
  72.         try {
  73.             auIn = AudioSystem.getAudioInputStream(soundFile);
  74.             auInL = AudioSystem.getAudioInputStream(soundFile1);
  75.             clip = AudioSystem.getClip();
  76.             clip1 = AudioSystem.getClip();;
  77.             clip.open(auIn);
  78.             clip1.open(auInL);
  79.             clip.start();
  80.             clip1.start();
  81.         } finally {
  82.             if(auIn != null) {
  83.                 auIn.close();
  84.             }
  85.             else if(auInL != null){
  86.                 auInL.close();
  87.             }
  88.         }
  89.     }
  90. }
');