Informatics 45 Spring 2010
Code Examples


Code examples, from lecture and otherwise

Over the course of the quarter, as we work on code in lecture, I'll be providing commented code examples for you. These examples are mostly to give you clean and well-documented examples of some of the things we cover in lecture (and possibly a few things that we don't, time permitting), so that you can be free in lecture to avoid trying to take detailed notes when we're writing code together, instead concentrating on understanding the process and the bigger-picture concepts at work when we develop the examples.

Lecture Date(s) Description
Th 4/1 Our example of GUI layout and event handling in Swing
Tu 4/6
Th 4/8
The second GUI example, including JPanels and nested layout, model/view separation, and custom events — five progressively improved versions
Th 4/8
Tu 4/13
The "names list" example of GridBagLayout, JLists, ListModels, along with some extensions we didn't implement in lecture
Th 4/15 A simple chat server and client using sockets
Tu 4/20 Improving our chat server and client using protocol separation
Th 4/22 Mixing sockets with GUIs, including the use of threads to keep the GUI responsive
Tu 4/27 Reading the bytes in a file into a byte array
Tu 4/27 Sending bytes through a socket (which is surprisingly similar to reading them from the file)
Th 4/29 Downloading a web page via a Java program
Th 4/29 Using the Twitter API to post Twitter updates from a Java program
Tu 5/4 Fetching a Twitter timeline using the Twitter API, including parsing its XML response
Th 5/6 Issuing a Google query from a Java program, including using open source software to parse the JSON response
Tu 5/11
Th 5/13
Tu 5/18
The complete Othello game (more or less) that we built in lecture
Th 5/20
Tu 5/25
Our first animation, a ball bouncing around an empty area
Tu 5/25
Th 5/27
Adding a paddle and turning our animation into a simple game, including sound


How to use these examples in Eclipse

Here's what you'll want to do in order to pull each example into Eclipse.

After taking these steps, the example should be available in Eclipse!

Note that Eclipse will collapse a large comment that I've written at the top of each .java file, so that you can only see the first line of it. You'll want to be sure to expand these comments (by clicking the little + next to them) and read them, because that's where a lot of the useful information is.