// HalloWeltApplet.java MM 2003
import java.applet.*; // Applet
import java.awt.*; // Graphics
/**
* Dieses Applet gibt den Schriftzug "Hallo Welt!" aus.
*/
public class HalloWeltApplet extends Applet
{
/**
* Hauptmethode, Darstellung des Applet.
*/
public void paint( Graphics g)
{
setForeground(Color.translucent);
switch (wechsel)
{
g.setColor(Color.yellow);
g.drawString( "Hallo Welt!", 50, 50);
g.setColor(Color.blue);
}
}
/**
* Wechseln der Farben
* wird von Javascript aufgerufen.
*/
public void setWechsel (int nr)
{ wechsel = nr;
repaint( 100L);
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<!-- Diese Seite bindet das HalloWelt - Applet ein. -->
<title>HalloWeltApplet</title>
</head>
<body>
<!-- Applet --> <applet code="HalloWeltApplet.class"
height="100" width="170"> </applet>
<hr><!-- Javascript --> <a
onclick="neueFarbe('blue');" href="javascript:void(0)">blau</a>
<a onclick="" neuefarbe('yellow=""
href="javascript:void(0)">gelb</a>
</body>
</html>
public class BackgroundChanger extends JApplet {
private Random random = new Random();
public BackgroundChanger() {
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
changeColor();
}
});
}
private void changeColor() {
int red = random.nextInt(255);
int green = random.nextInt(255);
int blue = random.nextInt(255);
Color background = new Color(red, green, blue);
getContentPane().setBackground(background);
}
}
import java.applet.*; // Applet
import java.awt.*; // Graphics
/**
* Dieses Applet gibt den Schriftzug "Hallo Welt!" aus.
*/
public class HalloWeltAppletPlus extends JApplet {
private Random = new Random();
public void HalloWeltAppletPlus() {
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
changeColor();
}
});
}
private void changeColor() {
int red = random.nextInt(255);
int green = random.nextInt(255);
int blue = random.nextInt(255);
Color background = new Color(red, green, blue);
getContentPane().setBackground(background);
}
private Random random = new Random();//Der Variablenname fehlt
<applet id="applet" code="Applet.class" width=600 height=600 alt="" > </applet>
<script language="JavaScript">
var applet= document.getElementById("applet");
alert(applet.getAppletInfo());
</script>
getAppletContext().showDocument(new java.net.URL("javascript:testFunction()"));