SR3. In this exercise, you will study class Point and practice reading the API.
Class Point is in package java.awt , so type this import statement into Java:
Now open this url in your browser:
In the upper-left frame in the window, click on “ java.awt ”. In the lower-left
frame, scroll down and select “ Point ”. In the right frame you will see a descrip-
tion of class Point . Notice that it says that an instance of class Point is a point
representing a location in ( x , y ) coordinate space, specified in integer precision,
by which they mean type int . Scroll down until you see “Field Summary”,
“Constructor Summary”, and “Method Summary”. These show you the compo-
nents of every object of class Point . On a piece of paper, draw one folder
(instance) of class Point , putting in it all the components. Do not forget to draw
x and y as variables, and for each method, include the types of its parameters.
Create two instances of class Point :
Point p1= new Point();
Point p2= new Point(5, 6);
Class Point lets you access the fields x and y . See what their values are in
p1 and p2 . For example, evaluate p2.x .
In the Point webpage, the summary for x does not say what its initial value
is. To find out what value x has when you do
click on “ Point() ” in the Constructor Summary. See whether the information
that comes up tells you. Then use the back button to get back to the Constructor
Now look through the Method summaries. Type in some method calls and
see what happens. For example, try, one after the other, these method calls:
See what function toString gives you by typing in p2.toString() .
Experiment until you are familiar with Point and its methods.
Customizing a class to suit our needs
A subclass definition
Suppose we want to change the title of a JFrame to contain its origin (the posi-