📄 applet1.java
字号:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import SettingDlg;
import Demo;
import GoThread;
//import Demo;
//import GoThread;
public class Applet1 extends Applet implements ActionListener
{
public int m_nStep=-1;
public boolean m_bPaused =true;
public boolean m_bStepInto =false;
public Button m_btnNext,m_btnReset,m_btnGo,m_btnSetting,m_btnStepIn;
private TextArea m_taSource;
private boolean m_bSortType =true;
private String m_sDefault="WERs8CP";
private String m_sData;
public Demo m_Demo;
private GoThread m_Go;
private String m_sCode[]=
{
"void LInsertionSort (Elem SL[ ], int n) ", //0
"{ ", //1
" SL[0].key = MAXINT ; ", //2
" SL[0].next= 1; SL[1].next = 0; ", //3
" for(i=2;i<=n;++i){ ", //4
" for(j=0,k=SL[0].next;Compare(SL[k].key ", //5
" SL[i].key);j=k,k=SL[k].next) ", //6
" { ; } //Notice here is null loop ", //7
" SL[j].next = i; ", //8
" SL[i].next = k; ", //9
" } ", //10
" Arrange(SL,n); ", //11
"}//LinsertionSort ", //12
" ", //13
"void Arrange ( Elem SL[ ], int n ) ", //14
"{ ", //15
" p = SL[0].next; ", //16
" for ( i=1; i<n; ++i ) ", //17
" { ", //18
" while (p<i) p = SL[p].next; ", //19
" q = SL[p].next; ", //20
" if ( p!= i ) { ", //21
" SL[p]←→SL[i]; ", //22
" SL[i].next = p; ", //23
" } ", //24
" p = q; ", //25
" } ", //26
"} // Arrange " //27
};
private void addComponent(Component c,int x,int y, int width,int height)
{
c.setLocation (x,y);
c.setSize (width,height);
add (c);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource ()==m_btnSetting)
{
Frame m_Frame=new Frame("setting test");
SettingDlg m_Dlg=new SettingDlg (m_Frame,m_sData,m_bSortType);
m_Dlg.setDefault (m_sDefault);
m_Dlg.setLocation (320,240);
m_Dlg.setVisible (true);
if(m_Dlg.IsUpdate()){
m_sData =m_Dlg.getData ();
m_bSortType =m_Dlg.getSortType ();
m_bPaused =true;
m_nStep=-1;
showSource();
m_Demo.reset ();
m_bStepInto=false;
m_btnStepIn.setLabel ("跟踪子程");
m_Go=new GoThread (this);
m_Go.start ();
}
}
else if(e.getSource ()==m_btnNext)
{
if(m_nStep==-1)
{
m_Demo.setData (m_sData,m_bSortType);
}
if(m_nStep==11&&m_bStepInto)
{
m_nStep=20;
// showSource();
}
m_nStep=m_Demo.proceed (m_nStep);
showSource();
}
else if(e.getSource ()==m_btnReset)
{
m_nStep=-1;
m_bStepInto=false;
m_btnStepIn.setLabel ("跟踪子程");
m_Demo.reset();
m_Go=new GoThread (this);
m_Go.start();
showSource();
}
else if(e.getSource ()==m_btnStepIn)
{
if(m_bStepInto)
{
m_btnStepIn.setLabel ("跟踪子程");
m_bStepInto=false;
}
else
{
m_bStepInto=true;
m_btnStepIn.setLabel("跳过子程");
}
}
else if(e.getSource ()==m_btnGo)
{
if(m_nStep==-1)
{
m_Demo.setData (m_sData,m_bSortType);
showSource();
}
if(m_bPaused)
{
m_Go.resume ();
m_bPaused=false;
m_btnGo.setLabel ("暂停执行");
m_btnNext.setEnabled (false);
m_btnSetting.setEnabled (false);
m_btnReset.setEnabled (false);
}
else
{
m_Go.suspend ();
m_btnGo.setLabel("连续执行");
m_bPaused = true;
m_btnNext.setEnabled(true);
m_btnReset.setEnabled(true);
m_btnSetting .setEnabled (true);
}
}
}
public void setSource()
{
m_taSource.setText("");
for(int i=0;i<m_sCode.length ;i++)
m_taSource.append (m_sCode[i]+"\r\n");
}
public void showSource()
{
if(m_nStep==-1)
{
m_taSource.select (0,0);
return;
}
int nStart=0;
int nEnd=0;
int step=m_nStep;
if(m_nStep>=20)
step=step-6;
for(int i=0;i<step;i++)
nStart+=m_sCode[i].length()+1;
nEnd=nStart+m_sCode[step].length ()+1;
m_taSource.select(nStart,nEnd);
}
public void init()
{
m_Demo =new Demo ();
m_taSource =new TextArea(20,50);
m_taSource. setEditable(false);
m_taSource. setBackground( Color.white );
setSource ();
m_btnNext =new Button ("单步执行");
m_btnGo =new Button ("连续执行");
m_btnReset =new Button ("重新开始");
m_btnStepIn =new Button ("跟踪子程");
m_btnSetting =new Button ("排序设置");
m_btnNext. addActionListener(this);
m_btnGo. addActionListener (this);
m_btnReset. addActionListener (this);
m_btnStepIn. addActionListener (this);
m_btnSetting. addActionListener(this);
int nHeight =20;
int nWidth =15;
setLayout(null);
addComponent(m_taSource,20,20,320,240);
addComponent(m_Demo,340,20,380,280);
addComponent(m_btnReset,20,320,nWidth*5,nHeight);
addComponent(m_btnNext, 120,320,nWidth*5,nHeight);
addComponent(m_btnStepIn,320,320,nWidth*5,nHeight);
addComponent(m_btnGo, 420,320,nWidth*5,nHeight);
addComponent(m_btnSetting,520,320,nWidth*5,nHeight);
m_sData =m_sDefault;
m_nStep =-1;
m_bSortType =true;
m_bStepInto =false;
//m_btnStepIn.setEnabled(false);
m_Go =new GoThread (this);
m_Go.start ();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -