Algorithm Help Please
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Algorithm Help Please

  1. #1
    Join Date
    Nov 2010
    Posts
    15

    Algorithm Help Please

    Hello all,
    I seem to be having a little issue getting my lines to connect. With this, I'm trying to input X,Ys, then draw lines connecting them all. Though it doesn't seem like I'm going at this right.

    Here is the repaint i'm using, however only 2nd line I inserted connect then it goes crazy.

    Any help is appreciated,
    Thanks.
    Code:
    private class GraphicPanel extends JPanel
    {
    	public GraphicPanel()
        {
        	setBackground(Color.BLACK);
        }
         public void paintComponent(Graphics g)
         {
           super.paintComponent(g);
    		Graphics2D g2 = (Graphics2D) g;
           g2.setColor(Color.BLUE);
    	   if(numCalls==1)
    	   {
    		          int graphW=jsp1.getWidth();
    		          int graphH=jsp1.getHeight();
    		          if(origX>graphW)
    		          	origX=(graphW/2);
    		          if(origY>graphH)
    		          	origY=(graphH/2);
    		          originX=(graphW/2);
           			  originY=(graphH/2);
           			  g.drawLine(originX,originY,(originX+allX[numCalls]),(originY+allY[numCalls]));
          		 	  originX+=allX[numCalls];
          	 	      originY+=allY[numCalls];
          	 	      g2.setColor(Color.GREEN);
      			      g2.fillOval(originX,originY,3,3);
    		}
           if(numCalls>1)
           {
    		   for(int displayNum=numCalls;displayNum>0;displayNum--)
    		   {
    		   	 g2.setColor(Color.BLUE);
    		   	 g.drawLine((originX-allX[numCalls]),(originY-allY[numCalls]),originX,originY);
           		 g.drawLine(originX,originY,(originX+allX[displayNum]),(originY+allY[displayNum]));
           		 originX+=allX[numCalls];
           		 originY+=allY[numCalls];
           		 g2.setColor(Color.GREEN);
           		 g2.fillOval(originX,originY,3,3);
    		   }
    		}
         }
    }

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Algorithm Help Please

    There's not enough information to really work out what you are trying to do or what is happening.

    Basically you need to do some debugging yourself. Add some print statements to output the state of the variables and the co-ordinates you are drawing and you should be able to work out where it is going wrong.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center