Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Mark - 27 Jun 2005 02:28 GMT
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?
Larry Barowski - 27 Jun 2005 03:14 GMT
> ...
> 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().


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.