Hej. Tak jak w temacie: mam problem z użyciem apletu w HTML-u. Aplet jest już gotowy, a ja mam tylko problem z odpaleniem go przez HTML.Tu jest kod źródłowy apletu:
package pierwszy_projekt;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.awt.image.*;
import java.util.*;
import java.net.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2009</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Snieg
extends Applet
implements Runnable {
boolean isStandalone = false;
//BorderLayout borderLayout1 = new BorderLayout();
int wysokosc, szerokosc;
int szybkoscX[], szybkoscY[], platkiX[], platkiY[];
int liczbaPlatkow = 100;
int wielkoscPlatka = 5;
Random r = new Random();
Image img;
Graphics gDC;
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
//Construct the applet
public Snieg() {
}
//Initialize the applet
public void init() {
wysokosc = getHeight();
szerokosc = getWidth();
szybkoscX = new int[liczbaPlatkow];
szybkoscY = new int[liczbaPlatkow];
platkiX = new int[liczbaPlatkow];
platkiY = new int[liczbaPlatkow];
for (int i = 0; i < liczbaPlatkow; i++){
szybkoscY[i] = r.nextInt(5) + 1;
int dir = (r.nextInt(2)==0)?-1:1;
szybkoscX[i] = dir * (r.nextInt(10) + 1);
platkiX[i] = r.nextInt(szerokosc - 1);
platkiY[i] = r.nextInt(wysokosc - 1);
}
img = getImage(getDocumentBase(), getParameter("plik"));
gDC = getGraphics();
}
public void run(){
while(true){
gDC.setColor(Color.WHITE);
gDC.drawImage(img, 0, 0, this);
for(int i = 0; i < liczbaPlatkow; i++){
int dir = (r.nextInt(5)==0)?-1:1;
szybkoscX[i] = dir * szybkoscX[i];
platkiX[i] += szybkoscX[i];
platkiY[i] += szybkoscY[i];
if ((platkiY[i] > szerokosc) || (platkiX[i] < 0))
szybkoscX[i] = - szybkoscX[i];
if (platkiY[i] > wysokosc){
szybkoscY[i] = r.nextInt(5) + 1;
dir = (r.nextInt(2)==0)?-1:1;
szybkoscX[i] = dir * (r.nextInt(10) + 1);
platkiX[i] = r.nextInt(szerokosc - 1);
platkiY[i] = r.nextInt(10);
} gDC.fillOval(platkiX[i], platkiY[i], wielkoscPlatka, wielkoscPlatka);
} try{
Thread.sleep(100);
} catch (
InterruptedException e){
}
}
}
/* try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}*/
//Component initialization
private void jbInit() throws Exception {
}
//Start the applet
public void start() {
Thread thread = new Thread (this);
thread.start();
}
//Stop the applet
public void stop() {
}
//Destroy the applet
public void destroy() {
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
}
Mój plik w HTML-u wygląda tak:
//Rozdział 5 zad 2
<html>
<head>
</head>
<body>
<applet
code = "Snieg.class"
width = "320"
height= "200">
</applet>
</body>
</html>
Gdy uruchamiam ten plik HTML w appletviewer przez cmd wyskakuje mi w Javie, że "Applet not initialized", natomiast w cmd pisze mi, że nie znaleziono klasy Snieg. Z tego co szukałem na necie trzeba podobno dodać parametr ze zdjęciem do html-a. Napisałby mi ktoś jak to polecenie ma mniej więcej wyglądać ? Z góry dzięki.