Introduction to Computer Graphics and Java Programming for Artists

School of the Museum of Fine Arts ::: Continuing Education

George Aroush, instructor

Lecture Two -- What is an OS; Introduction to Graphics and Graphics Functions



  1. The handouts named:
  2. Sample Programs in Batch Two:
  3. "Computer Graphics : Principles and Practice" by: James D. Foley



    Do before our next lecture

  1. Write a program that plots pixels in the four corners and the center of a 640 x 480 drawing area.
  2. Write a program that makes a connect-the-dots puzzle (without the delay for now.)
  3. Write a program that draws a star (any size and number of points.)
  4. Modify so that it produces a very different pattern (or write one anew.)

Back to the top of this page. Back to main Index


The Microcomputer

What is a Computer?

A computer is a vast network of electronic circuits, some of which store information and others of which make selections, move information around and modify it. The information stored in a computer is, to the computer, meaningless patterns of ON and OFF switches. To the computer an ON switch is simply a true/positive voltage, while an OFF switch is simply a false/no-voltage. To us, depending on how the information is presented, it can be an image, movement, prose, music, cash flow, a physics experiment, or speech. If the patterns are made by an artist, they are known as art.

The operation of a computer is the result of an expertly choreographed joint effort between hardware and software. A hardware comprises a computer's physical components -- its circuitry, disk drives, keyboard, video screen, and so on. Software is what brings the hardware to life. Software is a series of detailed, stepwise instructions that programmers assemble in order to control the hardware and turn it into a tool for specific tasks, everything from writing memos to drawing floor plans to creating computer art. Software is stored by hardware (on disks, for example), but the instructions themselves are invisible. We can't look at a disk and tell whether it contains software any more than we can determine what someone knows by looking at his or her brain.

The Structure of a Computer

Software and hardware work together much like our brain and body do. A person's brain handles the intellectual work -- taking in information and making decisions -- and uses the body to interact with the outside world. At the heart of a computer is the Central Processing Unit (CPU) In a computer, the CPU, follows the software's instructions -- shuttling information, performing calculations, turning pixels on/off and making decisions -- and uses the hardware to interact with us, receiving our instructions from the keyboard and mouse and supplying responses using the screen or a printer.

In minicomputers and mainframe computers, the workhorses of business and scientific computing, central processing units comprise many separate electronic components -- often more than exist in an entire PC. In a personal computer like the IBM PC, however, the CPU is a one-piece affair. The PC is built around a microprocessor -- a single component that performs the same basic jobs as the CPU in a larger computer. A microprocessor is an Integrated Circuit, also called an IC or chip. The latter term is a tribute to the substance from which ICs are made -- minute wafers, or chips, of silicon. A single IC contains the electronic equivalent of thousands -- in many cases, millions -- of separate electronic components. It's an entire circuit that would have filled a gymnasium thirty years ago -- miniaturized to fit on a head of a thumbtack.

The IC was the most significant advance in electronics since the dawn of transistors marked the dusk of vacuum tubes. A CPU has a number of registers or temporary information storage bins, a program counter to keep track of where it is in its program, and a decision-making calculator called the Arithmetic-Logic Unit (ALU). It is connected to different forms of computer memory and to input/output (I/O) circuitry. It can get data from the memory, act upon it, modify it, and put it somewhere else. Most of the CPU's work is involved in moving information around (in reality that's all what a computer can do, move data around and no more!)


A computer's CPU is a central switching station, but a switching station isn't worth much if it isn't connected to something. A CPU is connected to many components, but one of the most important is memory, the computer's storage area for software and for data -- the information we're creating and storing, whether a letter, a name-and-address list, or a picture. (Note: don't get confused with the storage of a disk and memory, the two are different type of storage.)

A CPU must be able to keep track of what's stored where. If it were to use memory indiscriminately, it might load a program into an area that already contains a program, or worse, your own data. Thus, each location in memory has its own address, the computers memory equivalent of post office box numbers. By keeping track of memory addresses, the CPU is able to determine where things are, and equally important, how much unused memory, or free memory, is available for new data or more programs. The computer has two different kinds of memory, RAM and ROM. RAM (Random Access Memory) is a memory the CPU can read (get data from) and write to (store data in.) ROM (Read Only Memory) is unchangeable. The CPU can only get information from it, not store anything in it. ROM is used for the basic operating system of the computer; hundreds of small programs that do everything from reading the keyboard to putting graphics on the screen. RAM is used to hold temporary stuff -- programs, data for images, text you type, etc. It has one property you should keep well in mind. When you switch off the computer, everything stored in RAM vanish. Fortunately, there are ways of storing stuff in RAM semi-permanently.

