package Nodepad; import java.awt.*; import java.awt.event.*; import javax.swing.*; /** * Node.java * * * Created: Mon Dec 30 13:56:15 2002 * * @author Stuart C. Shapiro * @version * * A bordered, integer-valued node that can be moved around a sketch Pad. */ public class Node extends ParentNode { /** * Creates a bordered Node, with a given Pad, location, and value. * * @param p the Pad this node is on. * @param x the x value of this node's initial location. * @param y the y value of this node's initial location. * @param v the integer value of this node. */ public Node (Pad p, int x, int y, int v){ super(p, x, y, v); this.setBorder(BorderFactory.createLineBorder(Color.black,1)); } /** * Paints this node as a rectangle with its value centered inside. * * @param g the Graphics component of this node. */ public void paintComponent(Graphics g) { setSize(size); setLocation(locpt); g.setColor(Color.black); //Draw the label, centered, twice the size of the standard font. {Font currFont = g.getFont(); g.setFont(currFont.deriveFont(2*currFont.getSize2D()));} g.drawString(label, (size.width - g.getFontMetrics().stringWidth(label))/2, 30); } /** * Terminates cursor following. */ public void mouseReleased (MouseEvent evt){ shouldmove = false; if (this.getBounds().contains(evt.getX(), evt.getY()) && !pad.getMovingNodes()) { value = pad.getAcc(); label = "" + value; repaint(); } } }// Node