Ads 468x60px

freak2code is the blog about latest geek news,software reviews ,trends in technology and more informative stuff......

Tuesday, 14 August 2012

NullPointerException problem


NullPointerException problem

I just recently learned how to incorporate time into my programs. Specifically using the Timer and TimerTask classes to make a specific action occur after a certain amount of times, and repeat every amount of time. I first tried it, and just made a simple program that counted to 10 then exited. That worked fine. Now my goal is to create an applet that draws red circles on the screen repetitively. Here is my code:
Code java:


import java.util.Timer;
import java.util.TimerTask;
import java.util.Date;
import javax.swing.*;
import java.awt.*;
 
public class TimerTest extends JApplet
{
 public static Graphics pa;
 public void paint(Graphics page)
 {
  pa = page;
  pa.setColor(Color.red);
  pa.fillOval(100,100,50,50);
  Timer timer = new Timer();
  timer.schedule(new CountDown(), 1000);
 }
 
 private static class CountDown extends TimerTask
 {
  public static Graphics pa;
  public void paint(Graphics page)
  {
   pa = page;
   pa.setColor(Color.red);
   pa.fillOval(100,100,50,50);
  }
  public void run()
  {
   pa.fillOval(200,200,50,50);
  }
 }
}

0 comments:

Post a Comment

Recent Posts