I'm woking on assignemnt which includes 5 concentric circles like target sign. One white circle one red and so on. If user click anyone of them i want to get those x , y points. and user should see small dot on that target sign. I wrote some code as follows. Right now I can see concentric circles but when I click on those circle I'm getting null pointer exception at runtime. Can somebody please explain me why?
Thanks in advance,
Ashu
import java.applet.Applet;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
/*
<applet code = Target.class height = 400 width=400>
</applet>
*/
public class Target extends Applet implements MouseListener {
private Label statusBar;
int x,y;
public void init() {
Label statusBar = new Label();
}
public Target() {
Target t = new Target();
t.addMouseListener(this);
}
public void paint(Graphics g) {
g.setColor(Color.red);
g.fillOval(0, 0, 240, 240);
g.setColor(Color.white);
g.fillOval(20, 20, 200, 200);
g.setColor(Color.red);
g.fillOval(40, 40, 160, 160);
g.setColor(Color.white);
g.fillOval(60, 60, 120, 120);
g.setColor(Color.red);
g.fillOval(80, 80, 80, 80);
g.fillOval(x, y, 4, 4);
}
public void mouseClicked(MouseEvent e)
{
x = e.getX();
y = e.getY();
statusBar.setText(e.getX()+","+e.getY());
repaint();
}
public void mousePressed(MouseEvent e){ }
public void mouseEntered(MouseEvent e){ }
public void mouseExited(MouseEvent e){ }
public void mouseReleased(MouseEvent e){ }
}