package v3;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.applet.AudioClip;
import java.net.URL;
public class exam extends Frame {
private Image img = null;
private Image img2 = null;
private Image img3 = null;
int x = 500;
int y = 400;
String hurl;
AudioClip audio;
public static void main(String[] args) {
new exam();
}
public exam() {
this.setSize(1366,768);
this.setLocation(100,100);
img = Toolkit.getDefaultToolkit().createImage("./photos/car.jpg");
img3 = Toolkit.getDefaultToolkit().createImage("./photos/car.jpg");
img2 = Toolkit.getDefaultToolkit().createImage("./photos/car.jpg");
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_RIGHT)
x = x + 5;
else if(e.getKeyCode() == KeyEvent.VK_LEFT)
x = x -5;
else if(e.getKeyCode() == KeyEvent.VK_UP)
y = y -5;
else if(e.getKeyCode() == KeyEvent.VK_DOWN)
y = y +5;
repaint();
}
});
String hurl;
AudioClip audio;
this.setVisible(true);
}
public void paint(Graphics g) {
g.drawImage(img2,100,400,200,200, this);
g.drawImage(img3,x,y,200,200, this);
g.drawImage(img,1200,400,100,200,this);
}
}
package v3;
import java.awt.*;
import java.applet.Applet;
import java.applet.AudioClip;
import java.net.URL;
public class AudioPlay extends Applet{
String hurl;
AudioClip audio;
public void init() {
resize(300,100);
if(hurl==null) {
hurl="audio/nocompleted.au";
}
try {
audio = getAudioClip(new URL(getDocumentBase(),hurl));
} catch(Exception e) { }
this.setBackground(Color.lightGray);
audio.play();
}
}
希望能在控制图片移动的同时播放音频,怎么实现呢?