lab25
subdirectory of your personal repo, the other submits a file report.txt
in the lab25
subdirectory of your personal repo.ch08/graphed2
directory in the book code which you should have cloned some time ago. If you haven't recently updated your local copy, do that first.
cd path/to/bookCode git pull cp -R ch08/graphed2 ~/networkThen make an Eclipse project from existing sources with the files in
~/network
.SimpleGraph
and SimpleGraphEditor
to NetworkGraph
and NetworkGraphEditor
.setSize
method to CircleNode
. PersonNode
that extends CircleNode
. Supply a default constructor that sets the superclass color to white and the size to 40. Add a field imageURL
, and use Ctrl+Space to generate a getter and setter for it.NetworkGraph
, change the prototypes so you no longer have the circle nodes but instead have one PersonNode
.public class PersonNode { public void setImageURL() { ... try { icon = new ImageIcon(new URL(imageURL)); } catch (IOException ex) { } } private ImageIcon icon; }
paintIcon
method of the ImageIcon
. You'll need to find the bounds to put it in the right place. What did you do?PersonNode
isn't blank but uses a default icon such as this one: CircularNode
and the line attachments are at the circle boundary. Do this:
Shape oldClip = g2.getClip(); g2.setClip(new Ellipse2D.Double(...)); Paint g2.setClip(oldClip);
ImageIcon icon
field with a field Image image
. In setImageURL
, call
image = new ImageIcon(new URL(imageURL)).getImage();In the
draw
method, draw the image like this:
double width = image.getWidth(null); double height = image.getHeight(null); Rectangle2D bounds = getBounds(); double scale = Math.min(bounds.getWidth() / width, bounds.getHeight() / height); width = scale * width; height = scale * height; g2.drawImage(image, (int) (bounds.getX() + bounds.getWidth() - width), (int) (bounds.getY() + bounds.getHeight() - height), (int) width, (int) height, null);What does this code do?