Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Frame;
- import java.awt.Graphics;
- import java.awt.Rectangle;
- public class IntersectTest extends Frame implements Runnable {
- private Rectangle firstBox = new Rectangle(50, 50, 100, 100);
- private Rectangle secondBox = new Rectangle(50, 400, 100, 100);
- public IntersectTest() {
- setSize(800, 600);
- setVisible(true);
- }
- public static void main(String[] args) {
- Thread thread = new Thread(new IntersectTest());
- thread.start();
- }
- public void paint(Graphics g) {
- g.drawRect(50, firstBox.y, 100, 100);
- g.drawRect(50, 400, 100, 100);
- repaint();
- }
- @Override
- public void run() {
- try {
- while (true) {
- firstBox.y++;
- if (firstBox.intersects(secondBox)) {
- break;
- }
- paint(getGraphics());
- Thread.sleep(10);
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment