Dijkstra's Shortest Path Algorithm in java

profileDamansandhu
Project.zip

Project/DijkstraSearch.java

Project/DijkstraSearch.java

/*
 */

import  java . io . * ;
import  java . awt . * ;
import  javax . swing . * ;
import  trubgp . * ;    // TRU Board Games Playground package


public   class   DijkstraSearch
{
   static   Board  board ;    // Game board
  
   public   static   void  main ( String []  args )
   {
     // Creat a game board
    create ();
   }
  
  
   // Create a new board
  
   static   void  create ()
   {
   }
}

Project/Graph.java

Project/Graph.java

public   class   Graph
{
   private   VertexString  vertices [];    // 
   private   double  adjacencies [][];    // adjacent matrix
   private   int  numVertices ;    // number of vertices
  
   public   Graph ( int  numVertices )
   {
    vertices  =   new   VertexString [ numVertices ];
     for   ( int  i  =   0 ;  i  <  numVertices ;  i ++ )  
      vertices [ i ]   =   null ;
    
    adjacencies  =   new   double [ numVertices ][];
     for   ( int  i  =   0 ;  i  <  numVertices ;  i ++ )   {
      adjacencies [ i ]   =   new   double [ numVertices ];
       for   ( int  j  =   0 ;  j  <  numVertices ;  j ++ )
        adjacencies [ i ][ j ]   =   - 1 ;
     }
    
     this . numVertices  =  numVertices ;
   }
  
   public   void  keepVertex ( int  id ,   VertexString  vertex )
   {
    vertices [ id ]   =  vertex ;
   }
  
   public   void  setNeighbors ( int  idFrom ,   int  idTo ,   double  cost )
   {
    adjacencies [ idFrom ][ idTo ]   =  cost ;
   }
    
   public   void  reset ()
   {
     for   ( int  i  =   0 ;  i  <  numVertices ;  i ++ )   {
      vertices [ i ]. reset ();
     }
   }
  
   public   boolean []  getNeighbors ( int  id )
   {
     boolean  neighbors []   =   new   boolean [ numVertices ];
    
     for   ( int  i  =   0 ;  i  <  numVertices ;  i ++ )
       if   ( adjacencies [ id ][ i ]   <   0 )
        neighbors [ i ]   =   false ;
       else
        neighbors [ i ]   =   true ;
      
     return  neighbors ;
   }
  
   public   double  cost ( int  idFrom ,   int  idTo )
   {
     return  adjacencies [ idFrom ][ idTo ];
   }
  
   public   boolean  isEmpty ()
   {
     return  vertices [ 0 ]   ==   null ;
   }
  
   public   int  size ()
   {
     return  numVertices ;
   }
  
   public   VertexString  find ( int  id )
   {
     if   ( id  <   0 )
       return   null ;
     else
       return  vertices [ id ];
   }
  
   public   VertexString  find ( String  content )
   {
     for   ( int  i  =   0 ;  i  <  numVertices ;  i ++ )
       if   ( vertices [ i ]. getContent (). equals ( content ))
         return  vertices [ i ];
    
     return   null ;
   }
}

Project/graph.txt

// number of nodes 8 // node id and its content (strings) 0 A 1 B 2 C 3 D 4 E 5 F 6 G 7 H // Adjacency matrix -1 3 4 -1 15 -1 -1 -1 3 -1 -1 7 6 -1 -1 -1 4 -1 -1 8 -1 4 -1 -1 -1 7 8 -1 -1 -1 4 5 15 6 -1 -1 -1 3 7 -1 -1 -1 4 -1 3 -1 -1 7 -1 -1 -1 4 7 -1 -1 3 -1 -1 -1 5 -1 7 3 -1

Project/LinkedListADT.java

Project/LinkedListADT.java

/*
 * Doubly linked list
 */

public   class   LinkedListADT < T >
{
   private   NodeADT < T >  head ,  tail ;
   private   int  count ;
   private   NodeADT < T >  nextNode ;    // For operating as Iterator

   public   LinkedListADT ()
   {
    head  =   null ;
    tail  =   null ;
    count  =   0 ;
    nextNode  =   null ;
   }
  
   public   void  addToFirst ( T element )
   {
     NodeADT < T >  node  =   new   NodeADT < T > ( element );
    
     if   ( count  ==   0 )   {
      head  =  tail  =  node ;
     }
     else   {
      node . setNext ( head );
      head . setPrev ( node );
      head  =  node ;
     }
    count ++ ;
   }
  
   public   void  addToLast ( T element )
   {
     NodeADT < T >  node  =   new   NodeADT < T > ( element );
    
     if   ( count  ==   0 )   {
      head  =  tail  =  node ;
     }
     else   {
      node . setPrev ( tail );
      tail . setNext ( node );
      tail  =  node ;
     }
    count ++ ;
   }
  
   public  T removeFirst ()
   {
     if   ( count  ==   0 )
       return   null ;
     else   {
      T element  =  head . getElement ();
      head  =  head . getNext ();
       if   ( head  ==   null )
        tail  =   null ;
       else
        head . setPrev ( null );
      count -- ;
       return  element ;
     }
   }
  
   public  T removeLast ()
   {
     if   ( count  ==   0 )
       return   null ;
     else   {
      T element  =  tail . getElement ();
      tail  =  tail . getPrev ();
       if   ( tail  ==   null )
        head  =   null ;
       else
        tail . setNext ( null );
      count -- ;
       return  element ;
     }
   }
  
   public  T first ()
   {
     if   ( head  ==   null )
       return   null ;
     else
       return  head . getElement ();
   }
  
   public  T last ()
   {
     if   ( tail  ==   null )
       return   null ;
     else
       return  tail . getElement ();
   }
  
   public   boolean  isEmpty ()
   {
     return  count  ==   0 ;
   }
  
   public   int  size ()
   {
     return  count ;
   }
  
   public   NodeADT < T >  head ()
   {
     return  head ;
   }
  
   // Need to be careful when this method is used
   public   void  resize ( int  newSize )
   {
    count  =  newSize ;
   }
  
  
   /*
   * The next three methods:
   *   For operating as Iterator
   */
  
   public   void  rewind ()
   {
    nextNode  =  head ;
   }
  
   public   boolean  hasNext ()
   {
     return  nextNode  !=   null ;
   }
  
   public  T next ()
   {
     if   ( nextNode  ==   null )
       return   null ;
    
    T element  =  nextNode . getElement ();
    nextNode  =  nextNode . getNext ();

     return  element ;
   }
  
   public   void  remove ()
   {
     NodeADT < T >  prevNode ;
    
     // get the previous node
    
     // if there is nothing
     if   ( nextNode  ==   null )   {
       if   ( tail  ==   null )
         return ;
       // next is after tail
       else  
        prevNode  =  tail ;
     }
     // next is in the linked list
     else  
      prevNode  =  nextNode . getPrev ();
    
     // remove prevNode.
    
     if   ( prevNode  ==   null )
       ;
     else   if   ( prevNode  ==  head )
      removeFirst ();
     else   if   ( prevNode  ==  tail )
      removeLast ();
     else   {
      prevNode . getPrev (). setNext ( prevNode . getNext ());
      prevNode . getNext (). setPrev ( prevNode . getPrev ());
      count -- ;
     }
   }
}

Project/NodeADT.java

Project/NodeADT.java

// Node for double linked list

public   class   NodeADT < T >
{
   private   NodeADT < T >  prev ;
   private   NodeADT < T >  next ;
   private  T element ;
  
   public   NodeADT ()
   {
    prev  =   null ;
    next  =   null ;
    element  =   null ;
   }

   public   NodeADT ( T e )
   {
    prev  =   null ;
    next  =   null ;
    element  =  e ;
   }
  
   public   NodeADT < T >  getNext ()
   {
     return  next ;
   }
  
   public   void  setNext ( NodeADT < T >  n )
   {
    next  =  n ;
   }
  
   public   NodeADT < T >  getPrev ()
   {
     return  prev ;
   }
  
   public   void  setPrev ( NodeADT < T >  p )
   {
    prev  =  p ;
   }
  
   public  T getElement ()
   {
     return  element ;
   }
  
   public   void  setElement ( T e )
   {
    element  =  e ;
   }
}

Project/NodeBinaryTree.java

Project/NodeBinaryTree.java

public   class   NodeBinaryTree < T >
{
   private   int  id ;
   private  T content ;
   private   NodeBinaryTree < T >  parent ,  left ,  right ;
  
   public   NodeBinaryTree ()  
   {
     this . id  =   - 1 ;
     this . content  =   null ;
    parent  =   null ;
    left  =   null ;
    right  =   null ;
   }
  
   public   NodeBinaryTree ( T content )  
   {
     this . id  =   - 1 ;
     this . content  =  content ;
    parent  =   null ;
    left  =   null ;
    right  =   null ;
   }
  
   public   NodeBinaryTree ( int  id ,  T content )  
   {
     this . id  =  id ;
     this . content  =  content ;
    parent  =   null ;
    left  =   null ;
    right  =   null ;
   }
  
   public   int  getId ()
   {
     return  id ;
   }
  
   public  T getContent ()
   {
     return  content ;
   }
  
   public   NodeBinaryTree < T >  getParent ()
   {
     return  parent ;
   }
  
   public   void  setParent ( NodeBinaryTree < T >  parent )
   {
     this . parent  =  parent ;
   }
  
   public   NodeBinaryTree < T >  getLeft ()
   {
     return  left ;
   }
  
   public   void  setLeft ( NodeBinaryTree < T >  left )
   {
     this . left  =  left ;
   }
  
   public   NodeBinaryTree < T >  getRight ()
   {
     return  right ;
   }
  
   public   void  setRight ( NodeBinaryTree < T >  right )
   {
     this . right  =  right ;
   }
}

Project/NodePriorityQueue.java

Project/NodePriorityQueue.java

/*
 * Min priority queue node
 */

//public class NodePriorityQueue<T> extends NodeBinaryTree<T> implements Comparable<NodePriorityQueue<T>>
public   class   NodePriorityQueue < T >   extends   NodeBinaryTree < T >
{
   private   double  priority ;    // The smaller, the higher
  
   public   NodePriorityQueue ( T content )
   {
     super ( content );
   }
  
   public   void  setPriority ( double  p )
   {
    priority  =  p ;
   }
  
   public   double  getPriority ()
   {
     return  priority ;
   }
}

Project/NodePriorityQueueVertex.java

Project/NodePriorityQueueVertex.java

/*
 * Min priority queue node
 */

public   class   NodePriorityQueueVertex   extends   NodePriorityQueue < VertexString >
{
   public   NodePriorityQueueVertex ( VertexString  content )
   {
     super ( content );
   }
}

Project/PriorityQueue.java

Project/PriorityQueue.java

/*
 * The smaller priority, the higher
 */

//public class PriorityQueue<T> implements HeapADT<T>
public   class   PriorityQueue < T >
{
   private   NodePriorityQueue < T >  root ;
   int  numNodes ;

   public   PriorityQueue ()  
   {
    root  =   null ;
    numNodes  =   0 ;
   }
  
   public   void  addElement ( T element )
   {
    addElement ( 0 ,  element );
   }
  
   public   void  addElement ( double  priority ,  T element )
   {
     // When thre is no node
    
     if   ( numNodes  ==   0 )   {
      root  =   new   NodePriorityQueue < T > ( element );
      root . setPriority ( priority );
      numNodes ++ ;
       return ;
     }
    
     // Find the place where the new node goes to
     //   Actually the parent node
    
     NodePriorityQueue < T >  parent ;
     int  position  =  numNodes ;
     String  s  =  position  +   "" ;
    
     while   ( position  >   0 )   {
       if   ( position  %   2   ==   1 )
        position  =  position  /   2 ;
       else
        position  =  position  /   2   -   1 ;
      s  =  position  +   ","   +  s ;
     }
     String  positions []   =  s . split ( "," );
    
    parent  =  root ;    // position == 0
     for   ( int  i  =   1 ;  i  <  positions . length  -   1 ;  i ++ )   {    // except the new position
       if   ( Integer . parseInt ( positions [ i ])   %   2   ==   1 )
        parent  =   ( NodePriorityQueue < T > )( parent . getLeft ());
       else
        parent  =   ( NodePriorityQueue < T > )( parent . getRight ());
     }
    
     // Create the new node
     // Attach the new node to its parent
    
     NodePriorityQueue < T >  nodeNew  =   new   NodePriorityQueue < T > ( element );
    nodeNew . setPriority ( priority );
     if   ( numNodes  %   2   ==   1 )   {
      parent . setLeft ( nodeNew );
      nodeNew . setParent ( parent );
     }
     else   {
      parent . setRight ( nodeNew );
      nodeNew . setParent ( parent );
     }
    numNodes ++ ;
    
     // Adjust the heap
    
     NodePriorityQueue < T >  node  =  nodeNew ;
     while   ( node  !=  root )   {
       if   ( node . getPriority ()   <   (( NodePriorityQueue < T > )( node . getParent ())). getPriority ())
        swapChildParent ( node ,   ( NodePriorityQueue < T > )( node . getParent ()));
       else
         break ;
     }
   }
  
   // New for Dijkstra
  
   public   void  addElement ( NodePriorityQueue < T >  nodeNew )
   {
   }
  
