PDA

View Full Version : Mettere un bottone in un applet


The Incredible
25-03-2003, 09:23
Ciao a tutti , è possibile inserire in un applet un bottone?
Come posso fare?

PGI
25-03-2003, 10:33
Ecco un applet con un bottone


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")


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.

The Incredible
25-03-2003, 10:58
Ti Ringrazio