Java Reference
In-Depth Information
29 panel.add(jbtResume);
30 panel.add(jbtSuspend);
31 panel.add(
new
JLabel(
"Select"
));
32 panel.add(jcboNations);
33 add(jlblImageLabel, BorderLayout.CENTER);
34 add(panel, BorderLayout.SOUTH);
35
36 jbtResume.addActionListener(
new
ActionListener() {
37 @Override
38
register listener
public void
actionPerformed(ActionEvent e) {
39
40 }
41 });
42 jbtSuspend.addActionListener(
new
ActionListener() {
43 @Override
44
start();
start audio
register listener
public void
actionPerformed(ActionEvent e) {
45
46 }
47 });
48 jcboNations.addActionListener(
new
ActionListener() {
49 @Override
50
public void
actionPerformed(ActionEvent e) {
51 stop();
52 current = jcboNations.getSelectedIndex();
53 presentNation(current);
54 }
55 });
56
57 jlblImageLabel.setIcon(icons[
0
]);
58 jlblImageLabel.setHorizontalAlignment(JLabel.CENTER);
59
60
61 }
62
63
private void
presentNation(
int
index) {
64 jlblImageLabel.setIcon(icons[index]);
65 jcboNations.setSelectedIndex(index);
66 currentAudioClip = audioClips[index];
67
68 }
69
70 @Override
71
stop();
stop audio
register listener
select a nation
present a nation
currentAudioClip = audioClips[
0
];
currentAudioClip.play();
currentAudioClip.play();
public void
start() {
currentAudioClip.play();
play a clip
72
73 }
74
75 @Override
76
public void
stop() {
77
78 }
79 }
currentAudioClip.stop();
stop audio clip
main method omitted
A label is created in line 13 to display a flag image. An array of flag images for seven nations
is created in lines 22-23. An array of audio clips is created in lines 24-25. The image files and
audio files are stored in the same directory as the applet class file so these files can be located
using the
getResource
method.
The combo box for country names is created in lines 16-17. When a new country name in
the combo box is selected, the current presentation is stopped and a new selected nation is
presented (lines 51-53).