|
-
December 6th, 2010, 03:56 AM
#1
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);
}
}
}
}
-
December 6th, 2010, 05:44 AM
#2
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 Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|