Examples of Useful Java Classes

(pre-defined)

class Rectangle

Fields

  int x;      ˆ

  int y;      ˜    all are accessible

  int width;  ˜    as public variables

  int height; ¯

 

Rectangle Constructors

Rectangle(int x, int y, int width, int height)

Rectangle(int width, int height)  //x=y=0

Rectangle()  //x=y=width=height=0

3 others


Note:  No Rectangle(int x, int y)

Why?


Rectangle methods  (partial list)

Enlarge rectangle, if necessary, to include point x,y

Enlarge to include r

Asks whether point x,y is inside this rectangle.

Move by dx, dy

 

To Next Slide To Previous Slide To Contents