📄 appletdemo6.java
字号:
//Example 6 of Chapter 6
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.*;
public class AppletDemo6 extends JApplet
{
private AudioClip currentSound;
private JList choose;
private JButton play, loop, stop;
private String choices[] = { "danger.au", "wrong.wav", "popped.aif" };
private int switchkey = 0;
public void init()
{
Container container = getContentPane();
container.setLayout( new FlowLayout() );
currentSound = getAudioClip( getDocumentBase(), choices[ 0 ] );
choose = new JList( choices );
choose.addListSelectionListener
(
new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
int k = -1;
for(int i=0; i<choices.length; i++)
{
if ( choices[ i ]==choose.getSelectedValue()) k = i;
}
currentSound.stop();
currentSound = getAudioClip( getDocumentBase(), choices[ k ] );
}
}
);
container.add( choose );
ButtonHandler handler = new ButtonHandler();
play = new JButton( "Play" );
play.addActionListener( handler );
container.add( play );
loop = new JButton( "Loop" );
loop.addActionListener( handler );
container.add( loop );
stop = new JButton( "Stop" );
stop.addActionListener( handler );
container.add( stop );
}
public void start()
{
switch(switchkey)
{
case 1:
currentSound.play();
play.setSelected( true );
break;
case 2:
currentSound.loop();
loop.setSelected( true );
break;
case 3:
currentSound.stop();
stop.setSelected( true );
}
}
public void stop()
{
currentSound.stop();
}
private class ButtonHandler implements ActionListener
{
public void actionPerformed( ActionEvent actionEvent )
{
if ( actionEvent.getSource() == play )
{
switchkey = 1;
currentSound.play();
}
if ( actionEvent.getSource() == loop )
{
switchkey = 2;
currentSound.loop();
}
if ( actionEvent.getSource() == stop )
{
switchkey = 3;
currentSound.stop();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -