drawing primitives and vectors

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???
 
V

VisionSet

Alan said:
Hi all


I am confused with the way my program behaves..
what might be wrong???

A few potential problems here:

Paint(Graphics g) should be paint(Graphics g) or name it something
different.

What is DrawOb? where is the code?
Rest of DrawPanel class where is the code?

paintComponent() the switch is just choosing one object to draw, it would
need to draw all in the Vector in one go.

And you can't store primitives in a Vector - bad terminology.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top