A simple code from the book. Why it use applet.repaint() instead of applet.paint() in the listener?
paint() is a public method in class Dots, why I cannot do applet.paint() in which applet is an object of class Dots.
--------------------------
import java.applet.Applet;
import java.awt.*;
public class Dots extends Applet
{
private final int RADIUS = 16;
Point clickPoint = null;
public void init()
{
DotsMouseListener listener = new DotsMouseListener(this);
addMouseListener(listener);
}
public void paint(Graphics page)
{
page.setColor(Color.red);
if (clickPoint != null)
page.fillOval (clickPoint.x-RADIUS,clickPoint.y-RADIUS,RADIUS*2,RADIUS*3);
}
public void setPoint(Point point)
{
clickPoint = point;
}
}
--------------------------
import java.awt.*;
import java.awt.event.*;
public class DotsMouseListener implements MouseListener
{
private Dots applet;
public DotsMouseListener (Dots theApplet)
{
applet = theApplet;
}
public void mouseClicked (MouseEvent event)
{
Point clickPoint = event.getPoint();
applet.setPoint(clickPoint);
applet.repaint();
//applet.paint(applet);
}
public void mousePressed (MouseEvent event){}
public void mouseReleased (MouseEvent event){}
public void mouseEntered (MouseEvent event){}
public void mouseExited (MouseEvent event){}
}
paint() is a public method in class Dots, why I cannot do applet.paint() in which applet is an object of class Dots.
--------------------------
import java.applet.Applet;
import java.awt.*;
public class Dots extends Applet
{
private final int RADIUS = 16;
Point clickPoint = null;
public void init()
{
DotsMouseListener listener = new DotsMouseListener(this);
addMouseListener(listener);
}
public void paint(Graphics page)
{
page.setColor(Color.red);
if (clickPoint != null)
page.fillOval (clickPoint.x-RADIUS,clickPoint.y-RADIUS,RADIUS*2,RADIUS*3);
}
public void setPoint(Point point)
{
clickPoint = point;
}
}
--------------------------
import java.awt.*;
import java.awt.event.*;
public class DotsMouseListener implements MouseListener
{
private Dots applet;
public DotsMouseListener (Dots theApplet)
{
applet = theApplet;
}
public void mouseClicked (MouseEvent event)
{
Point clickPoint = event.getPoint();
applet.setPoint(clickPoint);
applet.repaint();
//applet.paint(applet);
}
public void mousePressed (MouseEvent event){}
public void mouseReleased (MouseEvent event){}
public void mouseEntered (MouseEvent event){}
public void mouseExited (MouseEvent event){}
}