Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am developing an application where I draw large number of lines (color is given as black) and update them where I need to remove them from screen.

I thought of making their color to match with the background so that I can make them hide. It seems to be simple and works but in the practical sense I have 10000 points and almost more than 20000 lines to be drawn and as most the line overlap or cross each other it is so disgusting the view.

So I need some kind of function to actually remove those selected lines between two known points from screen. Even I have a problem with the background color I can match the exact background default color of the applets. Can anyone suggest me solution or the color?

share|improve this question
Could you add a screen shot of the problem you are having with the display? – user40980 Apr 21 '13 at 23:36
up vote 0 down vote accepted

To draw usingbackground color can use which returns the background color, this can be set to the graphics object you are painting to.

Use double buffering, first clear the area by making a rectangle using default color :

g.setColor(backgroundColor); g.fillRect(0, 0, fullWidth, fullHeight);

and then draw only active lines. So no complicated algorithm, just start from a clean slate and draw only what is required


fillRect(int x, int y, int width, int height) on same page

Double buffering is explained here

and you could make your own image to process off screen

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.