Package client.frame

Source Code of client.frame.YahtzeeFrame

package client.frame;

import general.statics.function.ErrorPumper;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import server.protocol.Message;
import client.gfx.wrapper.FaviconEngine;
import client.gui.Constants;
/**
* The <code>YahtzeeFrame</code> class is a subclass of <code>JFrame</code> that adds custom, desired functionality to it.
* It is also the upper-most class in the yahztee frame hierarchy, which also means that it contains the non-specific properties
* for all the frames of this project.
*
* @author Priidu Neemre
*/
public abstract class YahtzeeFrame extends JFrame {

  private static final long serialVersionUID = 00000001L;
  public static final String FRAME_DEFAULT_TITLE = "Yahtzee";
 
  public YahtzeeFrame(){
    //General properties for all the frames of the game
    this.setResizable(false);
    FaviconEngine fav = new FaviconEngine(Constants.FAVICON_PATH);
    this.setIconImage(fav.getFaviconImg());
  }
 
  /**
   * Updates all the GUI values and indicators accordingly to the current state of the client.
   */
  public abstract void updateGUIIndicators();
 
  /**
   * Writes a message of type <code>String</code> into the logging area (wherever the logging area is, is for the subclass
   * to decide) of the current frame.
   *
   * @param message  the string being written into the logging area
   */
  public abstract void writeToLogArea(String message);
 
  /**
   * Writes a message of type <code>Message</code> into the logging area (wherever the logging area is, is for the subclass
   * to decide) of the current frame.
   *
   * @param message  the message being written into the logging area
   */
  public abstract void writeToLogArea(Message msg);
 
  /**
   * A "thread-safe" container of the <code>updateGUIIndicators()</code> method, which queues the requested actions for the
   * EDT to complete. Enables other threads to call the updateGUIIndicators() method without the fear of Swing breaking.
   */
  public void updateGUIForeign(){
    try{
      SwingUtilities.invokeAndWait(new Runnable(){
        public void run(){
          updateGUIIndicators();
        }
      });
    }catch(Exception e){
      ErrorPumper.errorMsg(ErrorPumper.ERR015_UNKNOWN_ERROR_EDT, e);
    }
  }

  /**
   * A "thread-safe" container of the <code> writeToLogArea(String message)</code> method, which queues the requested
   * actions for the EDT to complete. Enables other threads to call the writeToLogArea(String message) method without
   * the fear of Swing breaking.
   *
   * @param message  the string being written into the logging area
   */
  public void writeToLogAreaForeign(final String message){
    try{
      SwingUtilities.invokeAndWait(new Runnable(){
        public void run(){
          writeToLogArea(message);
        }
      });
    }catch(Exception e){
      ErrorPumper.errorMsg(ErrorPumper.ERR015_UNKNOWN_ERROR_EDT, e);
    }
  }
 
  /**
   * A "thread-safe" container of the <code> writeToLogArea(Message msg)</code> method, which queues the requested
   * actions for the EDT to complete. Enables other threads to call the writeToLogArea(Message msg) method without
   * the fear of Swing breaking.
   *
   * @param message  the message being written into the logging area
   */
  public void writeTOLogAreaForeign(final Message msg){
    try{
      SwingUtilities.invokeAndWait(new Runnable(){
        public void run(){
          writeToLogArea(msg);
        }
      });
    }catch(Exception e){
      ErrorPumper.errorMsg(ErrorPumper.ERR015_UNKNOWN_ERROR_EDT, e);
    }
  }
}
TOP

Related Classes of client.frame.YahtzeeFrame

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.