Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Whe repaint instead of paint?

Status
Not open for further replies.

wellas666

Programmer
Feb 10, 2006
23
0
0
GB
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){}
}
 
Here is some discussion on the matter that you might find valuable:


From quickly glancing at it, I get the impression that repaint() is pretty much the same as paint(), UNLESS you provide arguments (to the repaint(...) call) which, then, allow you to "repaint()" merely a portion of a GUI.

There's more to it than that. Check out the link.

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top