Class Block

  • Direct Known Subclasses:
    Table

    public class Block
    extends java.lang.Object
    A block in the blocks-world.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.awt.Color color
      The color of the block.
      protected double dx
      The x translation for drawing (0-1).
      protected double dy
      The y translation for drawing (0-1).
      protected Block lower
      The block where this block is located on.
      protected int number
      The number of the block.
      SimplePropertyChangeSupport pcs
      The helper object for bean events.
      protected Block upper
      The block located on upper of this block.
    • Constructor Summary

      Constructors 
      Constructor Description
      Block​(int number, java.awt.Color color, Block lower)
      Create a new block.
      Block​(java.awt.Color color, Block lower)
      Create a new block.
    • Field Detail

      • number

        protected int number
        The number of the block.
      • color

        protected java.awt.Color color
        The color of the block.
      • lower

        protected Block lower
        The block where this block is located on.
      • upper

        protected Block upper
        The block located on upper of this block.
      • dx

        protected double dx
        The x translation for drawing (0-1).
      • dy

        protected double dy
        The y translation for drawing (0-1).
    • Constructor Detail

      • Block

        public Block​(java.awt.Color color,
                     Block lower)
        Create a new block.
        Parameters:
        color - The color of the block.
        lower - The block where this block is located on.
      • Block

        public Block​(int number,
                     java.awt.Color color,
                     Block lower)
        Create a new block.
        Parameters:
        number - The number of the block.
        color - The color of the block.
        lower - The block where this block is located on.
    • Method Detail

      • getNumber

        protected static int getNumber()
        Get an instance number.
      • getColor

        public java.awt.Color getColor()
        Get the color of the block.
        Returns:
        The color of the block.
      • getLower

        public Block getLower()
        Get the block where this block is located on.
        Returns:
        The block where this block is located on.
      • isClear

        public boolean isClear()
        Check if this block is clear.
      • stackOn

        public void stackOn​(Block lower)
        Move this block on top of another block.
      • setLower

        protected void setLower​(Block lower)
        Set the lower block, where this block is located on.
        Parameters:
        lower - The lower block.
      • addBlock

        protected void addBlock​(Block block)
        Add a block to this block.
      • removeBlock

        protected void removeBlock​(Block block)
        Remove a block from this block.
      • toString

        public java.lang.String toString()
        Create a string representation of this block.
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Check for equality.
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Calculate the hash code.
        Overrides:
        hashCode in class java.lang.Object
      • addPropertyChangeListener

        public void addPropertyChangeListener​(PropertyChangeListener listener)
        Add a PropertyChangeListener to the listener list. The listener is registered for all properties.
        Parameters:
        listener - The PropertyChangeListener to be added.
      • removePropertyChangeListener

        public void removePropertyChangeListener​(PropertyChangeListener listener)
        Remove a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.
        Parameters:
        listener - The PropertyChangeListener to be removed.