Here is the code in PackageWrapping class:
public void show(Vector<Point>POINTS)
{
Vector<Line>LINES = this.lines(POINTS);
Vector<Line>PWLINES = new Vector<Line>();
for (int i = 0; i < LINES.size(); i++)
{
PWLINES.add(LINES.get(i));
this.G.transfer(POINTS, PWLINES);
this.G.repaint();
try
{
Thread.sleep(500);
}
catch (Exception e){}
}
}
And here is how it looks in Graphic class:
public void paint(Graphics G)
{
G.setColor(Color.white);
G.fillRect(0, 0, 400, 400);
G.setColor(Color.red);
for(int i = 0; i < this.LINES.size(); i++)
{
Point A = this.LINES.get(i).A;
Point B = this.LINES.get(i).B;
for (int j = 0; j < 5; j++)
{
G.drawLine(A.x-2+j, A.y, B.x-2+j, B.y);
G.drawLine(A.x, A.y-2+j, B.x, B.y-2+j);
}
}
G.setColor(Color.blue);
for(int i = 0; i < this.POINTS.size(); i++)
{
Point P = this.POINTS.get(i);
G.fillOval(P.x-5, P.y-5, 10, 10);
}
}
And here is how it is in Main class:
Graphic G;
....
public Main()
{
....
G = new Graphic();
G.setBounds(50, 35, 400, 400);
CONTAINER.add(G);
G.addMouseListener(this);
.....
G.repaint();
}
.....
public void actionPerformed(ActionEvent arg0)
{
if (arg0.getSource() == pw)
{
PackageWrapping PW = new PackageWrapping(G);
PW.show(POINTS);
}
}
Hope I was clear enough. The funny thing is, that after I click the button pw, the program gets stuck (I sometimes put some System.out.println("whatever...") just to see that it perfectly is written each 500ms!!!), the button is like it was pressed and not released... and after it makes everything it just then shows the final result(without showing the middle results that I want so much). I did not implement anything related to Threads however. Where do I have to do that?
public class Main extends JFrame implements ActionListener, MouseListener
public class PackageWrapping
public class Graphic extends Canvas
Did I have to put anything more somewhere?
By the way, I've read a lot of articles related to Threads and they are working to me, but not working when I am trying to use them for my graphics!
Thank you for your help.