si scusami..me ne sono accorto solo dopo, cmq sia il codice è questo:
codice:
public void ShowTimer(String text)
{
time2.setText(text);
}
public void Random() // da definire
{
}
static class CountDown
{
private static int attesa = 1000;
private static GiocoForza4 f4;
private static Timer t;
private static int i;
public CountDown(GiocoForza4 f4)
{
this.f4 = f4;// initializes the reference to the Welcome class.
String text = (" " + i + " ");
f4.ShowTimer(text);
//f4ShowTimer(text);
}
public static void start()
{
new Timer(attesa, new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
for(i = 5; i >= 0; i--)
{
System.out.println(i);
try
{
synchronized(((Timer) e.getSource()))
{
((Timer) e.getSource()).wait(1000);
}
String text = (" " + i + " ");
f4.ShowTimer(text);
if(i == 0)
{
((Timer) e.getSource()).stop();
// porre il random
}
}
catch (InterruptedException ex)
{
Logger.getLogger(GiocoForza4.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}).start();
}
}
questo codice mi produce un errore:
codice:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at GiocoEffettivo.GiocoForza4$CountDown$1.actionPerformed(GiocoForza4.java:163)
at javax.swing.Timer.fireActionPerformed(Timer.java:312)
at javax.swing.Timer$DoPostEvent.run(Timer.java:244)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:691)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
il primo pezzo di codice viene richiamato in un JButton all'interno di una griglia con la chiamata:
codice:
GiocoForza4.CountDown.start();
spero di essere stato chiaro..magari nel caso nn riesca a risolvere se gentilmente mi potreste suggerire un metodo alternativo per fare un countDown..vi ringrazio anticipatamente !