Stampare a schermo il testo indicato con un ritardo fisso.
event_print
main
event_print
PHP Code:
package oggetto;
import javax.swing.JOptionPane;
import javax.swing.Timer;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class event_print {
static public class event implements ActionListener{
public event( String in){
text = in;
}
public void actionPerformed(ActionEvent e) {
System.out.println(text);
}
private String text;
}
public event_print(int ms, String in_string){
exec = new Timer(ms,new event(in_string)); // the timer call function actionPerformed in the object of type event
}
public void start(){
exec.start();
JOptionPane.showMessageDialog(null,"Exit?");
System.exit(0);
}
private Timer exec;
}
PHP Code:
import oggetto.event_print;
public class test {
public static void main(String[] input){
new event_print(1000,"ciao mondo").start();
}
}