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

📄 applet1.java

📁 学习数据结构的最好辅助工具,快速帮助你熟悉数据结构的相关技术
💻 JAVA
字号:
import java.awt.*;
import java.applet.*;
import Demo;
import GoThread;

public class Applet1 extends Applet
{
	private String sourceCode[] = {
		"void CreateList_L(LinkList &L, int n)",					// 0
		"{",														// 1
		"  L = new LNode();",										// 2
		"  L->next = NULL;",										// 3
		"  for (i = n; i > 0; --i)",								// 4
		"  {",														// 5
        "    p = new LNode();",										// 6
        "    scanf(&p->data);",										// 7
		"    p->next = L->next;",									// 8
		"    L->next = p;",											// 9
        "  }",														// 10
		"}" };														// 11
	private String m_data = "abcdef";
	private int m_numNodes = 6;
	public int m_step = 0;
	private int m_numLines = 12;
	private GoThread go;
	public boolean m_paused = true;

	// Virtual Machine and its process
	class CVirtualMachine
	{
		int p, i;
	};
	private CVirtualMachine m_VM;
	
	public int proceed()
	{
		switch(m_step)
		{
		case 0:
			m_data = tData.getText();
			m_numNodes = m_data.length();
			if(m_numNodes>6)
			{
				m_numNodes = 6;
				tData.setText(m_data.substring(0, 6));
			}
			m_LLDemo.reset(m_numNodes, m_data);
			return 2;
		case 2:
			m_LLDemo.create();
			return 3;
		case 3:
			m_LLDemo.setHeadNull();
			m_VM.i = m_numNodes+1;
			return 4;
		case 4:
			m_VM.i --;
			if(m_VM.i > 0) return 6;
			else return 11;
		case 6:
			m_LLDemo.newNode();
			return 7;
		case 7:
			m_LLDemo.setData();
			return 8;
		case 8:
			m_LLDemo.setNextPointer();
			return 9;
		case 9:
			m_LLDemo.setPointer();
			return 4;
		default:
			return 0;
		}
	}

	private GridBagLayout gbLayout;
	private GridBagConstraints gbConstraints;
	
	private TextArea Source;
	public Button bNext, bReset, bGo;
	private Demo m_LLDemo;
	private TextField tData;
	private Label l1;
	
	private void addComponent(Component c, int column, int row, int width, int height)
	{
		gbConstraints.gridx = column;
		gbConstraints.gridy = row;
		gbConstraints.gridwidth = width;
		gbConstraints.gridheight = height;
		gbLayout.setConstraints(c, gbConstraints);
		add(c);
	}

	/**
	 * The entry point for the applet. 
	 */
	public void init()
	{
		gbLayout = new GridBagLayout();
		setLayout( gbLayout );
		gbConstraints = new GridBagConstraints();
		
		Source = new TextArea( 20, 50);
		Source.setEditable(false);
		Source.setBackground(Color.white);
		for(int i=0;i<m_numLines;i++) Source.append(sourceCode[i] + "\r\n");
		bNext = new Button("执行下一句");
		bReset = new Button("重置环境");
		bGo = new Button("连续执行");
				
		m_LLDemo = new Demo(m_numNodes, m_data);
		m_LLDemo.setSize(350,200);
		tData = new TextField(m_data);
		l1 = new Label("链表数据", Label.RIGHT);
		l1.setSize(30, 20);

		addComponent(Source, 0, 0, 3, 2);
		addComponent(m_LLDemo, 3, 0, 3, 1);
		addComponent(l1, 4, 1, 1, 1);
		addComponent(tData, 5, 1, 1, 1);
		addComponent(bNext, 0, 2, 1, 1);
		addComponent(bReset, 1, 2, 1, 1);
		addComponent(bGo, 2, 2, 1, 1);
		
		m_VM = new CVirtualMachine();
		go = new GoThread(this);
		go.start();
	}

	public boolean action(Event p1, Object p2)
	{
		if( p1.target == bNext )
		{
			m_step = proceed();
			showSource();
		}
		else if( p1.target == bReset )
		{
			m_step = 0;
			showSource();
			m_LLDemo.reset(m_numNodes, m_data);
			m_LLDemo.repaint();
		}
		else if( p1.target == bGo )
		{
			if(m_paused)
			{
				bNext.setEnabled(false);
				bReset.setEnabled(false);
				go.resume();
				bGo.setLabel("暂停执行");
				m_paused = false;
			}
			else
			{
				go.suspend();
				bGo.setLabel("连续执行");
				m_paused = true;
				bNext.setEnabled(true);
				bReset.setEnabled(true);
			}
		}
		return true;
	}
	
	public void showSource()
	{
		int start = 0;
		for(int i=0; i<m_step; i++) start += sourceCode[i].length() + 1;
		Source.select( start, start + sourceCode[m_step].length() );
	}
	
}

⌨️ 快捷键说明

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