Commits

Steven! Ragnarök committed 352e866

Added many images, set page 1 and 2.

Comments (0)

Files changed (11)

+# CS151 Final Cheat Sheet #
+The three sheet (6-sides) 8 1/2 x 11 cheat sheet for the CS151 Final.

aggregate-legend.png

Added
New image

class-diagram.png

Added
New image

implement-legend.png

Added
New image

mvc-diagram.png

Added
New image
 ---
 layout: default
-title: index
+title: page1
 ---
+<img src=implement-legend.png />
+<img src=aggregate-legend.png />
+<img src=relation-legend.png />
+<img src=seq-diagram.png />
+<img src=state-diagram.png />
 
-This is a test to see just how much work I'm going to have to do.
-
-<div style="width:4in; float:left; padding:0.25in; border:1px black solid;">
+## Iterator Pattern ##
+<div style="width:4in; float:left;">
 {% highlight java %}
-  public static void main(String[] args)
-  {
-    
+  public Iterator<T> getIterator() {
+		return new Iterator<T> {
+    	public boolean hasNext() { return cur <items.size(); }
+			public T next() { return items.get(cur++); }
+			public void remove() {
+				throw new UnsupportedOperationException();
+			}
+		};
   }
 {% endhighlight %}
 </div>
+<br /><br /><br /><br /><br /><br /><br /><br /><br />
 
+## MVC Pattern ##
+<img src=mvc-diagram.png style="width:2in"/>
+
+---
+layout: default
+title: page2
+---
+
+## Fonts in awt ##
+<div class=left>
+{% highlight java %}
+public static void main(String[] args) {
+	FontFrame frame = new FontFrame();
+	frame.setDefaultCloseOperation(
+		JFrame.EXIT_ON_CLOSE);
+	frame.setVisible(true);
+}
+
+class FontFrame extends JFrame {
+	setTitle("Font Test");
+	setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
+	// Add panel to frame.
+	FontPanel panel = new FontPanel();
+	add(panel);
+
+	public static final int DEFAULT_HEIGHT = 200;
+	public static final int DEFAULT_WIDTH = 300;
+}
+
+class FontPanel extends JPanel {
+	public void paintComponent(Graphics g) {
+		super.paintComponent(Graphics g);
+		Graphics2D g2 = (Graphics2D) g;
+		Stromg message = "Hello World!";
+		Font f = new Font("Serif", Font.BOLD, 36);
+		g2.setFont(f);
+		FontRenderContext context = g2.getFontRenderContext();
+		Rectangle2D bounds = f.getStringBounds(message, context);
+		double x = (getWidth() - bounds.getWidth()) / 2;
+		double y = (getHeight() - bounds.getHeight()) / 2;
+		double ascentleading = -bounds.getY();
+		double baseY = y + ascentleading;
+		g2.drawString(message, (int) x, (int) baseY);
+		g2.setPaint(Color.GRAY);
+		g2.draw(new Line2D.Double(x, baseY, x + bounds.getWidth(). baseY));
+		g2.draw(new Rectange2D.Double(x, baseY, x + bounds.getWidth(),
+			bounds.getHeight()));
+	}
+}
+{% endhighlight %}
+</div>
+## Timers in awt ##
+<div class=left>
+{% highlight java %}
+public class TimerTester {
+	public static void main(String[] args) {
+		JFrame frame = new JFrame();
+		final int FIELD_WIDTH = 20;
+		final JTextField textField = new JTextField(FIELD_WIDTH);
+
+		frame.setLayout(new FlowLayout());
+		frame.add(textField);
+
+		ActionListener listener = new
+			ActionListener() {
+				public void actionPerformed(ActionEvent event) {
+					Date now = new Date();
+					textField.setText(now.toString());
+				}
+			};
+		final int DELAY = 1000;
+		Timer t = new Timer(Delay, listener);
+		t.start();
+
+		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+		frame.pack();
+		frame.setVisible(true);
+	}
+}
+{% endhighlight %}
+</div>
+## Comparator ##
+<div class=left>
+{% highlight java %}
+public class MaxTester {
+	public static int maximum(ArrayList<Integer> a,
+			Comparator<Integer> c) {
+		public int maxi
+		Collections.sort(a, c);
+		return a.get(a.size() - 1);
+	}
+	
+	public static void main(String[] args) {
+		ArrayList<Integer> ints = new ArrayList<Integer>();
+		ints.add(3); ints.add(50); ints.add(15); ints.add(20);
+		int result = maximum(ints, new Comparator<Integer>() {
+			public int compare(Integer i; Integer j)
+		{ return i - j; }});
+		System.out.println(result);
+	}
+}
+{% endhighlight %}
+</div>
+## Simple Animation ##
+<div class=left>
+{% highlight java %}
+public static void main(String[] args) {
+	JFrame frame = new JFrame();
+	int DEFAULT_WIDTH = 400;
+	int DEFAULT_HEIGHT = 400;
+	frame.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
+	int CAR_WIDTH = 100;
+	final MoveableShape shape = new CarShape(0, 0, CAR_WIDTH);
+	final JPanel panel = new MyPanel(shape);
+	frame.add(panel);
+
+	final int DELAY = 100;
+	Timer t = new Timer(DELAY, new ActionListener() {
+		public void actionPerformed(ActionEvent e) {
+			shape.translate(1,0);
+			panel.repaint();
+		}
+	});
+	t.start();
+
+	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+	frame.setVisible(true);
+}
+{% endhighlight %}
+</div>
+<div class=left>
+{% highlight java %}
+class Country implements Comparable<Country> {
+	private String name;
+	private double area;
+	public Country(String aName, double anArea){
+		name = aName;
+		area = anArea;
+	}
+	public String getName() {
+		return name;
+	}
+	public double getArea() {
+		return area;
+	}
+}
+
+public int compareTo(Country other) {
+	if (area < other.area) return -1;
+	if (area > other.area) return 1;
+	return 0;
+}
+
+public class CountrySortTester {
+	public static void main(String[] args) {
+		ArrayList<Country> countries = new ArrayList<Country>();
+		countries.add(new Country("Uruguay", 176220));
+		countries.add(new Country("Thailand", 514000));
+		countries.add(new Country("Belgium", 30510));
+		Collections.sort(countries);
+	}
+{% endhighlight %}
+</div>
+## Comparable ##

relation-legend.png

Added
New image

seq-diagram.png

Added
New image

state-diagram.png

Added
New image
 	font-size: 10px;
 	font-weight: thin;
 	background-color: #eee;
+	width:8.5in;
+	height: 11in;
 }
 
+img { float:left; padding:10px; width:4in; }
+
 code {
   font-family: Inconsolata, Courier, "Courier New", mono;
   font-size:10px;
 }
-
+img { padding:1px; border:1px solid black; }
+div { padding:1px; border:1px solid black; }
+.left { float:left; }
+.clear { clear:both; }