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

📄 frame.java

📁 Java AWT界面例子
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package end;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;import java.io.*;import java.util.*;import java.awt.image.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p> * @author unascribed * @version 1.0 */class mohu implements Runnable{        tong m_tong;        frame nowframe;		String s1;		StringBuffer s2;		int length;        Thread ComputeThread=null;        public void start()        {          if(ComputeThread==null)          {              ComputeThread=new Thread(this,"Compute");              ComputeThread.start();          }        }	void Init()	{                m_tong=new tong();                m_tong.nowframe=nowframe;                m_tong.ismohu=true;                m_tong.ComputeThread=ComputeThread;                nowframe.List1con.removeAllElements();                length = s1.length();	}	public void run()	{                Animate ani=new Animate();                ani.nowframe=nowframe;                ani.gook=true;                ani.aninum=0;                ani.start();                //try{ComputeThread.sleep(1);}catch(InterruptedException e){}		int i=0;		for(i=0;i<length;i++)		{                        m_tong=new tong();                        m_tong.nowframe=nowframe;                        m_tong.ismohu=true;			s2=new StringBuffer(s1);			s2.setCharAt(i,'?');                        m_tong.s1=s2.toString();                        m_tong.Init();                        m_tong.analyze();		}		for(i=0;i<length+1;i++)		{                        s2=new StringBuffer(s1);						s2.insert(i,'?');                        m_tong.s1=s2.toString();                        m_tong.Init();                        m_tong.analyze(); 		}        ani.gook=false;	}}class tong implements Runnable{        boolean isrunning=false;        boolean ismohu;        frame nowframe;        Thread ComputeThread=null;        public void start()        {          if(ComputeThread==null)          {              ComputeThread=new Thread(this,"Compute");              ComputeThread.start();          }        }        void analyze()        {            int i=0;            try{ComputeThread.sleep(1);}catch( InterruptedException e){}            while(!isend&&i<20)            {                try{ComputeThread.sleep(1);}catch( InterruptedException e){}            	try{                String m=findnext();                int te=nowframe.indexin.findindexnum(m);  	        	long bol=nowframe.indexin.wordblock[te].transpoint;  	        	nowframe.wordsin.getwordsblock(nowframe.words,bol);  	        	bol=nowframe.wordsin.findword(m);                //System.out.print(" "+m);                if(bol!=-1)                {                  //System.out.print(" "+m);                  nowframe.List1con.addElement(m);                  i++;                } }catch (IOException x){}            }            nowframe.ChooseList1.setListData(nowframe.List1con);        }        public void run()        {            isrunning=true;            Animate ani=new Animate();            ani.nowframe=nowframe;            ani.gook=true;            ani.aninum=0;            ani.start();            try{ComputeThread.sleep(1);}catch( InterruptedException e){}            //System.out.print(" "+s1);            if(ismohu==false)            {                nowframe.List1con.removeAllElements();            }            int i=0;            while(!isend&&i<20)            {            	try{ComputeThread.sleep(1);}catch( InterruptedException e){}                try{                String m=findnext();                int te=nowframe.indexin.findindexnum(m);  	        	long bol=nowframe.indexin.wordblock[te].transpoint;  	        	nowframe.wordsin.getwordsblock(nowframe.words,bol);  	        	bol=nowframe.wordsin.findword(m);                //System.out.print(" "+m);                if(bol!=-1)                {                  System.out.print(" "+m);                  nowframe.List1con.addElement(m);                  i++;                } }catch (IOException x){}            }            nowframe.ChooseList1.setListData(nowframe.List1con);            ani.gook=false;            isrunning=false;        }	int numofdelim;	String s1;	StringTokenizer s2;	char delim[];	boolean isend=false;	void Init()	{		int i=0;		s2=new StringTokenizer(s1,"?",true);		String temp;		int m=s2.countTokens();		int n=0;		for(i=0;i<m;i++)		{			temp=s2.nextToken();			if(temp.compareTo("?")==0)			{				n++;			}		}		numofdelim=n;                if(n==0)                {                    isend=true;                    return;                }		delim=new char[n];		for(i=0;i<n;i++)		{			delim[i]='a';		}		isend=false;	}	String findnext()	{		int i=numofdelim-1;		while((delim[i]=='z')&&i>0)		{			delim[i]='a';			i--;		}		if((delim[i]=='z')&&i==0)		{			isend=true;			return "";		}		delim[i]=nextchar(delim[i]);		return compound();	}	String compound()	{		s2=new StringTokenizer(s1,"?",true);		int i=0;		StringBuffer result=new StringBuffer();		String temp;		while(s2.hasMoreTokens())		{			temp=s2.nextToken();			if(temp.compareTo("?")==0)			{				result.append(delim[i]);				i++;			}			else			{				result.append(temp);			}		}		return result.toString();	}	static char nextchar(char x)	{		if(x>='a'&&x<'z')		{			int i=(int)x;			i++;			return (char)i;		}		return 0;	}}class Words{	char m_word[];	long transpoint;	int i=0;    void getword(String a)    {         Reset();         if(a.length()<=40)              a.getChars(0,a.length(),m_word,0);         else              a.getChars(0,40,m_word,0);        }	Words()	{		m_word=new char[40];		transpoint=0;	}	void Reset()	{		for(i=0;i<40;i++)			m_word[i]=0;		i=0;	}	public static String toString(Words i)	{		String rettemp;		int j=0;		while(i.m_word[j]!=0)			{j++;}		rettemp=new String(i.m_word,0,j);		return rettemp;	}}class WordsList{	Words wordblock[]=new Words[250];	WordsList()	{		int i=0;		for(i=0;i<250;i++)		{			wordblock[i]=new Words();		}	}    void Reset()    {        int i=0;		for(i=0;i<250;i++)		{			wordblock[i].Reset();		}    }	void getindex(RandomAccessFile index) throws IOException	{                //index.seek(0);		int i=0;		int j=0;		try		{		for(i=0;i<250;i++)		{			for(j=0;j<40;j++)			{				wordblock[i].m_word[j]=index.readChar();			}			wordblock[i].transpoint=index.readLong();		}		}catch(EOFException x){}	}	void setusers(RandomAccessFile users) throws IOException	{                users.seek(0);		int i=0;		int j=0;		try		{		for(i=0;i<250;i++)		{			for(j=0;j<40;j++)			{				users.writeChar(wordblock[i].m_word[j]);			}			users.writeLong(wordblock[i].transpoint);		}}catch(EOFException x){}	}	int findindexnum(String m)	{		int i=0;		int base=0;		int tlength=250;		while(tlength>1)		{			i=base+tlength/2;			if(m.compareToIgnoreCase(wordblock[i].toString(wordblock[i]))<0||wordblock[i].toString(wordblock[i]).equalsIgnoreCase(""))			{				tlength=tlength/2+1;				if(tlength==2)					tlength=1;				continue;			}			if(m.compareToIgnoreCase(wordblock[i].toString(wordblock[i]))==0)			{				break;			}			if(m.compareToIgnoreCase(wordblock[i].toString(wordblock[i]))>0)			{				base=i;				tlength=tlength/2+1;				continue;			}		}		if(m.compareToIgnoreCase(wordblock[i].toString(wordblock[i]))<0||wordblock[i].toString(wordblock[i]).equalsIgnoreCase(""))			i--;		return i;	}	long findword(String m)	{		int i=0;		int base=0;		int tlength=250;		while(tlength>1)		{			i=base+tlength/2;                        if(i>=250)                        {                          i=248;                          tlength=2;                        }			if(m.compareToIgnoreCase(wordblock[i].toString(wordblock[i]))<0||wordblock[i].toString(wordblock[i]).equalsIgnoreCase(""))			{				tlength=tlength/2+1;				if(tlength==2)					tlength=1;				continue;			}			if(m.compareToIgnoreCase(wordblock[i].toString(wordblock[i]))==0)			{				return wordblock[i].transpoint;			}			if(m.compareToIgnoreCase(wordblock[i].toString(wordblock[i]))>0)			{				base=i;				tlength=tlength/2+1;                                if(tlength==2)                                  tlength=1;				continue;			}		}        if(m.compareToIgnoreCase(wordblock[base].toString(wordblock[base]))==0)        {             return wordblock[base].transpoint;        }		return -1;	}	int findwordind(String m)	{		int i=0;		int base=0;		int tlength=250;		while(tlength>1)		{			i=base+tlength/2;                        if(i>=250)                        {                          i=248;                          tlength=2;                        }			if(m.compareToIgnoreCase(wordblock[i].toString(wordblock[i]))<0||wordblock[i].toString(wordblock[i]).equalsIgnoreCase(""))			{				tlength=tlength/2+1;				if(tlength==2)					tlength=1;				continue;			}			if(m.compareToIgnoreCase(wordblock[i].toString(wordblock[i]))==0)			{				return i;			}			if(m.compareToIgnoreCase(wordblock[i].toString(wordblock[i]))>0)			{				base=i;				tlength=tlength/2+1;                                if(tlength==2)                                  tlength=1;				continue;			}		}		if(m.compareToIgnoreCase(wordblock[i].toString(wordblock[i]))<0||wordblock[i].toString(wordblock[i]).equalsIgnoreCase(""))			i=i-1;		return i;	}	void getwordsblock(RandomAccessFile words,long ind) throws IOException	{                Reset();		words.seek(ind);		getindex(words);	}}class LongIndexBasic{	static RandomAccessFile longindex2;	long index[]=new long[40];	void setLongIndex() throws IOException	{		int i=0;		for(i=0;i<40;i++)		{			longindex2.writeLong(index[i]);		}	}	void getLongIndex() throws IOException	{		int i=0;		for(i=0;i<40;i++)		{			index[i]=longindex2.readLong();		}	}}class frame extends JFrame implements KeyListener{  JPanel contentPane;  PopupMenu popupMenu1 = new PopupMenu();  JTextField InputField = new JTextField();  JButton StartCheck = new JButton();  TextArea OutputArea = new TextArea();  Label InputLabel = new Label();	boolean showtrans(long te) throws IOException	{		if (te==-1)		{			OutputArea.setText("对不起,未找到");			return false;		}		StringBuffer my=new StringBuffer();		trans.seek(te);		char ap;		ap=trans.readChar();		while(ap!=0)		{			my.append(ap);			ap=trans.readChar();		}		OutputArea.setText(my.toString());		return true;	}	boolean showlist(int te) throws IOException	{		int i=0;		List1con.removeAllElements();		do		{			List1con.addElement(wordsin.wordblock[te+i].toString(wordsin.wordblock[te+i]));		//	ChooseList.add("good");			i++;		}while(i<21&&te+i<250);		if(i<21)		{			int j=0;			do			{				List1con.addElement(wordsinnext.wordblock[j].toString(wordsinnext.wordblock[j]));				j++;			}while(j<(21-i));		}                ChooseList1.setListData(List1con);		return true;	}  //Construct the frame  public frame() {    enableEvents(AWTEvent.WINDOW_EVENT_MASK);    try {      jbInit();    }    catch(Exception e) {      e.printStackTrace();    }  }  //Component initialization  	static RandomAccessFile index;	static RandomAccessFile words;	static RandomAccessFile trans;	static RandomAccessFile users;	static RandomAccessFile usertrans;//  static RandomAccessFile longindex;//  static RandomAccessFile index2;	static WordsList indexin=new WordsList();	static WordsList wordsin=new WordsList();	static WordsList wordsinnext=new WordsList();	static WordsList userwords=new WordsList();        static void addwords(String theword,String thetrans)        {            try {            int i=0;            while(userwords.wordblock[i].m_word[0]!=0&&i<250)            {                i++;            }            if(i==250)              i=0;            userwords.wordblock[i].getword(theword);            usertrans.seek(usertrans.length());            userwords.wordblock[i].transpoint=usertrans.getFilePointer();            usertrans.writeChars(thetrans);            usertrans.writeChar(0);}catch(IOException e){}        }  JButton think = new JButton();  JMenuBar jMenu = new JMenuBar();  JMenu jFile = new JMenu();  JMenuItem jInputDict = new JMenuItem();  JMenuItem ExitMenu = new JMenuItem();  JButton find = new JButton();  boolean iswordmodel=true;  JRadioButton jRadioButton1 = new JRadioButton();  JRadioButton jRadioButton2 = new JRadioButton();  JLabel Mico1 = new JLabel();  JLabel Animate = new JLabel();  Vector List1con=new Vector();  JList ChooseList1 = new JList(List1con);  JMenuItem jInputWords = new JMenuItem();  Image icon;  void loadfile(String s1) throws IOException  {  	try {    StringBuffer file=new StringBuffer(s1);

⌨️ 快捷键说明

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