I have this code
private void startActionPerformed(java.awt.event.ActionEvent evt) {
this.start.setBackground(Color.green);
this.stop.setBackground(Color.lightGray);
if (!stopped) {
timer.cancel();
}
stopped = false;
stato.setText("Avviato");
timer = new Timer();
if(giacRitardo>0)
timer.schedule(S.run("argiacenze"), giacRitardo, giacRitardo);//parti dopo x secondi e itera ogni x secondi
if(cliRitardo>0)
timer.schedule(S.run("arclienti"), cliRitardo, cliRitardo);//parti dopo x secondi e itera ogni x secondi
// some other code
and
class TaskSchedulato extends TimerTask {
@Override
public void run() {
redirectSystemStreams();
DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
URL sito = null;
try {
sito = new URL(sUrl + "?aggiornamento=arlingue");
} catch (MalformedURLException ex) {
System.out.println("Indirizzo del sito mal formato o inesistente");
}
URLConnection yc = null;
try {
yc = sito.openConnection();
} catch (IOException ex) {
System.out.println("Errore di connessione _ ");
}
BufferedReader in = null;
try {
in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));
} catch (IOException ex) {
Logger.getLogger(TaskSchedulato.class.getName()).log(Level.SEVERE, null, ex);
}
String inputLine;
try {
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
} catch (IOException ex) {
Logger.getLogger(TaskSchedulato.class.getName()).log(Level.SEVERE, null, ex);
dataErrore = new Date();
System.out.println(sdf.format(dataErrore));
System.out.println("Errore di connessione: " + dataErrore);
}
try {
in.close();
} catch (IOException ex) {
Logger.getLogger(TaskSchedulato.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
and
TaskSchedulato S = new TaskSchedulato();
I need to extend the method run above, so that i can pass a string parameter to it. How can a do it. I'm almost a newbye in java. So, please forgive me for the inexperience.
Actually I receive the error: no suitable method found for run(String) method TimerTask.run() is not applicable (actual and formal argument lists differ in length) method MainForm.TaskSchedulato.run() is not applicable (actual and formal argument lists differ in length)
Thank you in advance