Input and Output (I/O)

For a computer's information storage and manipulation skills to be useful, it must be able to get information and instruction from us and to show us the result of its work. The circuitry and devices responsible for interacting with us form the computer's Input/Output, or I/O, section. A PC's input devices are the keyboard and the mouse, and we can use both to either issue instructions or create data. The PC's primary output device is the video screen. The speaker also qualifies as an output device. It allows the PC to aurally inform us of a problem or to get our attention before performing an operation that would result in data loss, such as quitting a program without saving our work.

Other output devices are printers such as printers, which allow us to commit our work to paper. A disk drive is also an input/output device. A disk drive is an I/O device for the PC itself; it lets the PC read (input) information into its memory, and write (output) information form memory to disk. Input/output devices attach to the computer by means of sockets called ports. The word "port" may sound like jargon at first, but when you think of a shipping port -- a point where ships can "connect" with a city to discharge and take on cargo -- you can see how the term applies to input/output devices. In its manuals, PCs doesn't use the term "port," but instead, calls these I/O sockets connectors, since that's what you see on the outside of the machine.

Operating Systems (OS)

Every computer has an Operating System (OS). An OS may be viewed as an organized collection of software extensions of hardware consisting of control routines for operating a computer and for providing an environment for execution of programs. Other programs rely on facilities provided by the operating system to gain access to computer-system resources, such as files and input/output devices. Programs usually invoke services of the operating system by means of operating-system calls. In addition, users may interact with the operating system directly by means of operating-system commands. In either case, the operating system acts as an interface between users and the hardware of a computer system. The PC has an OS called Windows 95/98/NT. Many people consider the OS to be a special program. Unfortunately that is wrong; Windows 95/98, NT 4.0 and DOS are just programs, like Lotus 123, Microsoft Word, Visual J++, etc.

Data, Files & Directories/Folders

As we work with the PC, we will generate lots of data. Data consists of the texts for our programs and the actual programs themselves, images, other texts, and patterns of numbers. This data will accumulate in the RAM, the PC's Read/Write memory. Our data is vulnerable in RAM, though; a system crash, power failure, or simply turning off the PC will wipe out our data as if it never existed! Something more permanent is needed. (We wouldn't do our best drawing in the sand on the beach, would we?) The solution is to store the data outside of the computer on a magnetic disk. The PC uses so called micro-floppy disk, and the OS takes care of moving data from RAM to disk and via-versa.

Data is saved on a disk in the form of a file. A file is a region of the disk with a particular name that is used to put data in the file and get it out of it. A disk can hold hundreds of files and it can often be a difficult and slow process to find a particular file. To over come this problem, files are often grouped together in directories/folders, which are somewhat like the drawers in a file cabinet. A directory/folder can hold files and sub-directories/sub-folders, which are themselves directories/folders.

Back to the top of this page. Back to main Index.


History and basic concepts of Computer Graphics

The early days

In the beginning, before the concept of computer graphics existed, there was period of computer "doodling." This was back in the early 1950s, when computers were being used almost exclusively to perform complex arithmetic "number crunching" functions. The answer to whatever equation was being solved was first converted from the language being used to solve the equation into American Standard Code for Information Interchange (ASCII), a simple code for representing upper and lowercase letters, numbers, and punctuation marks and other symbols. The ASCII numbers were in turn used to drive a Teletype-like printer in which the ASCII code was converted into a series of electrical signals that caused the Teletype keys to strike the paper. By using the period, dash, and other standard symbols in the ASCII charter set, crude images were created -- probably the first examples of computer-generated art.

Other early examples of computer-generated graphics were created by character generators. Rather than converting ASCII code into the keystroke of a Teletype machine, a character generator converts the code into a matrix of dots that can be printed with a do-matrix printer or displayed on a television screen. Because a character generator works with a particular basic matrix size -- nine dots by nine dots per character, for example, it is possible, by turning dots on and off, to create a large variety of graphics symbols in addition to the basic ASCII character set, and they can be combined into computer-generated graphics.

Other early computer-graphics work was performed with plotters -- devices capable of creating hard-copy images by moving a series of pens across the paper in response to control signals from the computer. In the computer/plotter relationship, the paper is seen as a grid with x, y coordinates corresponding to an x, y coordinate scheme established in the computer's software -- as if an invisible graph were drawn on the page. The computer can draw a line at any location on the page by issuing a command to touch the pen down at coordinate point x, y and then drag the pen to a second point x, y. If the line represented by end points x1, y1 and x2, y2 is treated as the radius of a circle with its center at x1, the plotter can be instructed to make a mark at each point solving the equation for a circle. One of the earliest plotter was made by Calcmp, in 1959.

The arrival of Screen-Based Systems

Despite all these early experiments with computer graphics, however, it was not until about ten years after the invention of the computer, in around 1955, that someone thought of displaying output not on paper but on a display screen. This led to the development of the screen-base system that in turn opened the door for the development of today's computer-graphics consciousness.

One of the first places to break the mold, to explore the revolutionary idea of using a cathode-ray tube (CRT) screen not to display an electrical wave-form, as on a television set or oscilloscope, but to graph the contents of a computer memory, was the MIT Lincoln Lab, with its TX-0 computer in the mid-1950s. At that time, MIT was using its computer to solve problems for a variety of scientific applications. To use its services, scientists would supply data and/or a program they had written, and the MIT team would run the problem on the computer overnight. Before the CRT hookup, there was only one option for getting the results: printout that would often consume literally reams of paper for a problem. The CRT offered an exciting new option. The computer output could be formatted into a chart or graph, and the graph photographed onto ordinary 35-millimeter film. In the morning, the submitting scientist could carry the results of the problem away in a small box of slides. The MIT system, of course, was not exactly interactive. Data was fed in, the computer did its number crunching, and several hours later the CRT screen could be photographed. Those who consider the era of modern computer graphics to have begun only when the graphics became interactive -- that is, when systems were developed in which a manipulation by the operator would cause a more or less immediate graphical response by the computer -- credit a U.S. Army project, developed around the same time as the MIT displays, as being the real origin of computer graphics.

Interactive Computing

The Army's SAGE air defense system used a primitive form of interactive computer graphics to locate the position of suspected enemy aircraft and missiles. The operator sat in front of a display that looked like a radar screen and held light pen -- a device shaped like a gun with a small photoelectric cell at its point. By using the light pen to point at symbols and identifying marks displayed on the screen, the operator could indicate the position of potentially unfriendly aircraft to the computer database, which could then track and pay special attention to the indicated marks.

Several developments in the early 1960s must also be counted among the midwives at the birth of computer graphics. The DAC-1 system, set up on an IBM 7094 mainframe computer at the General Motors research lab was a very early Computer Aided Drawing (CAD) system. Used to produce electronic sketches of proposed automobile designs, it is said to have increased productivity by 33 percent. The Itek optics design system, inspired by work done by the SAGE design team, was used to portray light rays moving through a series of lenses to simulate the complex processes used in lens design.

Around the same time as the Itek system, DEC introduced its first PDP-1 computer, which eventually led to the PDP-11, and then the VAX series, mainstays in the world of computer-graphics hardware. In 1962, Ivan Sutherland, working on the MIT Lincoln Lab's TX-2 and Whirlwind computers, wrote "Sketchpad." A seminal Ph.D. thesis that outlined software for interactive graphics, Sketchpad has earned Sutherland the unchallenged title of "father of modern computer graphics." The first truly interactive system, Sketchpad allowed the user to enter data into the computer and then see the results on the CRT almost immediately. Like the earlier SAGE system, Sketchpad used a light pen to signal the location of the drawing tip to the computer memory. But Ivan's system was "user friendly"; it allowed artists and engineers to draw objects (lines, circles, triangles, and even abstract shapes) on a blank screen that could as easily be a blank canvas. This was a moment of revolution -- a stirring vision of the future. Indeed, except for the addition of color and changes in a few minor details concerning how the graphics processing is accomplished, the 1963 version of Sketchpad has remained virtually unchanged in 95 percent of the graphics programs available today, including those that run on home computers. Thus, with the development of this remarkable device, Ivan Sutherland invented modern interactive computer graphics.

Not many months later, inspired by the TX-2 graphics project, the new formed Digital Equipment Corporation (DEC) introduced its first commercially available graphics product, the DEC 30. In 1965, IBM introduced its 2250 output display system, based on work that had come out of the General Motors DAC-1. The 2250 was an interactive-graphics system that used the 2250 display terminal as an output device for graphics generated by the new IBM 360 mainframe computer; the price of the system was over $100,000. Shortly after that, Control Data Corporation (CDC) came out with the Digigraphics display, base on the hardware and software used in the Itek optics display system. Computer graphics was born.

A Powerful blend of Technologies

"Computer graphics is a combination of the two most powerful, all-pervasive technologies that this civilization has come up with thus far: digital computer and television," says Richard Shoup, who developed a method of storing images in digital memory that allows them to be seen on standard television sets. "Combining those two has been a powerful piece of synergy." The linking of television displays and the computer, allowing the contents of the computer's memory to be displayed on the screen, has been, perhaps, the most important advance in the development of computer graphics (besides the obvious contributions of lower memory cost and smaller size.) The technology that has made all of the developments of computer graphics possible resides primarily in the CRT, of which the standard television picture tube is the best-known example.

A CRT is essentially a large vacuum tube of the type originally used throughout the electronics industry. Voltage applied to the cathode (a positively charged metal pallet) causes a flow of electrons toward the anode (a negatively charge plate.) Through the use of magnets, the electrons are focused so that they form an extremely fine beam of particles, which shoots forward toward the front of the tube. On the way, the beam is directed by another set of magnets or electrostatic charges that deflect it horizontally and vertically base on voltages applied to coils and magnets surrounding the neck of the tube. Because horizontal and vertical voltages are quite specifically defined, it is possible to aim the electron beam very accurately at the front of the screen, and therefor to covert the x, y coordinates of the DPU into specific location on the screen display. At the front of the tube, the beam of electrons hits a layer of phosphors that glow briefly -- the more electrons that strike them the brighter they glow -- then quickly fade. This general technology is used in almost every display device except the most recent kinds, which use liquid crystals and plasma screens and operate on a different principle.

The Key behind the Advancement

The fuel for this brilliant intellectual (and even, at times, artistic) fire was serious military-research money. Why was the Department of Defense (DoD) so interested in computer graphics? Quit simply, it was evident that a flight simulator was just around the corner. The flight simulator was seen as an invaluable training tool for pilots. It would display a simulated view of the landscape outside the training-cockpit window, and the landscape would change as the pilot manipulated the simulator's controls. The people at the Department of Defense knew that Evans and Sutherland were the ones who could make the flight simulator a reality. It is one of the great ironies of modern computer graphics that almost all of the intriguing now art forms, the fascinating television commercials, and the incredible movie special effects that have become so intertwined with our culture actually had their origins in military research. The work at Utah (where Evens and Sutherland worked) proceeded along several lines simultaneously, all concentrating on the need to grow beyond vector base graphics; as useful as the vector-generated image was for scientific purposes, it could not simulate reality well enough to train a pilot to fly through an imaginary landscape or land on an imaginary ship at sea. A series of vertex points and connecting lines is sufficient to suggest a runway to a trained pilot, but for one just learning, something more is needed; a skin or surface must be stretched over the lines to give them substance and weight.

Back to the top of this page. Back to main Index.


Beginner's Java Graphics Methods/Functions: Part I

Java and the Browser

To program in Java so that the Applet that we create runs in a browser, we must write a special version of a Java program that makes itself browser aware. Instead of spending time this week looking at those issues (the meaning of "browser aware"), we will postpone it for next week in favor of learning how to do graphics in Java first.


Most microcomputers generally use one of two operating modes to create screen displays. In text mode, the computer displayed text by retrieving the appearance of each character from a character-generator chip. In graphics mode, the computer displayed graphics by selectively turning on or off the dots on the screen -- the picture elements, or pixels. Pixel, is the smallest unit a computer can display. Pixels come in various sizes and shapes, depending upon the type of display that you are using, although from normal viewing distance they look like dots and alike.

Screen Coordinates System

Pixels, lines and areas are located on the screen with X and Y coordinates, such as are commonly used on graphs. On most computer screens, the origin, where X and Y both equal 0, is in the upper left hand corner. The Y coordinates, which determine vertical location, increase as one moves down the screen. The X coordinates, which determine horizontal location, increase from left to right. There are no negative coordinates. 0 is the minimum value of a screen coordinate. The maximum value of X is one less than the resolution. When talking about a particular location on the screen, the X coordinate is given first, then the Y. So (0, 0) is the coordinate of the origin at the upper left corner of the screen; (100, 100) is the coordinates just to the lower right corner of the origin.

Color and Gray-Scale Video

