首页>代码>java算法大全源码包(转网上的)>/codefans.net/java算法大全源码包/BD/AlgThread.java
/* AlgThread.java */

import java.awt.*;
import java.io.*;
import java.applet.*;
import java.net.*;
import java.util.*;

/**
 * <code>AlgThread</code> is an extension of the provided Java 
 * multi-threading package.
 * It enables the graphical display of the main execution thread to be
 * updated during the execution of the algorithm.
 * <p>
 * A section of this source file is normally displayed on the TextFrame.
 * This section starts with the line after 
 * <code>/*------------------*</code><code>/
 * </code> and finishes before the line <code>//------------
 * </code>.
 * Every line starting with <code>/*-*</code><code>/</code> will be discarded in
 * the source code display area and each line is terminated by the first
 * encounter of <code>/*-*</code><code>/</code>.
 * <p>
 * The source file <code>AlgThread.java</code> is <b>to be
 * modified/completed</b> for separate animation algorithms.
 *
 * @authorWoi L Ang
 * @sinceJDK1.0
 */
public class AlgThread extends Thread {
	/**
	 * Size of the data set appropriate for algorighm animation.
	 */
	public int max_data = 7;
	/**
	 * Array of strings used to set the choices of the data choice button
	 * in data menu.
	 */
	public static String[] dataSets = 
	{"Data Set 1", "Data Set 2", "Data Set 3"};

	private static String[] URLs =
		{ "http://ciips.ee.uwa.edu.au/~koh-ta/BD/BD.form",
		 "BD/BD.form",
		 "http://ciips.ee.uwa.edu.au/~koh-ta/BD/BD1.form"
		};

	/**
	 * The initial caller of the constructor of this class.
	 * It holds the references to all existing panels.
	 */ 
	public AlgAnimFrame frame;
	/**
	 * A reference to the drawing panel in order to update the animation
	 * during the execution of the algorithm.
	 * @see DrawingPanel
	 */
	public DrawingPanel drawingPanel;

	BlockDiagram bd;
	//TransDiagram td;

	/**
	 * Creates a new thread using the frame passed in as the parameter.
	 * If this constructor is called from the frame constructor,
	 * a drawingPanel will be initialized and assigned to the frame
	 * class.
	 * 
	 * @param frame An extended frame where the algorithm is going to 
	 * execute in.
	 *
	 * @see AlgAnimFrame
	 */
	public AlgThread(AlgAnimFrame frame) {
			this.frame = frame;
			this.drawingPanel = frame.getDrawingPanel();
			if (frame != null && frame.getAlg() != null && 
					frame.getAlg().drawingPanel != null) {
					// drawingPanel already created -> this constructor called from
					// clicking the run button -> use the generated data set
			}
	}

	/**
	 * Sets the delay between each animation step. This determines
	 * the rate the drawingPanel is updated. The <code>setDelay</code>
	 * method is normally called by the action listener of
	 * the <code>delay choice button</code> on the control panel.
	 * @param delay The delay set in milliseconds.
	 */
	public void setDelay(int delay) {
		drawingPanel.setDelay(delay);
	}

	/**
	 * Generate data based on the choice made on the menu.
	 * This method is application specific
	 * and the contents for the satisfaction of each 'if' statement
	 * have to be filled in based on the algorithm.
	 */
	public void generateData() {
		URL url;
		this.drawingPanel = frame.getDrawingPanel();
		int choice = frame.getDataChoice();
		System.out.println("genData " + choice );
		switch( choice ) {
			case 0: 
				bd = new BlockDiagram("Test");
				bd.ConsTestCase();
				break;
			case 1:
			case 2:
				System.out.println("URL: " + URLs[choice] );
				URL homeURL = frame.getApplet().getCodeBase();
				try {
					url = new URL( homeURL, URLs[choice] );
					bd = new BlockDiagram( url );
				} catch( Exception e ) {
					System.out.println("Error forming URL from " + URLs[choice] );
				}
				break;
			default:
				System.out.println("Invalid choice");
			} 
		System.out.println("generateData: exit" );
		drawingPanel.init();
		}

/*--------------------------------------------------------------------*/
//----
	/**
	 * This method is invoked when the <code>Thread</code> class
	 * <code>start()</code> method is called.
	 * It contains the statements to execute the methods which perform
	 * the algorithm. This method is to be completed based on separate
	 * animation algorithms.
	 * @see java.lang.Thread
	 */
	public void run() {
		generateData();
		frame.getTextFrame();
		// alg here
		drawingPanel.addDrawingObj( bd );

		// finish sorting
		frame.finishAlg();
		}

	/**
	 * Restore the drawing panel at the beginning or the end of each
	 * simulation.
	 */
	public void restoreDrawingPanel() {
		}

	/**
	 * This method is to be placed after the line where the fast
	 * forward function is to be performed.
	 */
	public void waitSkip() {
		if (!drawingPanel.getSkip()) return;
		((ImageButton)frame.getSkipItem()).setEnable();
		((ImageButton)frame.getRunItem()).setEnable();
		((ImageButton)frame.getStopItem()).setDisable();
		drawingPanel.setSkip(false);
		frame.setStep(true);
		frame.waitStep();
		}
}
最近下载更多
姜广坤  LV14 2022年5月20日
wwykerwin  LV1 2022年3月22日
2196316269  LV10 2021年2月25日
safeqd2186  LV3 2020年12月12日
zzhsq2008  LV1 2020年9月10日
来水代码  LV1 2020年7月3日
才阿虎  LV1 2020年4月6日
wsk588  LV26 2020年1月15日
走你個魯  LV21 2020年1月13日
睡谷的传说  LV6 2019年12月30日
最近浏览更多
张言昊  LV9 2022年11月17日
姜广坤  LV14 2022年5月20日
wwykerwin  LV1 2022年3月22日
你脚上银铃响了  LV1 2021年10月27日
sfyzjc  LV2 2021年10月22日
xiaoluoaaa  LV8 2021年10月13日
 LV10 2021年6月12日
2196316269  LV10 2021年2月24日
少年迟暮 2021年1月25日
暂无贡献等级
safeqd2186  LV3 2020年12月12日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友