I have wrote a program that simulates memory allocation with first fit and best fit algorithms .
Now I want to associate my program with a drawing of set of boxes representing available memory segments
Before Allocation

After Allocation

So it just redraws but resizes one box and colors it … What is the easiest way to do so ?
I have a set of boxes with different sizes that will be drawn dynamically according to input when the user does some action one of the boxes will be resized and recolored and so on.
I think this is best approached using graphics.
BufferedImageof a size to fit all boxes.Graphicsinstance by calling either ofgetGraphics()orcreateGraphics().Graphics.setColor(Color)according to allocation status, then..Graphics.fillRect(int,int,int,int)orfillPolygon(Polygon)to draw the memory block.AffineTransformto scale the sizes. This would require aGraphics2Dobject to draw on.