Chiddix

IntersectTest.java

Oct 21st, 2011
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. import java.awt.Frame;
  2. import java.awt.Graphics;
  3. import java.awt.Rectangle;
  4.  
  5. public class IntersectTest extends Frame implements Runnable {
  6.  
  7.     private Rectangle firstBox = new Rectangle(50, 50, 100, 100);
  8.     private Rectangle secondBox = new Rectangle(50, 400, 100, 100);
  9.  
  10.     public IntersectTest() {
  11.         setSize(800, 600);
  12.         setVisible(true);
  13.     }
  14.  
  15.     public static void main(String[] args) {
  16.         Thread thread = new Thread(new IntersectTest());
  17.         thread.start();
  18.     }
  19.  
  20.     public void paint(Graphics g) {
  21.         g.drawRect(50, firstBox.y, 100, 100);
  22.         g.drawRect(50, 400, 100, 100);
  23.         repaint();
  24.     }
  25.  
  26.     @Override
  27.     public void run() {
  28.         try {
  29.             while (true) {
  30.                 firstBox.y++;
  31.                 if (firstBox.intersects(secondBox)) {
  32.                     break;
  33.                 }
  34.                 paint(getGraphics());
  35.                 Thread.sleep(10);
  36.             }
  37.         } catch (InterruptedException e) {
  38.             e.printStackTrace();
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment