Hi guys,
I have a file named DrawPanel and this class is supposed to draw different shapes which i declared before by using mousedrag. I am not able to draw more thatn one shape and put them in an array.It seems that i don't know where to change the value of shapeCount in my code.The followings are part of my code:
I am completely messed up. I would be appreciate if anybody can help me to solve my problem.
public void mousePressed(MouseEvent event)
{
System.out.println("MousePress...");
x1 = event.getX();
y1 = event.getY();
//currentShape = shapes[shapeCount-1];
repaint();
//shapeCount --;
System.out.println("currentShape="+currentShape);
}//end mousePressed method
public void mouseReleased(MouseEvent event)
{
System.out.println("MouseRelease,shapeCount="+shapeCount);
x2 = event.getX();
y2 = event.getY();
if(shapeType == 0)
{
//shapes[shapeType] = new MyLine(x1, y1, x2, y2,color);
//shapes[shapeType].draw(g);
shapes[shapeCount-1]= new MyLine(x1,y1,x2,y2,color);
currentShape = shapes[shapeCount-1];
System.out.println("currentshaperelease="+currentShape);
//line.draw(g);
repaint();
}
/* else if (shapeType == 1)
{
MyRectangle rectangle = new MyRectangle(x1,y1,x2,y2,color,true);
rectangle.draw(g);
//shapes[shapeType] = new Rectangle();
//shapes[shapeType].draw(g);
repaint();
}
else if (shapeType ==2)
{
shapes[shapeType] = new MyOval(x1,y1,x2,y2,color,true);
shapes[shapeType].draw(g);
repaint();
}
else */
;
}//end mouseReleased
public void mouseDragged(MouseEvent event)
{
System.out.println("mouseDrag");
x2 = event.getX();
y2 = event.getY();
//System.out.println("x1y1x2y2"+x1+y1+x2+y2);
//g.setColor(Color.BLACK);
System.out.println("shapeCountdrag="+shapeCount);
//shapes[shapeCount-1]=new MyLine(x1,y1,x2,y2,Color.black);
System.out.println("currentShapedrag="+currentShape);
//shapes[shapeType].draw(g);
repaint();
}
public void paintComponent(Graphics g){
super.paintComponent(g);
//for(int i=shapeCount;i>0;i--){
if(currentShape != null){
//shape.draw(g);
System.out.println("shapeCountPaint="+shapeCount);
//shapeCount--;
shapes[shapeCount-1].draw(g);
shapeCount--;
}
else {
System.out.println("currentshapepaint="+currentShape);
//shapeCount--;
//break;
}
//}
}