Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Add point to graphics area without having to paint the whole area?

Reply
Thread Tools

Add point to graphics area without having to paint the whole area?

 
 
Mark
Guest
Posts: n/a
 
      06-27-2005
I have written a graphics program that generates a lot of data points
and as each data point is calculated, it is placed on the chart. I
decided to add each point as it is calculated, rather than to generate
all points and show the chart only when all points are done, as a bit of
eye-candy to keep the user interested.

The code fragments below shows how it is done:

===============
public void addPoint(DataPoint point)
{
// Vector of graph points
dataPoints.add(point);
repaint();
}

public void paint(Graphics g)
{
Graphics2D g2d = (Graphics2D)g;

// Draw X and Y axes, grid lines, and scale numbers.
// (some code here)

// Now draw the graph points in the dataPoints Vector.
int numPoints = dataPoints.size();
for (int i = 0; i < numPoints; i++)
{
// Various calculations to properply place each point
// in the g2d space...

}
}
================

As each point is generated, it is put into the dataPoints vector
(through the addPoint() method), and then a repaint() invokes the
paint() method. Note that the paint() method re-does everything. Even
if I already have 200 points on the chart, and I add the 201st point,
all 201 points are redrawn just to achieve the visual effect of adding a
201st point to the chart.

As more points are added, things seem slower, since all points have to
be redrawn in order to add the last new point.

Question: Is there a technique to just add one point to the EXISTING
chart without having to redraw the ENTIRE chart?
 
Reply With Quote
 
 
 
 
Larry Barowski
Guest
Posts: n/a
 
      06-27-2005

"Mark" <(E-Mail Removed)> wrote in message
news:izIve.10594$(E-Mail Removed)...
> ...
> Question: Is there a technique to just add one point to the EXISTING
> chart without having to redraw the ENTIRE chart?


Use repaint(int, int, int, int) to only repaint a rectangle that covers
the new point.

Inside of paint(Graphics g), only paint points that intersect
g.getClipBounds().


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Share-Point-2010 ,Share-Point -2010 Training , Share-point-2010Hyderabad , Share-point-2010 Institute Saraswati lakki ASP .Net 0 01-06-2012 06:39 AM
*WITHOUT* using: ValidateRequest="False" for the whole page (or my whole site).... \A_Michigan_User\ ASP .Net 2 08-21-2006 02:13 PM
Scenario 5: IS-IS routing on Frame Relay Multi-point and Point-to-Point David Sudjiman Cisco 0 06-08-2006 09:11 AM
Unable to paint (using paint() in JPanel) inside mouse listeners eshedz@gmail.com Java 4 10-23-2005 09:13 PM
How do i refresh a datagrid from a pop up window without having to refresh the whole page? Pkenty ASP .Net Web Controls 0 05-28-2004 07:06 AM



Advertisments