Unformatted text preview:

CS1699Intermediate Programming and System Design Using a Mobile RobotLab 0: Java Warm-upIn this course, we will be using Symantec Visual Cafe’ 3.0a for Java 1.1.7a. As an object-oriented programming language, Java is similar in many ways to C++, so you will be able to startusing it very quickly, and then learn as you go. The Visual Cafe’ Integrated DevelopmentEnvironment facilitates the construction of GUI’s for your systems, and shares many similaritieswith other Visual IDE’s you may have used, such as Visual Basic, Visual C, etc.This lab consists of a step-by-step illustration of building a tiny, and frankly pretty useless Javasystem. By going through it carefully, though, you will be introduced to many aspects of thelanguage and the programming environment, and this will make it easier for you to do the later,more interesting labs on the robots.***1. Start Visual Cafe’. This may take a while, especially if this is the first time Visual Cafe’ hasrun on your machine. When Visual Cafe’ has opened, you should see mostly blank space onthe screen. If you instead see several open windows, select File/Close Project from the menubar.2. Open a new project by selecting File/New Project. Create an AWT Applet. You can set thisto be the default project type by selecting it and then pushing the Set Default button.Probably the most important feature of Java is that it is designed for portability: youcan design and build a single program that will run on a wide variety of platforms.This is achieved in a straightforward fashion: when you write Java code, it iscompiled into an intermediate language called Java Byte Code. Each operatingsystem then provides its own interpreter for byte code, called a Java Virtual Machine.There are several main types of Java projects, of which the most important areApplets, Applications, and Beans. Applets are programs that run within a browser,typically on a client machine. To ensure security when they are run on clients, thereare restrictions on what Applets can do. Applications are stand-alone programs thatrun on a local machine, and thus don’t have these security restrictions. A Bean is areusable component that complies with a set of standards (“the JavaBean standards”)to facilitate interoperability across systems and platforms.AWT is the Java Abstract Window Toolkit. It provides you with the tools toconstruct portable GUIs that can run on any platform, giving you the look and feel ofthat particular platform. A more recent windowing toolkit, which is included inVisual Cafe’ 3.0, is the Java Foundation Classes (JFC). The JFC provides what arecalled “Swing” components. Swing components are not yet fully supported by manybrowsers, so in this course we’ll stick to the AWT.23. Next, save your (still empty) project. Select File/Save As, and save your project to a newdirectory on a floppy disk. Go to your desktop and take a look at the files that were createdin that directory. Visual Café’ will create several new files.You’ll see that right now there’s a single .java file, namely, Applet1.java.4. Return to Visual Cafe’ and take a minute to look at the windows that are open. At the topleft is a Project Window, which shows you all the items in your project. There are three tabsat the bottom of the window that let you look at three views of your project: its Objects,Packages, and Files. Examine each view of your current project.5. Below the Project Window, you’ll see the Property List. It lets you view and access theproperties of an object. There’s currently only one object in your project, Applet1. Take alook at its properties. We’re going to build a simple calculator, so change the name of thisobject to Calculator. If you’d like, you can also change some of the other fields, such as thebackground and foreground colors and the font.6. Now go back to your desktop, and look again at the files in your directory. You’ll see thatApplet1.java has been changed to Calculator.java.Visual Cafe’ files have several different extensions. The most important ones toknow about for now are: .vep, .vpj, .ve2, and .cdb files contain various kinds of information about yourproject, and are used by Visual Café’. If you double-click a .vep file from yourdesktop, the project with which it is associated will be opened. .java files contain Java source-code .class files contain Java Byte Code (compiled Java)A note on terminology: We’ll use the terms object and instance interchangeably, andwe’ll also use the terms method and function interchangeably. You should knowthese terms from C++. Another fundamental term we’ll use is package. If you’veprogrammed in Lisp or some other languages, you’ll know about packages already.Otherwise, you can think of a package as very similar to a C++ library: it’s acollection of related files that are grouped together.Java has special requirements concerning the naming of files. These requirements areintended to make directory and file naming more rational, by associating the namesgiven to files and directories in the operating system (and even the entire network)with the names given to objects in a program. The basic rule is that each class mustbe stored in its own file, which has the same name as the class. There’s a similar rulefor packages: every package must be stored in its own directory (folder), which hasthe same name as the package.37. Make Visual Café’ your active window again. In addition to the Projects Window and theProperties Window, there’s a third open window: the Form Designer. This is where youcreate your GUI, by inserting buttons, text fields, etc. Visual Cafe’ automatically generatesJava code for the GUI you designed. To see this, right click on the Calculator object in theObjects tab of the Projects window, and select Edit Source. A window containing theautomatically generated source code will open. Take a look at it, just to get a sense of whatit’s like. In particular, note that it defines a new class, called Calculator, which extends theApplet1 class. That is, the Calculator class inherits the contents of the Applet1 class.8. You’re finally ready to design a GUI for your calculator. Go back to the Form Designer forthe Calculator object, and add a button and three textfields. The toolbar near the top of thescreen has tabs for various GUI components. Using them, you can select the object youwant,


View Full Document

Pitt CS 1699 - Intermediate Programming

Download Intermediate Programming
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Intermediate Programming and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Intermediate Programming 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?