cs106a – Assignment #7 – Task #5

The complete specification of assignment #7 can be found as part of the stream at iTunes.

Implement the FacePamphletCanvas class and complete the implementation of the FacePamphlet class

The class (which extends GCanvas) contains three public entries:

  • A constructor that has no parameters. You can use this to perform any initialization you may need for the canvas. Note: depending on how you implement the canvas, it is entirely possible that your constructor may not need to do anything. It’s perfectly fine if that’s the case.
  • Continue reading “cs106a – Assignment #7 – Task #5”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs106a – Assignment #7 – Task #4

The complete specification of assignment #7 can be found as part of the stream at iTunes.

Implement functionality for Change Status, Change Picture, and Add Friend buttons

The next step in the process is to complete more of the implementation of the FacePamphlet class, namely the functionality for the Change Status, Change Picture, and Add Friend buttons. The main issue to remember here is that these buttons effect the current profile, if there is one. As a result, one of the first things you should think about in implementing this milestone is how you will keep track of the current profile in the application. To help introduce the notion of the current profile, you might want to update the code for the Add, Delete, and Lookup button handlers so that:

  • Whenever a new profile is added, the current profile is set to be the newly added profile. If the user tried to add a profile with the name of an existing profile, then the existing profile with that name is set to be the current profile (this is similar to the case below where the users simply looks up an existing profile).
  • Continue reading “cs106a – Assignment #7 – Task #4”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs106a – Assignment #7 – Task #3

The complete specification of assignment #7 can be found as part of the stream at iTunes.

Implement the FacePamphletDatabase class

The FacePamphletDatabase class is used to keep track of all the profiles in the social network. The class which contains five public entries:

  • A constructor that has no parameters. You can use this to perform any initialization you may need for the database. Note: depending on how you implement the database, it is entirely possible that your constructor may not need to do anything. It’s perfectly fine if that’s the case.
  • An addProfile method that is passed a FacePamphletProfile, and is responsible for adding that profile to the database. Note that profile names are unique identifiers for profiles in the database. In other words, no two profiles in the database should have the same name and the name associated with a profile will never change. So, when a new profile is being added, if there is already an existing profile with the same name, the existing profile should be replaced by the new profile. Note: depending on what data structure you use to keep track of the database, this behavior may actually be quite easy to implement.
  • Continue reading “cs106a – Assignment #7 – Task #3”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs106a – Assignment #7 – Task #2

The complete specification of assignment #7 can be found as part of the stream at iTunes.

Implement the FacePamphletProfile class

The FacePamphletProfile class encapsulates the information pertaining to one profile in the social network. That information consists of four parts:

  1. The name of the person with this profile, such as “Mehran Sahami” or “Julie Zelenski”
  2. The status associated with this profile. This is just a String indicating what the person associated with the profile is currently doing. Until it is explicitly set, the status should initially be the empty string.
  3. The image associated with that profile. This is a GImage. Until it is explicitly set, this field should initially be null since we don’t initially have an image associated with a profile.
  4. The list of friends of this profile. The list of friends is simply a list of the names (i.e., list of Strings) that are friends with this profile. This list starts empty. The data structure you use to keep track of this list is left up to you.

The last method in the starter implementation of FacePamphletProfile is a toString method whose role is to return a human-readable representation of the data stored in the profile. The general form of the string returned by this method is: Continue reading “cs106a – Assignment #7 – Task #2”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs106a – Assignment #7 – Task #1

The complete specification of assignment #7 can be found as part of the stream at iTunes.

Assemble the GUI interactors

As seen in the initial start-up screen of the application (shown below), there are a number of interactors (JLabels, JTextFields, and JButtons) in both the NORTH and WEST border regions of the application.

cs106a – assignment #7 – task #1
Continue reading “cs106a – Assignment #7 – Task #1”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs106a – Lecture #25 to #28: Finally Java

The twenty-fifth lecture starts with a discussion of the next assignment as introduces concurrency in the theoretical part.

The twenty-sixth lecture discusses the differences between the ACM library set and “standard” java, end explains how to embed/compile java programs to run outside the development environment.

The twenty-seventh lecture explains which other classes are available at Stanford and what to expect.

The twenty-eight lecture is a wrap up and outlook for future classes.

Code for these lectures are available on github.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs106a – Assignment #6 – Extra Task #4

The complete specification of assignment #6 can be found as part of the stream at iTunes.

Adjust the font size as the application size changes

One of the wonderful features of this program is that it redraws itself to fill the available space if you change the size of the window. If you make it too small, however, the labels run together and become unreadable. You could eliminate this problem by choosing a font size that allows each label to fit in the space available.

Check if the label is wider than the column, if so adjust the font size:

	private void adjustSizeOfLabel(GLabel label) {
		double dx = getWidth() * 0.85 / NDECADES;
		double labelWidth = label.getWidth();
		if (labelWidth > dx) {
			Font font = label.getFont();
			label.setFont(font.deriveFont((float) (dx * font.getSize() / labelWidth)));
		}		
	}

	private void drawLabel(NameSurferEntry entry, int index, double x, double y) {
		...
		adjustSizeOfLabel(label);
		...
	}

	private void drawGrid() {
			...
			GLabel label = new GLabel(" " + year, x, yText);
			adjustSizeOfLabel(label);
			add(label);
			...
	}

The code for this assignment is available on github.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail