I am new to Java. I was just looking for how to make the Java program wait, and said that it was using the Thread.sleep() method. However, when I do this, an error occurs:
error: unregistered exception InterruptedException; must be caught or declared abandoned
I fixed this by adding throws InterruptedException to the method declaration, and now it works.
However, when I called the method, I got an error again. People say they use a throw and a catch block, but I'm not sure how to do this. Can someone help me here?
In any case, the code for Draw.java (with the sleep () method):
package graphics.utilities; public class Draw { public static void DS(int[] c) throws InterruptedException { \\ .. Drawing Algorithms Thread.sleep(2000); \\ .. More Drawing Algorithms } }
And in Square.java (call DS ()):
package graphics.shapes; import graphics.utilities.*; public class Square implements Graphics { int x1,y1,s; public Square(int x1,int y1,int s) { this.x1 = x1; this.y1 = y1; this.s = s; } public void GC() { System.out.printf("Square Coordinates:%n Start Point:%nx: %d%ny: %d%n Height/Width: %d%n%n" , this.x1,this.y1,this.s); } public void D() { int x2 = x1 + s; int y2 = y1; int x3 = x1 + s; int y3 = y1 + s; int x4 = x1; int y4 = y1 + s; int[] c = {x1,y1,x2,y2,x3,y3,x4,y4}; Draw.DS(c); } }
Thanks.