/** Initialize the applet */
  public void init() {
    // Create audio clips for pronouncing hours
    for (int i = 0; i < 12; i++)
      hourAudio[i] = Applet.newAudioClip(this.getClass().getResource("audio/hour" + i + ".au"));

    // Create audio clips for pronouncing minutes
    for (int i = 0; i < 60; i++)
      minuteAudio[i] = Applet.newAudioClip(this.getClass().getResource("audio/minute" + i + ".au"));

    // Add clock and time label to the content pane of the applet
    add(clock, BorderLayout.CENTER);
    add(jlblDigitTime, BorderLayout.SOUTH);
  }
Esempio n. 2
0
 /**
  * Gets an AudioClip.
  *
  * @return the audio clip
  */
 public AudioClip getAudioClip() {
   if (clip == null && getURL() != null) {
     clip = Applet.newAudioClip(getURL());
   }
   return clip;
 }
Esempio n. 3
0
  public GamePanel(String name, int l) {
    setFocusable(true);
    grabFocus();
    addMouseListener(this);
    addMouseMotionListener(this);
    addKeyListener(this);
    keys = new boolean[10000];

    try {
      scoreFont =
          Font.createFont(Font.TRUETYPE_FONT, new FileInputStream(new File("BRLNSB.ttf")))
              .deriveFont(0, 32);
    } catch (IOException ioe) {
      System.out.println("error loading BRLNSB.tff");
    } catch (FontFormatException ffe) {
      System.out.println("Something went wrong with the font.");
    }

    gameBckgrnd = new ImageIcon("Backgroundimage.png").getImage();
    for (int i = 1; i < 7; i++) {
      magnetList.add(new ImageIcon("gamelayerstuff/powerups/magnet" + i + ".png").getImage());
    }

    coinPic = new ImageIcon("gamelayerstuff/coins/byellowcoin1.png").getImage();
    player1 = new Player(200, 300, 100, "sheldon");

    click = false;
    ground = true;
    pause = false;
    lvlClear = false;
    die = false;
    musicOn = true;

    player1.setVelo(150);
    player1.setInvi(true);
    // ------------------------------------------------------------------------------------------------------------------------------------
    // Sound
    coinSound = Applet.newAudioClip(getClass().getResource("coin_pickup_2.wav"));
    clicked = Applet.newAudioClip(getClass().getResource("menu_deselect.wav"));
    starSound = Applet.newAudioClip(getClass().getResource("star.wav"));
    bounce = Applet.newAudioClip(getClass().getResource("grav_step_4.wav"));
    bckGrndMusic = Applet.newAudioClip(getClass().getResource("bgmusic00.wav"));
    bckGrndMusic.loop();
    // ------------------------------------------------------------------------------------------------------------------------------------

    // distance=0;
    score = 0;
    coins = 0;
    level = 1;
    prevLvl = level;
    backy = 0;
    height = backy;
    dieHeight = 0;
    dieMenuHeight = 0;

    pauseB = new SButton(400, 670, "pause", "");
    resumeB = new SButton(100, 500, "resume", "");
    menuB = new SButton(100, 620, "back", "");
    muteB = new SButton(400, 600, "mute", "");
    unmuteB = new SButton(400, 600, "unmute", "");
    // System.out.println("characters/"+name+"/"+name+"35.png");
  }
public class ClockWithAudioOnSeparateThread extends JApplet {
  protected AudioClip[] hourAudio = new AudioClip[12];
  protected AudioClip[] minuteAudio = new AudioClip[60];

  // Create audio clips for pronouncing am and pm
  protected AudioClip amAudio = Applet.newAudioClip(this.getClass().getResource("audio/am.au"));
  protected AudioClip pmAudio = Applet.newAudioClip(this.getClass().getResource("audio/pm.au"));;

  // Create a clock
  private StillClock clock = new StillClock();

  // Create a timer
  private Timer timer = new Timer(1000, new TimerListener());

  // Create a label to display time
  private JLabel jlblDigitTime = new JLabel("", JLabel.CENTER);

  /** Initialize the applet */
  public void init() {
    // Create audio clips for pronouncing hours
    for (int i = 0; i < 12; i++)
      hourAudio[i] = Applet.newAudioClip(this.getClass().getResource("audio/hour" + i + ".au"));

    // Create audio clips for pronouncing minutes
    for (int i = 0; i < 60; i++)
      minuteAudio[i] = Applet.newAudioClip(this.getClass().getResource("audio/minute" + i + ".au"));

    // Add clock and time label to the content pane of the applet
    add(clock, BorderLayout.CENTER);
    add(jlblDigitTime, BorderLayout.SOUTH);
  }

  /** Override the applet's start method */
  public void start() {
    timer.start(); // Resume clock
  }

  /** Override the applet's stop method */
  public void stop() {
    timer.stop(); // Suspend clock
  }

  private class TimerListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
      clock.setCurrentTime();
      clock.repaint();
      jlblDigitTime.setText(clock.getHour() + ":" + clock.getMinute() + ":" + clock.getSecond());
      if (clock.getSecond() == 0) announceTime(clock.getHour(), clock.getMinute());
    }
  }

  /** Announce the current time at every minute */
  public void announceTime(int h, int m) {
    new Thread(new AnnounceTimeOnSeparateThread(h, m)).start();
  }

  /** Inner class for announcing time */
  class AnnounceTimeOnSeparateThread implements Runnable {
    private int hour, minute;

    /** Get Audio clips */
    public AnnounceTimeOnSeparateThread(int hour, int minute) {
      this.hour = hour;
      this.minute = minute;
    }

    public void run() {
      // Announce hour
      hourAudio[hour % 12].play();

      try {
        // Time delay to allow hourAudio play to finish
        Thread.sleep(1500);

        // Announce minute
        minuteAudio[minute].play();

        // Time delay to allow minuteAudio play to finish
        Thread.sleep(1500);
      } catch (InterruptedException ex) {
      }

      // Announce am or pm
      if (hour < 12) amAudio.play();
      else pmAudio.play();
    }
  }

  public static void main(String[] args) {
    ClockWithAudioOnSeparateThread applet = new ClockWithAudioOnSeparateThread();
    applet.init();
    applet.start();
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setTitle("ClockWithAudioOnSeparateThread");
    frame.getContentPane().add(applet, BorderLayout.CENTER);
    frame.setSize(400, 320);
    frame.setVisible(true);
  }
}