arahman22

GraphElement.java

Feb 21st, 2012
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Graphics2D;
  3.  
  4. // General element of a graph (nodes and edges)
  5.  
  6. abstract public class GraphElement
  7. {
  8.     // The variables
  9.      private double xPos;               // The x-position
  10.      private double yPos;
  11.      protected String label;
  12.      Color defaultColor = Color.BLACK;
  13.      
  14.      
  15.      protected final int Width = 100;
  16.      protected final int Height = 30;
  17.      
  18.      public GraphElement()
  19.      {
  20.         xPos = 0;
  21.         yPos = 0;
  22.      }
  23.        
  24.      public GraphElement(double x, double y)
  25.      {
  26.         xPos = x;
  27.         yPos = y;
  28.      }
  29.      
  30.      /**
  31.         Get the x-position of the update
  32.         @return The x-position of the element
  33.       */
  34.      public final double getXPos()
  35.      {
  36.         return xPos;
  37.      }
  38.      
  39.      /**
  40.         Get the y-position of the update
  41.         @return The y-position of the element
  42.       */
  43.      public final double getYPos()
  44.      {
  45.         return yPos;
  46.      }
  47.      
  48.      public void moveTo (double xLoc, double yLoc)
  49.      {
  50.         xPos = xLoc;
  51.         yPos = yLoc;
  52.         System.out.println("Did it move?");
  53.      }
  54.        
  55.      public String toString()
  56.      {
  57.         String str = "(X,Y) Position: (" + xPos + "," + yPos + ")\n";
  58.         return str;
  59.      }
  60.      
  61.      //Abstract classes to be added by the subclasses
  62.      abstract void    draw(Graphics2D g2); 
  63.      abstract void setSelected(double x, double y);
  64.      abstract boolean isSelected(double x, double y);;
  65.      abstract double getWidth();
  66.      abstract double getHeight();
  67.  
  68.      boolean applyLabel()
  69.      {
  70.         return true;
  71.      }
  72.  
  73.      public String getLabel()
  74.      {
  75.        return label;
  76.      }
  77.          
  78.      public void setLabel(String label)
  79.      {
  80.        this.label = label;
  81.      }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment