Results 1 to 2 of 2

Thread: Help

  1. #1
    Samoyed is offline Member
    Join Date
    Dec 2015
    Posts
    1
    Rep Power
    0

    Default Help

    WHy my shape will change when click to square from line?it will save the shape drew.
    XML Code:
    public void paintComponent(Graphics g)
    {
    super.paintComponent(g);
    setBackground(bgColor);
    // Custom code to paint all the graphics from the List
    for (DrawingArea.Drawing drw : drawing) {
    g.setColor(drw.getFGColor());
    Point startPoint = drw.getStartPoint();
    Point endPoint = drw.getEndPoint();
    int x=Math.min(startPoint.x,endPoint.x);
    int y=Math.min(startPoint.y,endPoint.y);
    int width=Math.abs(startPoint.x-endPoint.x);
    int height=Math.abs(startPoint.y-endPoint.y);
    if (choice==1){
    g.fillRect(x,y,width, width);
    repaint();}
    else if (choice==2){
    g.fillRect(x,y,width,height);
    repaint();}
    else if (choice==3){
    g.fillOval(startPoint.x,startPoint.y,endPoint.x, endPoint.y);
    repaint();}
    else if(choice==4){
    	g.drawLine(startPoint.x,startPoint.y,endPoint.x, endPoint.y);
    repaint();
    }
    
    }
    // Paint the graphics as the mouse is being dragged
    g.setColor(fgColor);
    if (startPoint != null && endPoint != null) {
    int x=Math.min(startPoint.x,endPoint.x);
    int y=Math.min(startPoint.y,endPoint.y);
    int width=Math.abs(startPoint.x-endPoint.x);
    int height=Math.abs(startPoint.y-endPoint.y);	
    if (choice==1){
    g.fillRect(x,y,width, width);
    repaint();}
    else if (choice==2){
    g.fillRect(x,y,width,height);
    repaint();}
    else if (choice==3){
    g.fillOval(startPoint.x,startPoint.y,endPoint.x, endPoint.y);
    repaint();}
    else if(choice==4){
    	g.drawLine(startPoint.x,startPoint.y,endPoint.x, endPoint.y);
    repaint();
    }
    }
    }

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Help

    Please edit your post and wrap your code with code tags:
    [code]
    **YOUR CODE GOES HERE**
    [/code]
    to get highlighting and preserve formatting.

    Be sure the code is properly indented to show its logic.
    If you don't understand my response, don't ignore it, ask a question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •