Code Samples From A Java Program

The DrawObjectListManagerClass

Responsibility: Manages A List Of Draw Objects, Draws Each Object In List.

class DrawObjListMgrClass
{
private static DrawObjectClass DrawObjectList[] ;

public void DrawShapesInDrawObjectList(java.awt.Graphics g)
{
int NumberEntries ;
int ListEntry ;
DrawObjectClass TmpDO ;

TmpDO = new DrawObjectClass() ;

NumberEntries = GetActualNumberEntriesInDrawObjectList() ;

if ( NumberEntries > 0 )
{
for ( ListEntry = 0 ; ListEntry < NumberEntries ; ListEntry = ListEntry + 1 )
{
GetDrawObjectFromDrawObjectList(ListEntry, TmpDO) ;
TmpDO.DrawShape(g) ;
}
}
}
}
The Draw Object Class

Responsibility: Manages Properties Of A Single Draw Object, Draws Using Properties

class DrawObjectClass
{
private java.awt.Rectangle m_rect ;
private int m_lineWidth ;
private int m_shape ;
private int m_lineColorRed ;
private int m_lineColorGreen ;
private int m_lineColorBlue ;

public void DrawShape(java.awt.Graphics g)
{
switch (m_shape)
{
case DefaultManagerClass.LINESHAPE:
DrawShapeClass.DrawLineShapeAt( g, m_rect.x, m_rect.y,
m_rect.x + m_rect.width,
m_rect.y + m_rect.height ,
m_lineWidth,
m_lineColorRed, m_lineColorGreen, m_lineColorBlue ) ;
break;
case DefaultManagerClass.RECTSHAPE:
DrawShapeClass.DrawRectangleShapeAt( g, m_rect.x, m_rect.y,
m_rect.x + m_rect.width,
m_rect.y + m_rect.height ,
m_lineWidth,
m_lineColorRed, m_lineColorGreen, m_lineColorBlue ,
false ) ;
break;
case DefaultManagerClass.ROUNDRECTSHAPE:
DrawShapeClass.DrawRoundRectShapeAt( g, m_rect.x, m_rect.y,
m_rect.x + m_rect.width,
m_rect.y + m_rect.height ,
m_lineWidth,
m_lineColorRed, m_lineColorGreen, m_lineColorBlue ,
false , 10 , 10 ) ;
break;
case DefaultManagerClass.ELLIPSESHAPE:
DrawShapeClass.DrawEllipseShapeAt( g, m_rect.x, m_rect.y,
m_rect.x + m_rect.width,
m_rect.y + m_rect.height ,
m_lineWidth, m_lineColorRed, m_lineColorGreen,
m_lineColorBlue ,
false) ;
break;
}
}
}
The Draw Shape Class

Responsibility: Static Helper Class, Draws Objects Given Parameters

class DrawShapeClass
{
public static void DrawRectangleShapeAt(java.awt.Graphics g,
int x1, int y1, int x2, int y2,
int linewidth , int red , int green, int blue ,
boolean fillrect)
{
NewColor = new java.awt.Color(red,green,blue) ;

CurrentColor = g.getColor() ;
g.setColor( NewColor ) ;

for ( Counter = 0 ; Counter < linewidth ; Counter = Counter + 1 )
{
if ( !fillrect )
{
NewX1 = x1 + Counter ;
NewY1 = y1 + Counter ;
NewX2 = x2 - Counter ;
NewY2 = y2 - Counter ;
DX = NewX2 - NewX1 ;
DY = NewY2 - NewY1 ;
g.drawRect(NewX1,NewY1,DX,DY) ;
}
else
{
DX = x2 - x1 ;
DY = y2 - y1 ;
g.fillRect(x1,y1,DX,DY) ;
}
}

g.setColor(CurrentColor) ;
}
}
Return