   private   void  swapChildParent ( NodePriorityQueue < T >  node ,   NodePriorityQueue < T >  parent )
   {
     NodePriorityQueue < T >  grandParent ,  tmpGrandParentLeft ;
     NodePriorityQueue < T >  tmpParent ,  tmpParentLeft ,  tmpParentRight ;
     NodePriorityQueue < T >  tmpNodeLeft ,  tmpNodeRight ;
    
     // Save the necessary pointers
    
    grandParent  =   ( NodePriorityQueue < T > )( parent . getParent ());
     if   ( grandParent  !=   null )   {
      tmpGrandParentLeft  =   ( NodePriorityQueue < T > )( grandParent . getLeft ());
     }
     else   {
      tmpGrandParentLeft  =   null ;
     }
    tmpParent  =  parent ;
    tmpParentLeft  =   ( NodePriorityQueue < T > )( parent . getLeft ());
    tmpParentRight  =   ( NodePriorityQueue < T > )( parent . getRight ());
    tmpNodeLeft  =   ( NodePriorityQueue < T > )( node . getLeft ());
    tmpNodeRight  =   ( NodePriorityQueue < T > )( node . getRight ());

     // For node's child nodes
    
     if   ( tmpNodeLeft  !=   null )  tmpNodeLeft . setParent ( parent );
     if   ( tmpNodeRight  !=   null )  tmpNodeRight . setParent ( parent );
    
     // For parent that is swaped with node
    
    parent . setLeft ( tmpNodeLeft );
    parent . setRight ( tmpNodeRight );
    parent . setParent ( node );

     // For node that becomes parent
    
     if   ( tmpParentLeft  ==  node )   {    // node is the left child
      node . setLeft ( parent );
      node . setRight ( tmpParentRight );
      node . setParent ( null );
       if   ( tmpParentRight  !=   null )
        tmpParentRight . setParent ( node );
     }
     else   {    // node is the right child
      node . setLeft ( tmpParentLeft );
      node . setRight ( parent );
      node . setParent ( null );
       if   ( tmpParentLeft  !=   null )
        tmpParentLeft . setParent ( node );
     }

     // For grand parent
    
     if   ( grandParent  ==   null )   {    // then parent is the root.
      root  =  node ;
     }
     else   {
      node . setParent ( grandParent );
       if   ( tmpGrandParentLeft  ==  tmpParent )   {    // parent is the left child
        grandParent . setLeft ( node );
       }
       else   {
        grandParent . setRight ( node );
       }
     }
   }
  
   public  T removeMin ()
   {
     // If there is nothing, then return
     if   ( numNodes  ==   0 )
       return   null ;
    
     // If there is only one, then remove the root and return its content
     if   ( numNodes  ==   1 )   {
       NodePriorityQueue < T >  tmpRoot  =  root ;
      root  =   null ;
      numNodes  =   0 ;
       return  tmpRoot . getContent ();
     }
    
     // Find the last node
    
     NodePriorityQueue < T >  node ;
     int  position  =  numNodes - 1 ;
     String  s  =  position  +   "" ;
    
     while   ( position  >   0 )   {
       if   ( position  %   2   ==   1 )
        position  =  position  /   2 ;
       else
        position  =  position  /   2   -   1 ;
      s  =  position  +   ","   +  s ;
     }
     String  positions []   =  s . split ( "," );
    
    node  =  root ;    // position == 0
     for   ( int  i  =   1 ;  i  <  positions . length ;  i ++ )   {  
       if   ( Integer . parseInt ( positions [ i ])   %   2   ==   1 )
        node  =   ( NodePriorityQueue < T > )( node . getLeft ());
       else
        node  =   ( NodePriorityQueue < T > )( node . getRight ());
     }
    
     // Cut off the last node
    
     if   ( node . getParent (). getLeft ()   ==  node )
      node . getParent (). setLeft ( null );
     else
      node . getParent (). setRight ( null );
    
    numNodes -- ;
    
     // Keep the root node
     NodePriorityQueue < T >  tmpRoot  =  root ;
    
     // Make the last node as the root
    
    root  =  node ;
    root . setParent ( null );
    root . setLeft ( tmpRoot . getLeft ());
    root . setRight ( tmpRoot . getRight ());
    
     if   ( tmpRoot . getLeft ()   !=   null )
      tmpRoot . getLeft (). setParent ( root );
     if   ( tmpRoot . getRight ()   !=   null )
      tmpRoot . getRight (). setParent ( root );
    
     // Adjust the heap
    
    node  =  root ;
     while ( true )   {
       if   ( node . getLeft ()   ==   null   &&  node . getRight ()   ==   null )
         break ;
       else   if   ( node . getLeft ()   !=   null   &&  node . getRight ()   ==   null )   {
         if   ( node . getPriority ()   >   (( NodePriorityQueue < T > ) node . getLeft ()). getPriority ())
          swapChildParent (( NodePriorityQueue < T > ) node . getLeft (),  node );
         else
           break ;
       }
       else   if   ( node . getLeft ()   ==   null   &&  node . getRight ()   !=   null )   {
         if   ( node . getPriority ()   >   (( NodePriorityQueue < T > ) node . getRight ()). getPriority ())
          swapChildParent (( NodePriorityQueue < T > ) node . getRight (),  node );
         else
           break ;
       }
       else   {
         if   ((( NodePriorityQueue < T > ) node . getLeft ()). getPriority ()   <=   (( NodePriorityQueue < T > ) node . getRight ()). getPriority ())   {  
           if   ( node . getPriority ()   >   (( NodePriorityQueue < T > ) node . getLeft ()). getPriority ())
            swapChildParent (( NodePriorityQueue < T > ) node . getLeft (),  node );
           else
             break ;
         }
         else   if   ((( NodePriorityQueue < T > ) node . getLeft ()). getPriority ()   >   (( NodePriorityQueue < T > ) node . getRight ()). getPriority ())   {
           if   ( node . getPriority ()   >   (( NodePriorityQueue < T > ) node . getRight ()). getPriority ())
            swapChildParent (( NodePriorityQueue < T > ) node . getRight (),  node );
           else
             break ;
         }
         else
           break ;
       }
     }

     // Return the content of the root
     return  tmpRoot . getContent ();
   }
  
   public  T findMin ()
   {
     if   ( numNodes  ==   0 )
       return   null ;
     else
       return  getRoot (). getContent ();
   }
  
   // New for Dijkstra
  
   public   void  update ( NodePriorityQueue < T >  node )
   {
   }
  
   public   NodePriorityQueue < T >  getRoot ()
   {
     return  root ;
   }
  
   public   boolean  isEmpty ()
   {
     return  numNodes  ==   0 ;
   }
  
   public   int  size ()
   {
     return  numNodes ;
   }
}

Project/QueueListADT.java

Project/QueueListADT.java

/*
 * Queue using a doubly linked list
 */

public   class   QueueListADT < T >
{
   private   LinkedListADT < T >  linkedList ;

   public   QueueListADT ()
   {
     this . linkedList  =   new   LinkedListADT < T > ();
   }
  
   public   void  enqueue ( T element )
   {
     this . linkedList . addToLast ( element );
   }

   public  T dequeue ()
   {
     return   this . linkedList . removeFirst ();
   }

   public  T first ()
   {
     return   this . linkedList . first ();
   }

   public   boolean  isEmpty ()
   {
     return   this . linkedList . isEmpty ();
   }
  
   public   int  size ()
   {
     return   this . linkedList . size ();
   }
  
   public   NodeADT < T >  head ()
   {
     return  linkedList . head ();
   }
}

Project/StackListADT.java

Project/StackListADT.java

/*
 * Stack using doubly linked list
 */

public   class   StackListADT < T >
{
   private   LinkedListADT < T >  linkedList ;
  
   public   StackListADT ()
   {
     this . linkedList  =   new   LinkedListADT < T > ();
   }
  
   public   void  push ( T element )
   {
     this . linkedList . addToLast ( element );
   }

   public  T pop ()
   {
    T element  =   this . linkedList . removeLast ();
     return  element ;
   }
  
   public  T peek ()
   {
     return   this . linkedList . last ();
   }
  
   public   boolean  isEmpty ()
   {
     return   this . linkedList . isEmpty ();
   }
  
   public   int  size ()
   {
     return   this . linkedList . size ();
   }
  
   public   NodeADT < T >  head ()
   {
     return  linkedList . head ();
   }
}

Project/StackVertex.java

Project/StackVertex.java

/*
 * Queue using a linked list
 */

public   class   StackVertex   extends   StackListADT < VertexString >
{
}

Project/trubgp/BGPEventListener (1).java

Project/trubgp/BGPEventListener (1).java

package  trubgp ;

public   interface   BGPEventListener
{
   //public void clicked(Cell cell, int row, int col);
   public   void  clicked ( int  row ,   int  col );
}

Project/trubgp/BGPEventListener.class

package trubgp;
public abstract interface BGPEventListener {
    public abstract void clicked(int, int);
}

Project/trubgp/BGPEventListener.java

Project/trubgp/BGPEventListener.java

package  trubgp ;

public   interface   BGPEventListener
{
   //public void clicked(Cell cell, int row, int col);
   public   void  clicked ( int  row ,   int  col );
}

Project/trubgp/Board (1).java

Project/trubgp/Board (1).java

package  trubgp ;

import  java . awt . * ;
import  java . awt . event . * ;
import  javax . swing . * ;

public   class   Board
{
   private   int  N ,  M ,  CELL_HEIGHT ,  CELL_WIDTH ;
   private   Color  boardCellColor ;
   public   Cell  cells [][];
   private   JPanel  panelBoard ,  panelInput ,  panelOutput ;
   private   JFrame  frame ;
   private   JTextField  textField ;
   private   JButton  button1  =   null ,  button2  =   null ;
   private   BGPEventListener  button1Listener ,  button2Listener ;
   private   JTextArea  textArea ;
    
   public   Board ( int  rows ,   int  columns ,   int  width ,   int  height ,   String  style ,   Color  color )
   {
    create ( rows ,  columns ,  width ,  height ,  style ,  color );
   }

   public   Board ( int  rows ,   int  columns ,   int  width ,   int  height )
   {
    create ( rows ,  columns ,  width ,  height ,   "Line" ,   Color . WHITE );
   }
  
   private   void  create ( int  rows ,   int  columns ,   int  width ,   int  height ,   String  style ,   Color  color )
   {
    N  =  rows ;
    M  =  columns ;
    CELL_HEIGHT  =  height  /  rows ;
    CELL_WIDTH  =  width  /  columns ;
    
    boardCellColor  =  color ;
    
    panelBoard  =   new   JPanel ();
    panelBoard . setPreferredSize ( new   Dimension ( width ,  height ));
    panelBoard . setLayout ( new   GridLayout ( N ,  M ));
    panelBoard . setBorder ( BorderFactory . createCompoundBorder (
                             BorderFactory . createLineBorder ( Color . BLACK ,   1 ),  
                             BorderFactory . createLineBorder ( Color . WHITE ,   0 )));    // 0 -> padding 0
    
    textField  =   new   JTextField ( 20 );
    button1  =   new   JButton ( "Button1" );
    button1 . addActionListener ( new   ActionListener ()   {
      @ Override
       public   void  actionPerformed ( ActionEvent  event )
       {
         if   ( button1Listener  !=   null )
          button1Listener . clicked ( - 1 ,   - 1 );
       }
     });
    button2  =   new   JButton ( "Button2" );
    button2 . addActionListener ( new   ActionListener ()   {
      @ Override
       public   void  actionPerformed ( ActionEvent  event )
       {
         if   ( button2Listener  !=   null )
          button2Listener . clicked ( - 1 ,   - 1 );
       }
     });

    panelInput  =   new   JPanel ( new   FlowLayout ( FlowLayout . LEFT ));
    panelInput . setPreferredSize ( new   Dimension ( width ,   60 ));
    panelInput . setBorder ( BorderFactory . createCompoundBorder (
                             BorderFactory . createLineBorder ( Color . BLACK ,   0 ),  
                             BorderFactory . createLineBorder ( Color . WHITE ,   10 )));    // 0 -> padding 0
    panelInput . add ( textField );
    panelInput . add ( button1 );
    panelInput . add ( button2 );
                   
    panelOutput  =   new   JPanel ( new   FlowLayout ( FlowLayout . LEFT ));
    panelOutput . setPreferredSize ( new   Dimension ( width ,   110 ));
    panelOutput . setBorder ( BorderFactory . createCompoundBorder (
                             BorderFactory . createLineBorder ( Color . BLACK ,   0 ),  
                             BorderFactory . createLineBorder ( Color . WHITE ,   10 )));    // 0 -> padding 0
    textArea  =   new   JTextArea ( 5 ,   40 );
    textArea . setEditable ( false );
    panelOutput . add ( textArea );

   
    cells  =   new   Cell [ N ][];
     for   ( int  r  =   0 ;  r  <  N ;  r ++ )   {
      cells [ r ]   =   new   Cell [ M ];
       for   ( int  c  =   0 ;  c  <  M ;  c ++ )   {
        cells [ r ][ c ]   =   new   Cell ( panelBoard ,  r ,  c ,  CELL_WIDTH ,  CELL_HEIGHT ,   "" ,   0 );
        cells [ r ][ c ]. cellBackgroundColor ( boardCellColor );
         if   ( style . equals ( "NoLine" )   ||  style . equals ( "NO_LINE" ))
          cells [ r ][ c ]. setBorderWidth ( 0 );
       }
     }
    
    frame  =   new   JFrame ( "TRU Board Games Playground" );
    frame . setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE );
     //frame.setLayout(new GridLayout(3, 1));
    frame . getContentPane (). add ( panelBoard ,   BorderLayout . NORTH );
    frame . getContentPane (). add ( panelInput ,   BorderLayout . CENTER );
    frame . getContentPane (). add ( panelOutput ,   BorderLayout . SOUTH );
    frame . pack ();
    frame . setVisible ( true );
   }
  
   public   void  dispose ()
   {
    frame . dispose ();
   }

   public   void  setTitle ( String  title )
   {
    frame . setTitle ( title );
   }
  
   public   void  refresh ()
   {
    panelBoard . removeAll ();
    
     for   ( int  r  =   0 ;  r  <  N ;  r ++ )
       for   ( int  c  =   0 ;  c  <  M ;  c ++ )   {
        panelBoard . add ( cells [ r ][ c ]. getButton ());
         //cells[r][c].getButton().revalidate();
       }
    
     //panelBoard.invalidate();  // It does not work.
    panelBoard . revalidate ();    // It does work.
    panelBoard . repaint ();

     // Let's give Java Event Manager some time so that all the changes in BGP can be properly rendered.
    sleep ( 5 );
   }

   public   void  cellsClickEventListener ( BGPEventListener  listener )
   {
     for   ( int  r  =   0 ;  r  <  N ;  r ++ )
       for   ( int  c  =   0 ;  c  <  M ;  c ++ )
        cells [ r ][ c ]. clickEventListener ( listener );
   }
  
   public   Color  cellBackgroundColor ( int  row ,   int  col )
   {
     return  cells [ row ][ col ]. cellBackgroundColor ();
   }

   public   void  cellBackgroundColor ( int  row ,   int  col ,   Color  color )
   {
    cells [ row ][ col ]. cellBackgroundColor ( color );
   }

   public   String  cellContent ( int  row ,   int  col )
   {
     return  cells [ row ][ col ]. cellContent ();
   }

   public   void  cellContent ( int  row ,   int  col ,   String  content )
   {
    cells [ row ][ col ]. cellContent ( content );
   }

   public   void  cellContent ( int  row ,   int  col ,   String  content ,   float  fontSize )
   {
    cells [ row ][ col ]. cellContent ( content ,  fontSize );
   }
  
   public   void  switchCells ( int  row0 ,   int  col0 ,   int  row1 ,   int  col1 )
   {
     Cell  tmp  =  cells [ row0 ][ col0 ];
    
    cells [ row0 ][ col0 ]   =  cells [ row1 ][ col1 ];
    cells [ row0 ][ col0 ]. setNewPosition ( row0 ,  col0 );    // Not row1 and col1
    cells [ row1 ][ col1 ]   =  tmp ;
    cells [ row1 ][ col1 ]. setNewPosition ( row1 ,  col1 );
    
    refresh ();
   }
  
   public   void  button1ClickEventListener ( BGPEventListener  listener )
   {
    button1Listener  =  listener ;
   }
  
   public   void  button1SetName ( String  name )
   {
    button1 . setText ( name );
   }
  
   public   void  button2ClickEventListener ( BGPEventListener  listener )
   {
    button2Listener  =  listener ;
   }
  
   public   void  button2SetName ( String  name )
   {
    button2 . setText ( name );
   }
  
   public   void  showMessageDialog ( String  msg )
   {
     JOptionPane . showMessageDialog ( frame ,  msg );
   }
  
   public   String  getText ()
   {
     return  textField . getText ();
   }
  
   public   void  setText ( String  s )
   {
    textField . setText ( s );
   }
  
   public   void  appendText ( String  text )
   {
    textArea . append ( text  +   "\n" );
     // textArea.setCaretPosition(textArea.getDocument().getLength() - 1);  // It does not work
   }
  
   public   void  clearText ()
   {
    textArea . setText ( "" );
   }
  
   public   void  sleep ( long  ms )
   {
    panelBoard . revalidate ();    // It does work.
    panelBoard . repaint ();

     try   {
       Thread . sleep ( ms );
     }   catch   ( InterruptedException  e )   {
     }
   }
}

Project/trubgp/Board$1.class

package trubgp;
synchronized class Board$1 implements java.awt.event.ActionListener {
    void Board$1(Board);
    public void actionPerformed(java.awt.event.ActionEvent);
}

Project/trubgp/Board$2.class

package trubgp;
synchronized class Board$2 implements java.awt.event.ActionListener {
    void Board$2(Board);
    public void actionPerformed(java.awt.event.ActionEvent);
}

Project/trubgp/Board.class

package trubgp;
public synchronized class Board {
    private int N;
    private int M;
    private int CELL_HEIGHT;
    private int CELL_WIDTH;
    private java.awt.Color boardCellColor;
    public Cell[][] cells;
    private javax.swing.JPanel panelBoard;
    private javax.swing.JPanel panelInput;
    private javax.swing.JPanel panelOutput;
    private javax.swing.JFrame frame;
    private javax.swing.JTextField textField;
    private javax.swing.JButton button1;
    private javax.swing.JButton button2;
    private BGPEventListener button1Listener;
    private BGPEventListener button2Listener;
    private javax.swing.JTextArea textArea;
    public void Board(int, int, int, int, String, java.awt.Color);
    public void Board(int, int, int, int);
    private void create(int, int, int, int, String, java.awt.Color);
    public void dispose();
    public void setTitle(String);
    public void refresh();
    public void cellsClickEventListener(BGPEventListener);
    public java.awt.Color cellBackgroundColor(int, int);
    public void cellBackgroundColor(int, int, java.awt.Color);
    public String cellContent(int, int);
    public void cellContent(int, int, String);
    public void cellContent(int, int, String, float);
    public void switchCells(int, int, int, int);
    public void button1ClickEventListener(BGPEventListener);
    public void button1SetName(String);
    public void button2ClickEventListener(BGPEventListener);
    public void button2SetName(String);
    public void showMessageDialog(String);
    public String getText();
    public void setText(String);
    public void appendText(String);
    public void clearText();
    public void sleep(long);
}

Project/trubgp/Board.java

Project/trubgp/Board.java

package  trubgp ;

import  java . awt . * ;
import  java . awt . event . * ;
import  javax . swing . * ;

public   class   Board
{
   private   int  N ,  M ,  CELL_HEIGHT ,  CELL_WIDTH ;
   private   Color  boardCellColor ;
   public   Cell  cells [][];
   private   JPanel  panelBoard ,  panelInput ,  panelOutput ;
   private   JFrame  frame ;
   private   JTextField  textField ;
   private   JButton  button1  =   null ,  button2  =   null ;
   private   BGPEventListener  button1Listener ,  button2Listener ;
   private   JTextArea  textArea ;
    
