Java Reference
In-Depth Information
Monitors and pixels . The word pixel , a shortening of picture element , is the smallest rectangle
that your monitor can draw. The upper left corner of your monitor is called pixel
(0, 0) . In a pixel (x,y) , x is called the x-coordinate and y the y-coordinate.
Value x measures the distance from the left of the window and y measures the
distance from the top of the window, both in pixels.
The position of each window on your monitor is given by the pixel (x, y) of
its top left corner. The height and width of a window are also given in pixels.
Activity 1-5.5
explains pixels
and talks about
the resolution
of a monitor.
Remember our brief discussion about how you should only rarely directly
access instance variables? In fact, there are ways to limit access to instance vari-
ables and methods that you write, and you will learn about them later when you
learn how to write your own classes. Folder a3 shows variable title , but it is
grayed out, and we cannot access it directly because the programmers who wrote
class JFrame have limited our access to it. (In fact, we do not know the real name
of this variable or precisely how the title is stored in it!) We display this variable
only to make sure that you know this is the folder for the given url. This discus-
sion perhaps seems a tad silly right now, but information hiding is a vital strate-
gy when writing large programs.
In the folder are some instance-method names followed by parentheses;
some have a type inside them, which indicate the type that an argument of a call
on the method must have. These are only a few of the methods that are in each
instance of class JFrame .
The instance methods are used to access and manipulate parts of the JFrame .
Of course, the name of a method is not enough for us to know precisely what it
does. For that, we have to look in the Java API specs —Appendix II tells you how
to do this. Here, we briefly discuss some of the methods.
When a manila folder of class JFrame is first created, the associated window
does not appear on your monitor. It is hidden. Execution of the procedure call;
causes the window to appear on your monitor, probably in the upper left corner,
and quite small. You can drag its lower right corner to make it bigger, and the
window will be like the right picture in Fig. 1.5.
In the call , “ window ” indicates that we are dealing with the
manila folder whose name is in variable window . The “ . ” is used to indicate that
Figure 1.5:
Two instances of JFrame —windows on your monitor
Search WWH ::

Custom Search