<APPLET CODE=AppletSubclass.class WIDTH=anInt HEIGHT=anInt> <PARAM NAME=parameter1Name VALUE=aValue> <PARAM NAME=parameter2Name VALUE=anotherValue> </APPLET> |
||
Voir: http://tecfa.unige.ch/guides/java/tutorial/applet/appletsonly/appletTag.html ou un bon manuel HTML pour une liste complète des paramètres "système" |
||
<APPLET CODE=Simple.class WIDTH=100 HEIGHT=200> </APPLET>
Source: http://tecfa.unige.ch/guides/java/staf2x/ex/gui/virus/Virus.java
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Virus extends Applet {
/* A Warning box in an applet by J M Bishop Oct 1996
* Java 1.1 */
static private final int line = 15;
static private final int letter = 5;
public void paint(Graphics g) {
g.drawRect(2*letter, 2*line, 33*letter, 6*line);
g.drawString("W A R N I N G", 9*letter, 4*line);
g.drawString("Possible virus detected", 4*letter, 5*line);
g.drawString("Reboot and run virus", 5*letter, 6*line);
g.drawString("remover software", 7*letter, 7*line);
} }
Page HTML: http://tecfa.unige.ch/guides/java/staf2x/ex/gui/virus/virus.html
<H1>Virus Applet</H1>
<APPLET CODE="Virus.class" WIDTH=200 HEIGHT=200>
</APPLET>
<hr> Voici notre petit applet <hr>
HTML: http://tecfa.unige.ch/guides/java/staf2x/ex/gui/simple/simpleempty.html
Source: http://tecfa.unige.ch/guides/java/staf2x/ex/gui/simple/SimpleEmpty.java
import java.applet.Applet; import java.awt.Graphics;
public class SimpleEmpty extends Applet {
// excecution lorsque l'applet est chargé (initialisation des trucs "statiques")
public void init() {
}
// excecution lorsque l'applet démarre (aspets plus dynamiques)
// au début ou lorsque l'utilisateur revient sur la page
public void start() {
}
// excecution lorsque l'applet s'arrete par exemple l'utilisateur fait un "back"
public void stop() {
}
// excecution lorsque l'applet est détruit
public void destroy() {
}
void uneMethodeVide() { }
public void paint(Graphics g) {
//on fait quand-meme un minimum
g.drawString("Hello World", 5, 15);
}
}
HTML: http://tecfa.unige.ch/guides/java/staf2x/ex/gui/simple/Simple.java
Source: http://tecfa.unige.ch/guides/java/staf2x/ex/gui/simple/simple.html
StringBuffer buffer;
public void init() {
buffer = new StringBuffer();
addItem("initializing... ");
}
public void start() {
addItem("starting... "); }
public void stop() {
addItem("stopping... "); }
public void destroy() {
addItem("preparing for unloading..."); }
void addItem(String newWord) {
System.out.println(newWord);
buffer.append(newWord);
repaint(); }
public void paint(Graphics g) {
//Draw a Rectangle around the applet's display area.
g.drawRect(0, 0, size().width - 1, size().height - 1);
//Draw the current string inside the rectangle.
g.drawString(buffer.toString(), 5, 15);
}
HTML: http://tecfa.unige.ch/guides/java/staf2x/ex/gui/virus/virus2.html
Source: http://tecfa.unige.ch/guides/java/staf2x/ex/gui/virus/Virus2.java
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Virus2 extends Applet implements ActionListener {
/* A Warning box in an applet adapted from J M Bishop Oct 1996 - Java 1.1
* Must be run via its corresponding html file in a browser or the appletviewer */
static private final int line = 15; static private final int letter = 5;
// flag pour voir si c'est la première fois
static private boolean FirstTime = true;
static private int hits = 0;
public void paint(Graphics g) {
Button KillButton;
KillButton = new Button("Kill me");
KillButton.setSize(100,30);
KillButton.setLocation(50,170);
KillButton.addActionListener(this);
add(KillButton);
if (FirstTime)
{
KillButton.setVisible(true);
g.drawRect(2*letter, 2*line, 33*letter, 6*line);
g.drawString("W A R N I N G", 9*letter, 4*line);
g.drawString("Possible virus detected", 4*letter, 5*line);
g.drawString("Reboot and run virus", 5*letter, 6*line);
g.drawString("remover software", 7*letter, 7*line);
}
else
{
g.drawRect(2*letter, 2*line, 33*letter, 6*line);
String bye = "Good BYE [ " + hits + " ]";
g.drawString(bye, 9*letter, 4*line);
g.drawString("OH CRUEL WORLD !", 5*letter, 6*line);
}
}
public void actionPerformed(ActionEvent e) {
FirstTime = false;
hits++;
repaint();
}
}