Title: Wednesday, June 07, 2001
1CM245 Lecture 1
CM245 - Contemporary Programming Methods Lecture 2
Wednesday, June 07, 2001 Cecil P.
Schmidt Department of Computer Information
Sciences Washburn University Topeka, KS.
66621 zzschmid_at_washburn.edu
2Presentation Outline
- Syllabus
- Introduction to Java
- Chapter 1 of Bell Parr
- How to compile a Java program at Washburn
- Punch and run assignment
3Applets vs. Applications (Review)
- Applets are invoked as part of a Web page
- Applets cannot run alone. The must run with the
aid of a browser. - Applications are free standing programs
- Applications require the main method
- example Hello.java
-
4How Do You Build a Java Program
- Text Editor with Java Development Kit (JDK)
- Integrated Development Environments (IDE)
- VisualAge Java
- Visual J
- JBuilder
- An IDE is great for large applications, screen
painting and debugging. Its best to learn
without one first. - We are not using an IDE for this class. We are
using the text editor option.
5Files and Directories
- Java source file ltfilename.javagt
- Java object file ltfilename.classgt
- Typical data file ltfilename.datagt
- Directory contains a set of (related) files
6Edit-Compile-Execute Process
- Edit build a .java file using either an IDE or
an editor - Compile converts .java to .class (byte code)
- Execute run the .class file with the JVM
7Creating and running an applet
- HelloApplet.java
- Using the appletviewer utility
- Moving the file to your web site after testing
-
8Chapter 3 - Introduction to graphics
- Drawing a line on a graphic object
- g.drawLine(0,0,100,100)
- g is a graphic object which is automatically
created for you because your program ISA applet
and all applets have access to a method call
paint and a graphics object! - drawLine is method that comes with a graphics
object - The graphics screen
- Java graphics based on pixels
- A pixel is a small dot on the screen which can
accessed. - Different screens have different pixel counts
- In HTML we can define the initial pixel width and
height - A pixel is identified by a pair of numbers
(coordinates) starting at zero - (x,y) x horizontal position (increases left to
right) - y vertical position (increases top to bottom)
9The FirstLine Program
- An explanation of the program
- g.drawline(0,0,100,100)
- g.drawline(xStart,yStart,xEnd,yEnd)
- where xStart, yStart, xEnd, yEnd are know as
parameters (arguments) in java, - g is the name of the object
- drawline is the method name (same as function)
- note the semicolons and not all methods require
arguments - The paint method
- This method must be written by the programmer in
support on an applet - For our purposes now, we will assume that this is
the first method that runs in our applet.
10Other methods used for drawing
- Lets find the Graphics object and see what it has
to offer! - The Graphics class is a member of the AWT
library. - void drawLine(int x1, int y1, int x2, int y2)
- Draws a line, using the current color, between
the points (x1, y1) and (x2, y2) in this graphics
context's coordinate system - void drawRect(int x, int y, int width, int
height) - Draws the outline of the specified rectangle.
- void fillOval(int x, int y, int width, int
height) - Fills an oval bounded by the specified rectangle
with the current color. - void drawArc(int x, int y, int width, int height,
int startAngle, int arcAngle) - Draws the outline of a circular or elliptical arc
covering the specified rectangle
11Filling shapes and setting colors
- setColor
- fillRect
- fillArc
- fillOval
- The FirstShapes.java program
- Displaying characters on a graphic
object g.drawString("Hello CM245 class",30,40) - Joining strings with
12 Exercises
- PunchRun 2 (Lab 2)
- Data Visualization Exercise
- See course web site for complete write-up