Intersection between rectangles : Rectangle « 2D Graphics « Java Tutorial

Java Tutorial
1. Language
2. Data Type
3. Operators
4. Statement Control
5. Class Definition
6. Development
7. Reflection
8. Regular Expressions
9. Collections
10. Thread
11. File
12. Generics
13. I18N
14. Swing
15. Swing Event
16. 2D Graphics
17. SWT
18. SWT 2D Graphics
19. Network
20. Database
21. Hibernate
22. JPA
23. JSP
24. JSTL
25. Servlet
26. Web Services SOA
27. EJB3
28. Spring
29. PDF
30. Email
31. J2ME
32. J2EE Application
33. XML
34. Design Pattern
35. Log
36. Security
37. Apache Common
38. Ant
39. JUnit
Java
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Tutorial » 2D Graphics » Rectangle 
16. 41. 11. Intersection between rectangles
// This example is from the book _Java AWT Reference_ by John Zukowski.
// Written by John Zukowski.  Copyright (c) 1997 O'Reilly & Associates.
// You may study, use, modify, and distribute this example for any purpose.
// This example is provided WITHOUT WARRANTY either expressed or
import java.awt.Graphics;
import java.awt.Rectangle;

import javax.swing.JFrame;

public class intersection extends JFrame {
  Rectangle r = new Rectangle(5050100100);
  Rectangle r1 = new Rectangle(1001007575);

  intersection() {
    super("Intersection");
    setSize(250250);
  }

  public void paint(Graphics g) {
    g.drawRect(r.x, r.y, r.width, r.height);
    g.drawRect(r1.x, r1.y, r1.width, r1.height);
    Rectangle r2 = r.intersection(r1);
    System.out.println(r2);
    g.fillRect(r2.x, r2.y, r2.width, r2.height);
  }

  public static void main(String[] args) {
    JFrame f = new intersection();
    f.setVisible(true);
  }
}
16. 41. Rectangle
16. 41. 1. java.awt.Rectangle
16. 41. 2. Draw RectangleDraw Rectangle
16. 41. 3. drawRect (int, int, int, int) to draw a rectangle outline
16. 41. 4. drawRoundRect (int, int, int, int, int, int) to draw a rounded rectangle outline
16. 41. 5. Draw a three-dimensional rectangle outline
16. 41. 6. How do I...Fill shapes?How do I...Fill shapes?
16. 41. 7. Fill 3D RectangleFill 3D Rectangle
16. 41. 8. Draw Rectangle with Rectangle2D.Float
16. 41. 9. Draw RoundRectangle2D.Float
16. 41. 10. Ractangle with rounded corners drawn using Java 2D Graphics API
16. 41. 11. Intersection between rectangles
16. 41. 12. Grow a rectangle
16. 41. 13. Union two Rectangles
16. 41. 14. Clips the specified line to the given rectangle.
16. 41. 15. Returns a point based on (x, y) but constrained to be within the bounds of a given rectangle.
16. 41. 16. Checks, whether the given rectangle1 fully contains rectangle 2 (even if rectangle 2 has a height or width of zero!).
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.