Ecco un applet con un bottone
Codice:
import java.awt.*;
import java.applet.*;
public class MyApplet extends Applet {
public void init() {
Button bottone=new Button("Sono un bottone");
add(bottone);
}
}
e qui un applet con un bottone che fa qualcosa (se premuto cambia il testo del bottone in "ciao")
Codice:
import java.awt.*;
import java.applet.*;
public class MyApplet extends Applet {
Button bottone=new Button("bottone");
public void init() {
add(bottone);
}
public boolean action(Event e, Object trg) {
if(e.target instanceof Button) {
String tag=(String) trg;
if(tag.equals("bottone")) {
bottone.setLabel("ciao");
return true;
}
}
return false;
}
}
Il metodo di gestione degli eventi "action(...)" č "deprecated" ma retrocompatibile, in pratica funziona anche con i browser a carbone.
Ciao.