summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/hjp5/examples/HWApplet.java
blob: c7c7f1987e0bff2b7397779878ca6134498f853a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* HWApplet.java */

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class HWApplet
extends Applet
implements ActionListener
{
  Button    hello;
  Button    world;
  AudioClip helloClip;
  AudioClip worldClip;

  public void init()
  {
    super.init();
    setLayout(new FlowLayout());
    hello = new Button("Hello");
    hello.addActionListener(this);
    add(hello);
    world = new Button("World");
    world.addActionListener(this);
    add(world);
    helloClip = getAudioClip(getCodeBase(),"hello.au");
    worldClip = getAudioClip(getCodeBase(),"world.au");
  }

  public void actionPerformed(ActionEvent event)
  {
    String cmd = event.getActionCommand();
    if (cmd.equals("Hello")) {
      helloClip.play();
    } else if (cmd.equals("World")) {
      worldClip.play();
    }
  }
}