Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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? –  MichaelT Apr 21 '13 at 23:36

1 Answer 1

up vote 0 down vote accepted

To draw usingbackground color can use http://docs.oracle.com/javase/6/docs/api/java/awt/Component.html#getBackground() 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

Refernece http://docs.oracle.com/javase/6/docs/api/java/awt/Graphics.html#setColor(java.awt.Color)

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

Double buffering is explained here http://docs.oracle.com/javase/tutorial/extra/fullscreen/doublebuf.html

and http://stackoverflow.com/questions/4430356/java-how-to-do-double-buffering-in-swing you could make your own image to process off screen

share|improve this answer

Your Answer

 
discard

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.