Ik wilde een klein appletje maken om wav files af te kunnen spelen in mijn webpagina... Het probleem is dat ik dus een hele simpele applet heb gemaakt en in de appletviewer werkt hij maar niet op een webpagina...
De java code:
Van de webpagina:
De files staan allemaal bij elkaar in de directory... Alles komt wel in beeld maar hijs speeld geen geluid meer af...
Iemand enig idee wat ik fout doe?
De java code:
code:
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
| import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Player extends Applet implements MouseListener {
private MyObject playObject;
private MyObject stopObject;
private MyObject loopObject;
private AudioClip mySound;
final private String fileNamePath = new String("test.wav");
public void init() {
this.setBackground(new Color(255,255,255));
this.setLayout(null);
mySound = getAudioClip(getDocumentBase(), fileNamePath);
playObject = new MyObject("play", 5, 5, new Color(0, 0, 0));
stopObject = new MyObject("stop", 27, 5, new Color(0, 0, 0));
loopObject = new MyObject("loop", 45, 5, new Color(0, 0, 0));
this.addMouseListener(this);
}
public void paint(Graphics g) {
playObject.drawIt(g);
stopObject.drawIt(g);
loopObject.drawIt(g);
}
public void playSound() {
mySound.play();
}
public void stopSound() {
mySound.stop();
}
public void loopSound() {
mySound.loop();
}
public void mouseExited(MouseEvent me) { }
public void mouseEntered(MouseEvent me) { }
public void mouseReleased(MouseEvent me) { }
public void mousePressed(MouseEvent me) { }
public void mouseClicked(MouseEvent me) {
int tempX = me.getX();
int tempY = me.getY();
if (tempX >= playObject.giveX() && tempX <= (playObject.giveX()+12)) {
if (tempY >= playObject.giveY() && tempY <= (playObject.giveY()+8)) {
playSound();
}
}
else if (tempX >= stopObject.giveX() && tempX <= (stopObject.giveX()+8)) {
if (tempY >= stopObject.giveY() && tempY <= (stopObject.giveY()+8)) {
stopSound();
}
}
else if (tempX >= loopObject.giveX() && tempX <= (loopObject.giveX()+12)) {
if (tempY >= loopObject.giveY() && tempY <= (loopObject.giveY()+7)) {
loopSound();
}
}
}
}
class MyObject {
private String nameObject = new String("");
final private String playString = new String("play");
final private String stopString = new String("stop");
final private String loopString = new String("loop");
private boolean playAction = false;
private boolean stopAction = false;
private boolean loopAction = false;
private int[] playX = {0, 12, 0};
private int[] playY = {0, 4, 8};
private Color myColor;
private int x;
private int y;
public MyObject(String object, int x, int y, Color theColor) {
nameObject = object;
this.x = x;
this.y = y;
myColor = theColor;
if (nameObject.equals(playString)) {
playAction = true;
for (int i = 0; i < 3; i++) {
playX[i] = playX[i] + x;
playY[i] = playY[i] + y;
}
}
else if (nameObject.equals(stopString)) {
stopAction = true;
}
else if (nameObject.equals(loopString)) {
loopAction = true;
}
}
public int giveX() {
return x;
}
public int giveY() {
return y;
}
public void drawIt(Graphics g) {
if (playAction == true) {
g.setColor(myColor);
g.fillPolygon(playX, playY, 3);
}
else if(stopAction == true) {
g.setColor(myColor);
g.fillRect(0+x, 0+y, 8, 8);
}
else if(loopAction == true) {
g.setColor(myColor);
g.fillOval(0+x, 0+y, 7, 7);
g.fillOval(5+x, 0+y, 7, 7);
}
}
} |
Van de webpagina:
code:
1
2
3
4
5
6
7
8
| <html> <title>TestPage</title> <body> <h1>TEST!!!</h1> <applet codebase="." code="Player.class" width=62 height=18></applet> </body> </html> |
De files staan allemaal bij elkaar in de directory... Alles komt wel in beeld maar hijs speeld geen geluid meer af...
Iemand enig idee wat ik fout doe?