   public   Board ( int  rows ,   int  columns ,   int  width ,   int  height ,   String  style ,   Color  color )
   {
    create ( rows ,  columns ,  width ,  height ,  style ,  color );
   }

   public   Board ( int  rows ,   int  columns ,   int  width ,   int  height )
   {
    create ( rows ,  columns ,  width ,  height ,   "Line" ,   Color . WHITE );
   }
  
   private   void  create ( int  rows ,   int  columns ,   int  width ,   int  height ,   String  style ,   Color  color )
   {
    N  =  rows ;
    M  =  columns ;
    CELL_HEIGHT  =  height  /  rows ;
    CELL_WIDTH  =  width  /  columns ;
    
    boardCellColor  =  color ;
    
    panelBoard  =   new   JPanel ();
    panelBoard . setPreferredSize ( new   Dimension ( width ,  height ));
    panelBoard . setLayout ( new   GridLayout ( N ,  M ));
    panelBoard . setBorder ( BorderFactory . createCompoundBorder (
                             BorderFactory . createLineBorder ( Color . BLACK ,   1 ),  
                             BorderFactory . createLineBorder ( Color . WHITE ,   0 )));    // 0 -> padding 0
    
    textField  =   new   JTextField ( 20 );
    button1  =   new   JButton ( "Button1" );
    button1 . addActionListener ( new   ActionListener ()   {
      @ Override
       public   void  actionPerformed ( ActionEvent  event )
       {
         if   ( button1Listener  !=   null )
          button1Listener . clicked ( - 1 ,   - 1 );
       }
     });
    button2  =   new   JButton ( "Button2" );
    button2 . addActionListener ( new   ActionListener ()   {
      @ Override
       public   void  actionPerformed ( ActionEvent  event )
       {
         if   ( button2Listener  !=   null )
          button2Listener . clicked ( - 1 ,   - 1 );
       }
     });

    panelInput  =   new   JPanel ( new   FlowLayout ( FlowLayout . LEFT ));
    panelInput . setPreferredSize ( new   Dimension ( width ,   60 ));
    panelInput . setBorder ( BorderFactory . createCompoundBorder (
                             BorderFactory . createLineBorder ( Color . BLACK ,   0 ),  
                             BorderFactory . createLineBorder ( Color . WHITE ,   10 )));    // 0 -> padding 0
    panelInput . add ( textField );
    panelInput . add ( button1 );
    panelInput . add ( button2 );
                   
    panelOutput  =   new   JPanel ( new   FlowLayout ( FlowLayout . LEFT ));
    panelOutput . setPreferredSize ( new   Dimension ( width ,   110 ));
    panelOutput . setBorder ( BorderFactory . createCompoundBorder (
                             BorderFactory . createLineBorder ( Color . BLACK ,   0 ),  
                             BorderFactory . createLineBorder ( Color . WHITE ,   10 )));    // 0 -> padding 0
    textArea  =   new   JTextArea ( 5 ,   40 );
    textArea . setEditable ( false );
    panelOutput . add ( textArea );

   
    cells  =   new   Cell [ N ][];
     for   ( int  r  =   0 ;  r  <  N ;  r ++ )   {
      cells [ r ]   =   new   Cell [ M ];
       for   ( int  c  =   0 ;  c  <  M ;  c ++ )   {
        cells [ r ][ c ]   =   new   Cell ( panelBoard ,  r ,  c ,  CELL_WIDTH ,  CELL_HEIGHT ,   "" ,   0 );
        cells [ r ][ c ]. cellBackgroundColor ( boardCellColor );
         if   ( style . equals ( "NoLine" )   ||  style . equals ( "NO_LINE" ))
          cells [ r ][ c ]. setBorderWidth ( 0 );
       }
     }
    
    frame  =   new   JFrame ( "TRU Board Games Playground" );
    frame . setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE );
     //frame.setLayout(new GridLayout(3, 1));
    frame . getContentPane (). add ( panelBoard ,   BorderLayout . NORTH );
    frame . getContentPane (). add ( panelInput ,   BorderLayout . CENTER );
    frame . getContentPane (). add ( panelOutput ,   BorderLayout . SOUTH );
    frame . pack ();
    frame . setVisible ( true );
   }
  
   public   void  dispose ()
   {
    frame . dispose ();
   }

   public   void  setTitle ( String  title )
   {
    frame . setTitle ( title );
   }
  
   public   void  refresh ()
   {
    panelBoard . removeAll ();
    
     for   ( int  r  =   0 ;  r  <  N ;  r ++ )
       for   ( int  c  =   0 ;  c  <  M ;  c ++ )   {
        panelBoard . add ( cells [ r ][ c ]. getButton ());
         //cells[r][c].getButton().revalidate();
       }
    
     //panelBoard.invalidate();  // It does not work.
    panelBoard . revalidate ();    // It does work.
    panelBoard . repaint ();

     // Let's give Java Event Manager some time so that all the changes in BGP can be properly rendered.
    sleep ( 5 );
   }

   public   void  cellsClickEventListener ( BGPEventListener  listener )
   {
     for   ( int  r  =   0 ;  r  <  N ;  r ++ )
       for   ( int  c  =   0 ;  c  <  M ;  c ++ )
        cells [ r ][ c ]. clickEventListener ( listener );
   }
  
   public   Color  cellBackgroundColor ( int  row ,   int  col )
   {
     return  cells [ row ][ col ]. cellBackgroundColor ();
   }

   public   void  cellBackgroundColor ( int  row ,   int  col ,   Color  color )
   {
    cells [ row ][ col ]. cellBackgroundColor ( color );
   }

   public   String  cellContent ( int  row ,   int  col )
   {
     return  cells [ row ][ col ]. cellContent ();
   }

   public   void  cellContent ( int  row ,   int  col ,   String  content )
   {
    cells [ row ][ col ]. cellContent ( content );
   }

   public   void  cellContent ( int  row ,   int  col ,   String  content ,   float  fontSize )
   {
    cells [ row ][ col ]. cellContent ( content ,  fontSize );
   }
  
   public   void  switchCells ( int  row0 ,   int  col0 ,   int  row1 ,   int  col1 )
   {
     Cell  tmp  =  cells [ row0 ][ col0 ];
    
    cells [ row0 ][ col0 ]   =  cells [ row1 ][ col1 ];
    cells [ row0 ][ col0 ]. setNewPosition ( row0 ,  col0 );    // Not row1 and col1
    cells [ row1 ][ col1 ]   =  tmp ;
    cells [ row1 ][ col1 ]. setNewPosition ( row1 ,  col1 );
    
    refresh ();
   }
  
   public   void  button1ClickEventListener ( BGPEventListener  listener )
   {
    button1Listener  =  listener ;
   }
  
   public   void  button1SetName ( String  name )
   {
    button1 . setText ( name );
   }
  
   public   void  button2ClickEventListener ( BGPEventListener  listener )
   {
    button2Listener  =  listener ;
   }
  
   public   void  button2SetName ( String  name )
   {
    button2 . setText ( name );
   }
  
   public   void  showMessageDialog ( String  msg )
   {
     JOptionPane . showMessageDialog ( frame ,  msg );
   }
  
   public   String  getText ()
   {
     return  textField . getText ();
   }
  
   public   void  setText ( String  s )
   {
    textField . setText ( s );
   }
  
   public   void  appendText ( String  text )
   {
    textArea . append ( text  +   "\n" );
     // textArea.setCaretPosition(textArea.getDocument().getLength() - 1);  // It does not work
   }
  
   public   void  clearText ()
   {
    textArea . setText ( "" );
   }
  
   public   void  sleep ( long  ms )
   {
    panelBoard . revalidate ();    // It does work.
    panelBoard . repaint ();

     try   {
       Thread . sleep ( ms );
     }   catch   ( InterruptedException  e )   {
     }
   }
}

Project/trubgp/Cell (1).java

Project/trubgp/Cell (1).java

package  trubgp ;

import  java . awt . * ;
import  java . awt . event . * ;
import  javax . swing . * ;

public   class   Cell
{
   private   String  content ;
   private   float  contentFontSize ;
   private   JButton  button ;
   public   int  row ,  col ;
   public   BGPEventListener  listener  =   null ;
   Cell  thisCell ;
   private   Color  color ;
  
   public   Cell ( JPanel  panel ,   int  r ,   int  c ,   int  width ,   int  height )
   {
    create ( panel ,  r ,  c ,  width ,  height ,   "" ,   0 );
   }
  
   public   Cell ( JPanel  panel ,   int  r ,   int  c ,   int  width ,   int  height ,   String  content )
   {
    create ( panel ,  r ,  c ,  width ,  height ,  content ,   0 );
   }
  
   public   Cell ( JPanel  panel ,   int  r ,   int  c ,   int  width ,   int  height ,   String  content ,   float  fontSize )
   {
    create ( panel ,  r ,  c ,  width ,  height ,  content ,  fontSize );
   }

   private   void  create ( JPanel  panel ,   int  r ,   int  c ,   int  width ,   int  height ,   String  content ,   float  fontSize )
   {
     this . thisCell  =   this ;
     this . content  =  content ;
     this . contentFontSize  =  fontSize ;

     this . button  =   new   JButton ( content );
     this . button . addActionListener ( new   ActionListener ()   {
      @ Override
       public   void  actionPerformed ( ActionEvent  event )
       {
         //thisCell.listener.clicked(thisCell, row, col);
         if   ( listener  !=   null )
          listener . clicked ( row ,  col );
       }
     });
     this . button . setPreferredSize ( new   Dimension ( width ,  height ));
     if   ( fontSize  >   0 )
       this . button . setFont ( this . button . getFont (). deriveFont ( fontSize ));     
     this . button . setBackground ( Color . WHITE );
     this . color  =   Color . WHITE ;
     this . button . setBorder ( BorderFactory . createCompoundBorder (
                             BorderFactory . createLineBorder ( Color . BLACK ,   1 ),    // 1 -> border width 1
                             BorderFactory . createLineBorder ( Color . WHITE ,   0 )));    // 0 -> padding 0
    panel . add ( button );
    
     this . row  =  r ;
     this . col  =  c ;
   }
  
   public   void  cellBackgroundColor ( Color  color )
   {
     this . button . setBackground ( color );
     this . color  =  color ;
   }
  
   public   Color  cellBackgroundColor ()
   {
     return   this . color ;
   }
  
   public   String  cellContent ()
   {
     return  content ;
   }
  
   public   void  cellContent ( String  newContent )
   {
     this . content  =  newContent ;
     this . button . setText ( newContent );
     if   ( this . contentFontSize  >   0 )
       this . button . setFont ( this . button . getFont (). deriveFont ( this . contentFontSize ));     
   }
  
   public   void  cellContent ( String  newContent ,   float  fontSize )
   {
     this . content  =  newContent ;
     this . contentFontSize  =  fontSize ;
     this . button . setText ( newContent );
     if   ( this . contentFontSize  >   0 )
       this . button . setFont ( this . button . getFont (). deriveFont ( this . contentFontSize ));     
   }
  
   public   void  clickEventListener ( BGPEventListener  listener )
   {
     this . listener  =  listener ;
   }
  
   /*
  public void refreshActionListener()
  {
    for (ActionListener al: this.button.getActionListeners())
      this.button.removeActionListener(al);
    
    this.button.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent event)
      {
        listener.clicked(row, col); 
      }
    });
  }
  */
  
   public   JButton  getButton ()
   {
     return   this . button ;
   }
  
   public   void  setNewPosition ( int  newRow ,   int  newCol )
   {
     this . row  =  newRow ;
     this . col  =  newCol ;
   }
  
   public   void  setBorderWidth ( int  newWidth )
   {
     this . button . setBorder ( BorderFactory . createCompoundBorder (
                             BorderFactory . createLineBorder ( Color . BLACK ,  newWidth ),  
                             BorderFactory . createLineBorder ( Color . WHITE ,   0 )));    // 0 -> padding 0
   }
}

Project/trubgp/Cell$1.class

package trubgp;
synchronized class Cell$1 implements java.awt.event.ActionListener {
    void Cell$1(Cell);
    public void actionPerformed(java.awt.event.ActionEvent);
}

Project/trubgp/Cell.class

package trubgp;
public synchronized class Cell {
    private String content;
    private float contentFontSize;
    private javax.swing.JButton button;
    public int row;
    public int col;
    public BGPEventListener listener;
    Cell thisCell;
    private java.awt.Color color;
    public void Cell(javax.swing.JPanel, int, int, int, int);
    public void Cell(javax.swing.JPanel, int, int, int, int, String);
    public void Cell(javax.swing.JPanel, int, int, int, int, String, float);
    private void create(javax.swing.JPanel, int, int, int, int, String, float);
    public void cellBackgroundColor(java.awt.Color);
    public java.awt.Color cellBackgroundColor();
    public String cellContent();
    public void cellContent(String);
    public void cellContent(String, float);
    public void clickEventListener(BGPEventListener);
    public javax.swing.JButton getButton();
    public void setNewPosition(int, int);
    public void setBorderWidth(int);
}

Project/trubgp/Cell.java

Project/trubgp/Cell.java

package  trubgp ;

import  java . awt . * ;
import  java . awt . event . * ;
import  javax . swing . * ;

public   class   Cell
{
   private   String  content ;
   private   float  contentFontSize ;
   private   JButton  button ;
   public   int  row ,  col ;
   public   BGPEventListener  listener  =   null ;
   Cell  thisCell ;
   private   Color  color ;
  
   public   Cell ( JPanel  panel ,   int  r ,   int  c ,   int  width ,   int  height )
   {
    create ( panel ,  r ,  c ,  width ,  height ,   "" ,   0 );
   }
  
   public   Cell ( JPanel  panel ,   int  r ,   int  c ,   int  width ,   int  height ,   String  content )
   {
    create ( panel ,  r ,  c ,  width ,  height ,  content ,   0 );
   }
  
   public   Cell ( JPanel  panel ,   int  r ,   int  c ,   int  width ,   int  height ,   String  content ,   float  fontSize )
   {
    create ( panel ,  r ,  c ,  width ,  height ,  content ,  fontSize );
   }

   private   void  create ( JPanel  panel ,   int  r ,   int  c ,   int  width ,   int  height ,   String  content ,   float  fontSize )
   {
     this . thisCell  =   this ;
     this . content  =  content ;
     this . contentFontSize  =  fontSize ;

     this . button  =   new   JButton ( content );
     this . button . addActionListener ( new   ActionListener ()   {
      @ Override
       public   void  actionPerformed ( ActionEvent  event )
       {
         //thisCell.listener.clicked(thisCell, row, col);
         if   ( listener  !=   null )
          listener . clicked ( row ,  col );
       }
     });
     this . button . setPreferredSize ( new   Dimension ( width ,  height ));
     if   ( fontSize  >   0 )
       this . button . setFont ( this . button . getFont (). deriveFont ( fontSize ));     
     this . button . setBackground ( Color . WHITE );
     this . color  =   Color . WHITE ;
     this . button . setBorder ( BorderFactory . createCompoundBorder (
                             BorderFactory . createLineBorder ( Color . BLACK ,   1 ),    // 1 -> border width 1
                             BorderFactory . createLineBorder ( Color . WHITE ,   0 )));    // 0 -> padding 0
    panel . add ( button );
    
     this . row  =  r ;
     this . col  =  c ;
   }
  
   public   void  cellBackgroundColor ( Color  color )
   {
     this . button . setBackground ( color );
     this . color  =  color ;
   }
  
   public   Color  cellBackgroundColor ()
   {
     return   this . color ;
   }
  
   public   String  cellContent ()
   {
     return  content ;
   }
  
   public   void  cellContent ( String  newContent )
   {
     this . content  =  newContent ;
     this . button . setText ( newContent );
     if   ( this . contentFontSize  >   0 )
       this . button . setFont ( this . button . getFont (). deriveFont ( this . contentFontSize ));     
   }
  
   public   void  cellContent ( String  newContent ,   float  fontSize )
   {
     this . content  =  newContent ;
     this . contentFontSize  =  fontSize ;
     this . button . setText ( newContent );
     if   ( this . contentFontSize  >   0 )
       this . button . setFont ( this . button . getFont (). deriveFont ( this . contentFontSize ));     
   }
  
   public   void  clickEventListener ( BGPEventListener  listener )
   {
     this . listener  =  listener ;
   }
  
   /*
  public void refreshActionListener()
  {
    for (ActionListener al: this.button.getActionListeners())
      this.button.removeActionListener(al);
    
    this.button.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent event)
      {
        listener.clicked(row, col); 
      }
    });
  }
  */
  
   public   JButton  getButton ()
   {
     return   this . button ;
   }
  
   public   void  setNewPosition ( int  newRow ,   int  newCol )
   {
     this . row  =  newRow ;
     this . col  =  newCol ;
   }
  
   public   void  setBorderWidth ( int  newWidth )
   {
     this . button . setBorder ( BorderFactory . createCompoundBorder (
                             BorderFactory . createLineBorder ( Color . BLACK ,  newWidth ),  
                             BorderFactory . createLineBorder ( Color . WHITE ,   0 )));    // 0 -> padding 0
   }
}

Project/Vertex.java

Project/Vertex.java

public   class   Vertex < T >
{
   private   int  id ;
   private  T content ;
   private   Vertex < T >  parent ;
   private   boolean  visited ;
   private   boolean  expanded ;
  
   public   Vertex ()  
   {
    id  =   - 1 ;
    content  =   null ;
    parent  =   null ;
    visited  =   false ;
    expanded  =   false ;
   }
  
   public   Vertex ( T content )  
   {
    id  =   - 1 ;
     this . content  =  content ;
    parent  =   null ;
    visited  =   false ;
    expanded  =   false ;
   }
  
   public   Vertex ( int  id ,  T content )  
   {
     this . id  =  id ;
     this . content  =  content ;
    parent  =   null ;
    visited  =   false ;
    expanded  =   false ;
   }
  
   public   Vertex ( int  id ,  T content ,   Vertex < T >  parent )  
   {
     this . id  =  id ;
     this . content  =  content ;
     this . parent  =  parent ;
    visited  =   false ;
    expanded  =   false ;
   }
  
   public   void  reset ( int  id ,  T content )
   {
     this . id  =  id ;
     this . content  =  content ;
    parent  =   null ;
    visited  =   false ;
    expanded  =   false ;
   }
  
   public   void  reset ()
   {
    parent  =   null ;
    visited  =   false ;
    expanded  =   false ;
   }
  
   public   int  getId ()
   {
     return  id ;
   }
  
   public  T getContent ()
   {
     return  content ;
   }
  
   public   Vertex < T >  getParent ()
   {
     return  parent ;
   }
  
   public   void  setParent ( Vertex < T >  parent )
   {
     this . parent  =  parent ;
   }
  
   public   boolean  isVisited ()
   {
     return  visited ;
   }
  
   public   void  visited ()
   {
    visited  =   true ;
   }
  
   public   void  visited ( boolean  b )
   {
    visited  =  b ;
   }
  
   public   boolean  isExpanded ()
   {
     return  expanded ;
   }
  
   public   void  expanded ()
   {
    expanded  =   true ;
   }
  
   public   void  expanded ( boolean  b )
   {
    expanded  =  b ;
   }
}

Project/VertexString.java

Project/VertexString.java

public   class   VertexString   extends   Vertex < String >
{
   public   VertexString ( String  content )
   {
     super ( content );
   }
  
   public   VertexString ( int  id ,   String  content )
   {
     super ( id ,  content );
   }
  
   public   VertexString ( int  id ,   String  content ,   VertexString  parent )
   {
     super ( id ,  content ,  parent );
   }
}