⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 animation.java

📁 ALGAE是一个快速创建算法演示的框架。目前支持的算法实现语言包括java和c
💻 JAVA
字号:
package edu.odu.cs.zeil.AlgAE.Server;import edu.odu.cs.zeil.AlgAE.Application;import edu.odu.cs.zeil.AlgAE.Debug;import edu.odu.cs.zeil.AlgAE.ExternalMessageIO;import edu.odu.cs.zeil.AlgAE.MessageIO;import edu.odu.cs.zeil.AlgAE.Client.Client;import edu.odu.cs.zeil.AlgAE.Server.InternalMessageIO;import edu.odu.cs.zeil.AlgAE.Server.Server;import edu.odu.cs.zeil.AlgAE.Server.ServerThread;import java.applet.Applet;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.FileReader;import java.io.FileWriter;import java.io.InputStreamReader;import java.io.PrintWriter;import java.util.Hashtable;/** *  This is the base class for all AlgAE Java animations. *  <P> *  In general, an AlgAE animation consists of a <B>server</B> that *  runs the actual data structure and algorithm code to be animated, *  periodically sending messages about its current data state to the *  <B>client</B>.  The client is responsible for interpreting those *  messages, rendering them as a graphical image, and handling interaction *  with the human operator. *  <P> *  When animating Java code, the server and client are simply separate *  threads running within a single Java applet/application, communicating *  via a pipeline.  This class establishes that connection, *  <P> *  When animating C++ or other languages, however, the AlgAE Client is *  run as a separate applet/application on the user's machine, and *  communicates via TCP/IP sockets with a C++ AlgAE server running as *  a separate program, possibly elsewhere on the internet.  In this case, *  the class <code>Algorithm</code> and the <code>Server</code> package *  are not used. * *  @author Steven J Zeil **/public abstract class Animation extends Applet implements MenuGenerator{  private Client client;  private ServerThread server;  private String theTitle;  private Application application;    private String[][] pinfo = {//    {"host", "ip-name", "name of machine on which server is running"},//    {"port", "integer", "socket # at which to contact the server host"},    {"infile", "url", "input file of previously recorded AlgAE messages"},    {"outfile", "url", "output file for messages from AlgAE client"},    {"logfile", "url", "output file for logging messages for later playback"},    {"debug", "url", "output file for logging debugging info"},    {"layout", "wide | tall", "Should graphics fill window's width or height?"},    {"applet", "panel | window", "Should applet be run as a separate window?"},    {"fontsize", "int", "initial font size for client data/code display"},    {"help", "url", "location of help files"}  };              public Animation (String title, String[] args)  {    Hashtable arguments = Application.parseCommandLine(args);    application = new Application();    try      {	init (title, arguments);      }    catch (Exception e) {System.exit(1);}  }    public Animation(String title)  {    application = new Application();    application.applet = this;    theTitle = title;  }  /**   *  Supply a message to appear in the Help..About dialog.   *  Typically, this indicates the origin of the source code   *  being animated and the name of the person who prepared the   *  animation.   **/  public abstract String about();    /**   *  This routine should perform one or more calls to algae.menuItem   *  to create menu entries that the user can selesct via the Algorithm   *  menu.   */  public abstract void menu ();      private void init (String title, Hashtable arguments)    throws java.io.FileNotFoundException, java.io.IOException  {    server = null;    BufferedReader inStreamClient  = null;    PrintWriter    outStreamClient = null;        // If the program is invoked with -infile and -outfile arguments, then    // we will have no server but will "play back" a set of AlgAE messages    // previously saved in a file.    String fileName = (String)arguments.get("infile");    if (fileName != null)      try {	inStreamClient = new BufferedReader (new FileReader(fileName));	application.inReader = inStreamClient;      }    catch (java.io.FileNotFoundException e) {      Debug.error ("Unable to open " + fileName);      throw e;    }        fileName = (String)arguments.get("outfile");    if (fileName != null)      try {	outStreamClient = new PrintWriter(new BufferedWriter (new FileWriter(fileName)));	application.outWriter = outStreamClient;      }    catch (java.io.IOException e) {      System.out.println ("Unable to open " + fileName);      throw e;    }        MessageIO serverIO;    MessageIO clientIO;        if ((inStreamClient == null) || (outStreamClient == null))      {	InternalMessageIO io = new InternalMessageIO();	serverIO = io.serverIO();	clientIO = io.clientIO();		Debug.show (Debug.threads, "Animation.init: create server thread");	ServerThread s = new ServerThread (title, application, this, serverIO);	// application.register (s);	Debug.show (Debug.threads, "Animation.init: start server thread");	s.start();      }    else      clientIO = new ExternalMessageIO (inStreamClient, outStreamClient, 					application);    Debug.show (Debug.threads, "Animation.init: ready to launch client");    Client client = new Client (application, arguments, clientIO);    Debug.show (Debug.threads, "Animation.init: client launched");  }  public String[][] getParameterInfo()  {    return pinfo;  }    public void init()  {    Hashtable args = new Hashtable();    for (int i = 0; i < pinfo.length; ++i)      {	String val = getParameter(pinfo[i][0]);	if (val != null)	  {	    args.put (pinfo[i][0], val);	  }      }    int fileNum = 0;    while (true)      {	String number = "" + fileNum;		String name = "source" + number;	String val = getParameter(name);	if (val != null)	  {	    args.put (name, val);	  }	else	  break;		name = "index" + number;	val = getParameter(name);	if (val != null)	  {	    args.put (name, val);	  }	++fileNum;      }        try {      init(theTitle, args);    }    catch (Exception e)  {destroy();}  }  	    public void destroy()  {    server.stop();    super.destroy();  }    }  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -