In this lab, you will use the Java program authoring tool Eclipse (already present on your PC) to create a simple Java program. When you use Eclipse, you begin by creating a project that contains the files that constitute your Java program. Eclipse can have many projects open simultaneously, but in this first lab you'll only create and work on a single project called SE1010 Lab 1. You can either read instructions or watch a video on creating a new project in Eclipse.
Recall from lecture that, as a general rule, every Java program must have a main class - that is, a class that contains at least one method named main - in order to be able to run. When you run a Java program - say, by double-clicking on a program icon - the Operating System (Windows, in our case) and the Java Runtime Environment (JRE) send a “run” message to the program by calling the main method in the main class. And remember, the main class can have any reasonable name.
In this assignment, you'll create a program containing a main class and main method, and then write additional Java instructions that create instances - that is, objects - of another class (that has already been written for you) called WinPlotter. The WinPlotter class implements behavior such that, by calling it's methods, you can create a window and draw simple images in that window. The UML Class Diagram of the WinPlotter class is shown below.
Download the WinPlotter class by following this link. Save the file to a location on your directory that is convenient for you. The video shows how to include this class in your project.
Follow the WinPlotter link for online documentation (created with a tool we'll learn about later called JavaDoc) on the WinPlotter class and its various methods. Review this documentation in order to familiarize yourself with the capabilities of the WinPlotter class. Once you setup Eclipse, you'll also be able to view this documentation directly from within the Eclipse environment.
Your assignment is to write a Java application consisting of a main class called Lab1App that contains a main method. Within the main method you are to create three instances (objects) of the WinPlotter class, and send each object various messages such that it draws images into the windows managed by these objects. You can use your mouse to position the window anywhere on your screen, just as you would with any typical window. You cannot, however, size a WinPlotter window by dragging the corner with your mouse; you must resize the window programmatically by inserting Java code in your main class's main method that call the appropriate method of the WinPlotter class object. Start out by creating just one instance of the WinPlotter object, in order to keep things simple at the beginning. For the first WinPlotter window:
Demonstrate this to your instructor before moving on to the next step!
For the second WinPlotter window:
For the third WinPlotter window:
Java code may look like English, but it's still a computer language that is primarily designed to be understandable by a computer. When well-written, it is easy for a person to understand what the instructions are doing as well. Good software developers observe certain rules when writing Java code as part of good software development practices - so get started on the right track. Here are some basic rules for writing Java instructions that you should follow for starters:
Finally, test your program and make certain that it works correctly and conforms to all of the requirements stated above.
Along with your completed Java program, for this lab you must also:
You may draw these diagrams by hand, but be sure they are neat and legible.