Alan Kaminsky
•
Department of Computer Science
•
Rochester Institute of Technology
•
4486
+
2220
= 6706
Home Page
Advanced Programming
•
4003-707-02
•
Fall Quarter 2008
Course Page
4003-707-02 Advanced Programming
Module 4. 2D Graphics; Collections -- Lecture Notes
Prof. Alan Kaminsky
Rochester Institute of Technology -- Department of Computer Science
Collection Classes
Package java.util
Collection
Interface java.util.Collection<E>
Generic type parameters
List
Interface java.util.List<E>
Class java.util.ArrayList<E>
Class java.util.LinkedList<E>
The reason for multiple implementations of an interface
Time complexity of list operations
Set
Interface java.util.Set<E>
Class java.util.HashSet<E>
Class java.util.TreeSet<E>
Time complexity of set operations
Usage of the set elements'
equals()
and
hashCode()
methods
Map
Interface java.util.Map<E>
Class java.util.HashMap<E>
Class java.util.TreeMap<E>
Time complexity of map operations
Usage of the map keys'
equals()
and
hashCode()
methods
Primitive types as elements of collections
Iterators
Interface java.util.Iterator<E>
Traversal
Traversing the contents of a collection with an iterator
Traversing the contents of a map with an iterator
Iteration order of the collection classes
Interface java.lang.Iterable<E> and the for-each loop
Traversal
Traversing the contents of a collection with a for-each loop
Traversing the contents of a map with a for-each loop
Exceptions
Checked exceptions
Class java.lang.Exception and subclasses
Methods that throw checked exceptions
You must do something about checked exceptions, or your program won't compile
Unchecked exceptions
Class java.lang.RuntimeException and subclasses
Java statements that throw unchecked exceptions
Methods that throw unchecked exceptions
You don't have to do anything about unchecked exceptions, and your program will still compile
What happens when an exception is thrown
Exception handlers
Finally clauses
Throwing an exception
2D Graphics
See the
Battlefield
case study for examples
Classes for displaying graphical output on the screen -- in package javax.swing in the Java platform
Class JFrame -- The window
Class JPanel -- A widget in a window that can display stuff
Classes for displaying graphical output on the screen -- in package edu.rit.swing in the
Computer Science Course Library
Class DisplayablePanel -- A JPanel in which you can draw stuff
Interface Displayable -- An object the DisplayablePanel uses to do the actual drawing
Classes for geometrical objects -- in package java.awt.geom in the Java platform
Class Rectangle2D.Double -- rectangles, squares
Class Ellipse.Double -- ellipses, circles
Class Line2D.Double -- lines
Many others
Class Graphics2D -- in package java.awt in the Java platform
A graphics context
Used to draw stuff "somewhere"
A Displayable object's
draw()
method has a Graphics2D argument for drawing stuff in the DisplayablePanel in the JFrame on the screen
Graphics2D methods for drawing stuff
setRenderingHint()
-- turn on antialiasing, and other things
setPaint()
-- set the paint color
fill()
-- fill a geometric object with the current paint color
setStroke()
-- set the pen shape (the "stroke")
draw()
-- trace the outline of a geometric object with the current pen shape and paint color
Many others
Graphics2D coordinate system
1 unit = 1 pixel
X axis increases left to right
Y axis increases top to bottom (the opposite of the mathematical convention)
translate()
,
rotate()
, others -- transform the coordinate system
Other classes -- in package java.awt in the Java platform
Class BasicStroke -- a pen shape
Class Color -- a color
Advanced Programming
•
4003-707-02
•
Fall Quarter 2008
Course Page
Alan Kaminsky
•
Department of Computer Science
•
Rochester Institute of Technology
•
4486
+
2220
= 6706
Home Page
Copyright © 2008 Alan Kaminsky. All rights reserved. Last updated 24-Sep-2008. Please send comments to ark
@
cs.rit.edu.