When you look closely at a color display monitor, you can see that each color pixel is actually comprised of three much smaller patches of red, green, and blue light. Those three colors are the primary colors, the basic building blocks of white light. Because these triads of colored light are too small to see individually, the eyes merge them into a single, color pixel. Each pixel's triads of red, green, and blue light are created by three electron guns (one for each color) in the video tube's neck. The tube's inside surface is coated with red, green, and blue phosphor dots. By controlling the stream of electrons form each gun as the guns create each pixel, the display's video circuitry controls each pixel's color. (Some video monitors use just one electron gun that fires at all three types of phosphors.)


To draw a line at a particular location on the screen, we use the method:

java.awt.Graphics.drawLine(int x1, int y1, int x2, int y2);

Here (x1, y1) are two integer values (int data type) that define the start point for the line while (x2, y2), which are also integer values, define the end point of the line.

If we want to draw connected lines (the end of one line connected to another line) we call drawLine() over and over like this:

java.awt.Graphics.drawLine(10, 20, 100, 20);
java.awt.Graphics.drawLine(100, 20, 90, 50);
java.awt.Graphics.drawLine(90, 50, 57, 43);
. . . 

This in effect will draw what is called segments from the last point to a new point.

Plotting Points

The Java language does not offer any way to draw points (pixels) but we can achieve it by using the drawLine() method like this:

java.awt.Graphics.drawLine(int x1, int y1, int x1, int y1);

That is, we use the same starting point and the ending point for x1 and y1. For example to plot a point at the 10 by 15 pixels away from the origin use:

java.awt.Graphics.drawLine(10, 15, 10, 15);


The drawRect() method draws an outline rectangle. The left and right edges of the rectangle are at x and x + width. The top and bottom edges are at y and y + height.

java.awt.Graphics.drawRect(int x1, int y1, int width, int height);

To draw a filled rectangle we use the method:

java.awt.Graphics.fillRect(int x1, int y1, int width, int height);

To draw a square 50 by 50 pixels away from the origin use:

java.awt.Graphics.drawRect(50, 50, 100, 100);

This will give us a rectangle starting from the point (50, 50) and extending up to the point (150, 150)

Circles and Ovals

This method draws a circle or an ellipse such that it fits within the rectangle specified by the x, y, width and height arguments. The center of the oval is the center of the rectangle. When the value of width and height are equal we end up with a circle and when they are not equal we end up with an oval.

java.awt.Graphics.drawOval(int x, int y, int width, int height);

To draw a circle at the center of the origin with the radius of 50 pixels, use the following values:

java.awt.Graphics.drawOval(-50, -50, 50, 50);

The following will draw an oval with the center at 100, 100 with a radius of 50 for x and 80 for y:

java.awt.Graphics.drawOval(50, 20, 50, 100);

Arcs and Wedges

To draw a circular or elliptical arc use the method:

java.awt.Graphics.drawArc(int x, int y, int width, int height, int startAngle, int arcAngle);

The center of the arc is the center of the rectangle whose origin is (x, y) and whose size is specified by the width and height arguments. The two axes of the arc are given by the width and height arguments. The arc is drawn from startAngle to startAngle + arcAngle. The start angle and arc angle are in degrees, not radians. A start angle of 0 indicates the 3-o'clock position. A positive arc angle indicates a counter-clockwise rotation; a negative arc angle indicates a clockwise rotation. To draw a filled arc use the method:

java.awt.Graphics.fillArc(int x, int y, int width, int height, int startAngle, int arcAngle);

Rounded Rectangles

To draws an round-cornered rectangle use the method:

java.awt.Graphics.drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight);

The left and right edges of the rectangle are at x and x + width respectively. The top and bottom edges of the rectangle are at y and y + height.

The equivalent for a filled round-cornered rectangle is:

java.awt.Graphics.fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight);

Clearing an area on the Screen

To wipe out and clean everything (or part of a rectangular area) of the screen with the background color use the method:

java.awt.Graphics.clearRect(int x, int y, int width, int height);

Drawing Text

To write text/string on the screen we must use a special method to do so. The method that we used last week (System.out.print()) won't work as that method is not graphical. Java offer a method to draw string in graphic mode, this method is:

java.awt.Graphics.drawString(String s, int x, int y);

s is the text/string that we want to draw. x and y are the location on the screen where the text/string should be drawn. For example:

g.drawString("Hello, Java", 290, 240);

Example Programs

Three example programs are given later in this text (in batch two). shows how to plot 9 pixels. uses variables x and y in a limited way to help draw a triangle. uses several variables to help define a grid, and draw several filled rectangles and outline circles and ovals. The comments in the programs themselves should provide plenty of explanation.

Those are a list of all the graphic methods that we can use at this time. There are many other methods that require slightly more advanced programming techniques and skill (arrays of variables,) we'll learn these in couple of weeks and we will be able to write our own.

Back to the top of this page. Back to main Index.


Sample Programs -- Batch Two

 *  Program:
 *  Purpose:    To plot pixels using Java
 *  Author:     George Aroush
 *  Date:       1/1/1998
 *  Change Log: None
 *  Full description of Program:
 *      First use of graphics Java's graphical methods

public class Pixel extends java.applet.Applet
    public void paint(java.awt.Graphics g)
        g.drawLine(260, 170, 260, 170); /* Plot a pixel at (260, 170) */
        g.drawLine(280, 170, 280, 170); /* Plot a pixel 20 pixels to the right of the previous pixel */
        g.drawLine(260, 190, 260, 190); /* Plot a pixel 20 pixels below the first one */
        g.drawLine(280, 190, 280, 190); /* Plot a pixel 20 pixels to the right and below of the first one */
        g.drawLine(300, 190, 300, 190); /* Plot a pixel 20 pixels to the right and 6 pixels below*/
        g.drawLine(260, 210, 260, 210); /* Plot a pixel 40 pixels below the first one */
        g.drawLine(280, 210, 280, 210); /* Plot a pixel 20 pixels to the right and 40 pixels below */
        g.drawLine(300, 210, 300, 210); /* Plot a point 40 pixels to the right and 40 pixels below*/
        g.drawString("Hello, Java", 30, 50); /* Draw a string in the upper left corner */


    <applet code=Pixel width=640 height=480></applet>

 *  Program:
 *  Purpose:    To lines using Java
 *  Author:     George Aroush
 *  Date:       1/1/1998
 *  Change Log: None
 *  Full description of Program:
 *      Shows the use of line drawing with variables

public class Line extends java.applet.Applet
    public void paint(java.awt.Graphics g)
        int     x, y;   /* Declare two integer variables, x & y */

        x = 10;         /* Start drawing at 10, 10 */
        y = 10;

        g.drawLine(x, y, 610, 390);     /* Draw a line from (10, 10) to (610, 390)*/
        g.drawLine(610, 390, 320, 100); /* Draw a line from the last point plotted (610, 390) to (320, 100), */
                                        /* in effect we are drawing what is called a segment */

        g.drawLine(320, 100, x, y);     /* Continue the segment to x & y, forming a triangle */
        g.drawLine(160, 350, 160, 350); /* Plot a point inside the triangle */

        g.drawLine(160, 350, 300, 120); /* Draw a line from last point (i.e. 160, 350) to outside the triangle */


    <applet code=Line width=640 height=480></applet>

 *  Program:
 *  Purpose:    To different shapes using Java
 *  Author:     George Aroush
 *  Date:       1/1/1998
 *  Change Log: None
 *  Full description of Program:
 *      Shows the use of different drawing tools using Java

public class Forms extends java.applet.Applet
    public void paint(java.awt.Graphics g)
        int     h1, w1;
        int     x1, y1;
        int     x2, y2;
        int     x3, y3;
        int     x4, y4;

        w1 = h1 = 100;

            /* Define a grid of x's and y's every 100 pixels*/
        x1 = 0;
        y1 = 0;
        x2 = 100;
        y2 = 0;
        x3 = 0;
        y3 = 100;
        x4 = 100;
        y4 = 100;

            /* Draw 3 rectangles touching each other */
        g.drawRect(x1, y1, w1, h1);
        g.drawRect(x2, y2, w1, h1);
        g.fillRect(x4, y4, w1, h1);
            /* Draw 3 circles */
        g.drawOval(x3, y3, w1, h1);
        g.drawOval(x4, y4, w1 + 50, h1 + 50);
        g.drawOval(x1, y2, 50, 50);
            /* Draw four ovals with different proportions and sizes */
        g.drawOval(x1, y2, 20, 50);
        g.drawOval(x4, y1, 35, 90);
        g.drawOval(x3, y1, 100, 30);
        g.drawOval(x2, y2, 75, 110);

            /* draw a round rect */
        g.drawRoundRect(200, 200, w1, h1, 50, 50);

            /* Finish off with two more rectangles with corners on the grid */
        g.drawRect(x3, y1, x4, y2);
        g.drawRect(x4, y2, x1, y3);


    <applet code=Forms width=640 height=480></applet>

Back to the top of this page. Back to main Index.