AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Tempo infame!

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java (Italian)
View previous topic :: View next topic  
Author Message
Bixio
Guest





PostPosted: Thu Jan 29, 2004 11:46 am    Post subject: Tempo infame! Reply with quote



Ri-posto una mia vecchia richiesta, arricchita di altre richieste (sono
insaziabile) !!
Premettendo la mia inesperienza più totale, dovrei fare in modo di lanciare
un countdown di tot secondi, al termine del quale venga lanciata
un'eccezione che faccia terminare un metodo in esecuzione...
consigli?
aiuti?
tutto ben accetto!
Fabrizio


Back to top
daniele
Guest





PostPosted: Thu Jan 29, 2004 12:45 pm    Post subject: Re: Tempo infame! Reply with quote



"Bixio" <bixio.ng (AT) email (DOT) it> wrote in
news:No6Sb.161496$VW.6546665 (AT) news3 (DOT) tin.it:

Quote:
Ri-posto una mia vecchia richiesta, arricchita di altre richieste
(sono insaziabile) !!
Premettendo la mia inesperienza più totale, dovrei fare in modo di
lanciare un countdown di tot secondi,

In che contesto? (Servlet, Applet, App standalone.. )

Quote:
al termine del quale venga
lanciata un'eccezione che faccia terminare un metodo in esecuzione...
consigli?

Forse potrebbe esserti utile utilizzare un Timer e relativo thread
(TimerTask) che calcola il countdown e agisce di conseguenza.
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Timer.html

--
daniele

Back to top
Alberto
Guest





PostPosted: Thu Jan 29, 2004 1:11 pm    Post subject: Re: Tempo infame! Reply with quote



da
http://javaalmanac.com/
cercando
timer

Se hai una variabile e su timer la decrementi... il gioco e' fatto

http://javaalmanac.com/egs/java.util/ScheduleRepeat.html?l=find

int delay = 5000; // delay for 5 sec.
int period = 1000; // repeat every sec.
Timer timer = new Timer();

timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
// Task here ...
}
}, delay, period);

Guarda un po di documentazione di questi "oggetti"

Bixio wrote:

Quote:
Ri-posto una mia vecchia richiesta, arricchita di altre richieste (sono
insaziabile) !!
Premettendo la mia inesperienza più totale, dovrei fare in modo di lanciare
un countdown di tot secondi, al termine del quale venga lanciata
un'eccezione che faccia terminare un metodo in esecuzione...
consigli?
aiuti?
tutto ben accetto!
Fabrizio



Back to top
Bixio
Guest





PostPosted: Thu Jan 29, 2004 2:47 pm    Post subject: Re: Tempo infame! Reply with quote


"Alberto" <a.corni (AT) democenter (DOT) it> ha scritto nel messaggio
news:88udnQ55dO4Zm4Td4p2dnA (AT) kpnqwest (DOT) it...

Quote:
Se hai una variabile e su timer la decrementi... il gioco e' fatto

int delay = 5000; // delay for 5 sec.
int period = 1000; // repeat every sec.
Timer timer = new Timer();

timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
// Task here ...
}
}, delay, period);

Non ho ben capito come pensi di procedere... cosa fa esattamente il metodo
qui sopra? Dalla documentazione non sono riuscito a venirne a capo
completamente!
Grazie



Back to top
Alberto
Guest





PostPosted: Thu Jan 29, 2004 4:22 pm    Post subject: Re: Tempo infame! Reply with quote

Cosi' e' disegnata male ma funziona.
E' meglio creare una classe esterna che eredita da TimerTask
e inizializzare il timer, ad esempio nel costruttore di questo.

Su timeOut puoi invocare un tuo metodo che scatena qualunque cosa!


// Jdk
import java.util.*;
import java.io.*;
import java.util.Timer;

public static void main(String args[]) throws Exception {
int delay = 500; // delay for 5 sec.
int period = 1000; // repeat every sec.
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
_counter--;
if (_counter < 0) {
System.out.println(" time out!");
cancel();
System.exit(0);
} else {
System.out.println(" -" + _counter);
}
// Task here ...
}
private int _counter = 3;
}, delay, period);
}
}
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java (Italian) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.