A
Alan
Hi all
I am confused with the way my program behaves..
I have a class GroupDrawings which stores all primitives in a vector
and redraws them on the panel..this is the code
class GroupDrawings extends DrawOb
{
private Vector drawPrim;
GroupDrawings()
{
drawPrim = new Vector();
}
void addDrawPrim (DrawOb newPrim)
{
drawPrim.add(drawPrim.size(), newPrim);
}
void Paint(Graphics g)
{
for( Enumeration e = drawPrim.elements(); e.hasMoreElements()
((DrawOb)e.nextElement()).Paint(g);
}
}
Now when I add objects in DrawPanel class, i can add line, circle,
cubic spline etc..and they all redraw the way they are supposed
to...However i CANNOT store two different objects of the same
class..that is i cannot have two different lines becuase only second
line draws, as if the first one is not in the vector...same thing with
other primitives...Here is my code that adds object to GroupDrawings,
and i believe its where the error is..
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.setColor(dr_col);
switch (select) {
case LINE: if ( lineFlag == true)
{
if (drawings != null)
{
drawings.Paint(g);
}
drawings.addDrawPrim(line);
}
break;
case CIRCLE: if ( circleFlag == true )
{ circle.Paint(g);
if (drawings != null)
{
drawings.Paint(g);
g.setColor(Color.white);
g.setXORMode(Color.gray);
g.setPaintMode();
}
drawings.addDrawPrim(circle);}
break;
case CUBIC: if( cubicFlag == true)
{ cubic.Paint(g);
if (drawings != null)
{
drawings.Paint(g);
g.setColor(Color.white);
g.setXORMode(Color.gray);
g.setPaintMode();
}
drawings.addDrawPrim(cubic);}
break;
case FREEHAND: if( freeFlag == true)
{ freehand.Paint(g);
if (drawings != null)
{
drawings.Paint(g);
g.setColor(Color.white);
g.setXORMode(Color.gray);
g.setPaintMode();
}
drawings.addDrawPrim(freehand);}
break;
default:
break;
}
}//end paint comp
anyone has any idea what might be wrong???
I am confused with the way my program behaves..
I have a class GroupDrawings which stores all primitives in a vector
and redraws them on the panel..this is the code
class GroupDrawings extends DrawOb
{
private Vector drawPrim;
GroupDrawings()
{
drawPrim = new Vector();
}
void addDrawPrim (DrawOb newPrim)
{
drawPrim.add(drawPrim.size(), newPrim);
}
void Paint(Graphics g)
{
for( Enumeration e = drawPrim.elements(); e.hasMoreElements()
((DrawOb)e.nextElement()).Paint(g);
}
}
Now when I add objects in DrawPanel class, i can add line, circle,
cubic spline etc..and they all redraw the way they are supposed
to...However i CANNOT store two different objects of the same
class..that is i cannot have two different lines becuase only second
line draws, as if the first one is not in the vector...same thing with
other primitives...Here is my code that adds object to GroupDrawings,
and i believe its where the error is..
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.setColor(dr_col);
switch (select) {
case LINE: if ( lineFlag == true)
{
if (drawings != null)
{
drawings.Paint(g);
}
drawings.addDrawPrim(line);
}
break;
case CIRCLE: if ( circleFlag == true )
{ circle.Paint(g);
if (drawings != null)
{
drawings.Paint(g);
g.setColor(Color.white);
g.setXORMode(Color.gray);
g.setPaintMode();
}
drawings.addDrawPrim(circle);}
break;
case CUBIC: if( cubicFlag == true)
{ cubic.Paint(g);
if (drawings != null)
{
drawings.Paint(g);
g.setColor(Color.white);
g.setXORMode(Color.gray);
g.setPaintMode();
}
drawings.addDrawPrim(cubic);}
break;
case FREEHAND: if( freeFlag == true)
{ freehand.Paint(g);
if (drawings != null)
{
drawings.Paint(g);
g.setColor(Color.white);
g.setXORMode(Color.gray);
g.setPaintMode();
}
drawings.addDrawPrim(freehand);}
break;
default:
break;
}
}//end paint comp
anyone has any idea what might be wrong???