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

📄 jsapplet.java

📁 jSearch - turns search Engines into FIND engines - Programming in JAVA Copyright (C) 1999-2009 Hun
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		smsCh.setBounds(158,66,50,20);
		for (int c=1;c<=10;c++) smsCh.addItem(String.valueOf(c));
		smsCh.select(getParameter("smsCh"));
		valurlLa.setBounds(8,86,140,20);
		valurlCh.setBounds(158,86,50,20);
		valurlCh.addItem("Yes");
		valurlCh.addItem("No");
		valurlCh.select(getParameter("valurlCh"));
		languageLa.setBounds(8,146,80,20);
		languageCh.setBounds(118,146,90,20);
		languageCh.addItem("English");
		languageCh.addItem("Chinese");
		languageCh.select(getParameter("languageCh"));
		webBrowLa.setBounds(8,166,110,20);
		webBrowCh.setBounds(118,166,90,20);
		webBrowCh.addItem("IE (Windows)");
		webBrowCh.addItem("NS (Windows)");
		webBrowCh.addItem("NS (Linux)");
		webBrowCh.addItem("Other browsers");
		webBrowCh.select(getParameter("webBrowCh"));
		webBrowPLa.setBounds(8,186,110,20);
		webBrowPTf.setBounds(118,186,90,20);
		webBrowPTf.setBackground(Color.white);
		webBrowPTf.setText(getParameter("webBrowPTf"));
		//ABOUT		
		aboutCb.setBounds(686,116,65,20);
		aboutCb.setFont(tabStyleFo);
		aboutCb.setForeground(Color.yellow);
		aboutCb.setBackground(new Color(25600));
		aboutPa.setBackground(Color.cyan);
		copyingLa.setBounds(8,6,80,15);
		copyingLa.setAlignment(Label.CENTER);
		copyingLa.setBackground(new Color(6724095));
		copyingTe.setBounds(8,21,200,120);
		copyingTe.setFont(littleFo);
		copyingTe.setBackground(Color.white);
		copyingTe.setEditable(false);
		creditsLa.setBounds(8,146,80,15);
		creditsLa.setAlignment(Label.CENTER);
		creditsLa.setBackground(new Color(6724095));
		creditsTe.setBounds(8,161,200,95);
		creditsTe.setFont(littleFo);
		creditsTe.setBackground(Color.white);
		creditsTe.setEditable(false);
			
		/*****加入控件*****/

		//加入总计
		add(totalLa);
		add(totalNumLa);
			
		//加入SEARCH区域
		add(searchTLa);
		add(searchPa);
		searchPa.add(containingLa);
		searchPa.add(containingTf);
		searchPa.add(keyLogicLa);
		searchPa.add(findNowBu);
		searchPa.add(stopBu);
		searchPa.add(newSearchBu);
			
		//加入RESULTS区域
		add(resultTLa);
		add(titleLa);
		add(urlLa);
		add(resultLi);
			
		//加入PREVIEW-STATUS-MESSAGES区域
		//PREVIEW
		add(previewTLa);
		add(previewTe);
		//STATUS
		add(statusTLa);
		add(statusLi);
		//MESSAGES
		add(messageTLa);
		add(messageTe);
			
		//加入ENGINES&OPTIONS&ABOUT区域
		add(eoaCards);
		//ENGINES
		add(enginesCb);
		eoaCards.add("engines", enginesPa);
		enginesPa.add(categoryLa);
		enginesPa.add(categoryLi);
		enginesPa.add(searchEnginesLa);
		enginesPa.add(searchEnginesLi);
		//OPTIONS
		add(optionsCb);
		eoaCards.add("options", optionsPa);
		optionsPa.add(smcLa);
		optionsPa.add(smcCh);
		optionsPa.add(smlLa);
		optionsPa.add(smlCh);
		optionsPa.add(smsLa);
		optionsPa.add(smsCh);
		optionsPa.add(valurlLa);
		optionsPa.add(valurlCh);
		optionsPa.add(languageLa);
		optionsPa.add(languageCh);
		optionsPa.add(webBrowLa);
		optionsPa.add(webBrowCh);
		optionsPa.add(webBrowPLa);
		optionsPa.add(webBrowPTf);
		//ABOUT
		add(aboutCb);
		eoaCards.add("about", aboutPa);
		aboutPa.add(copyingLa);
		aboutPa.add(copyingTe);
		aboutPa.add(creditsLa);
		aboutPa.add(creditsTe);
			
		//setLayout to BorderLayout
		setLayout(new BorderLayout());
		searchPa.setLayout(new BorderLayout());
		enginesPa.setLayout(new BorderLayout());
		optionsPa.setLayout(new BorderLayout());
		aboutPa.setLayout(new BorderLayout());
		
		//SEARCH
		//设置按钮状态
		buttonStatus(2);
		
		//PREVIEW-STATUS-MESSAGES
		switchPSM(false, false, true);

		//在MESSAGES中加入信息
		messageTe.append(
			"JSearch version 2.0.0.0 [huntlin@public.xm.fj.cn], Copyright (C) 1999-2002 Hunt Lin\n" +
			"JSearch comes with ABSOLUTELY NO WARRANTY; for details see COPYING.\n" +
			"This is free software, and you are welcome to redistribute it\n" +
			"under certain conditions; see COPYING for details.\n"
		);
		
		//ENGINES&OPTIONS&ABOUT
		//ENGINES
		//加入搜索引擎类别信息
		for (Enumeration e = engDataCateg.elements(); e.hasMoreElements();)
			categoryLi.add((String)(e.nextElement()));
		//选中相应类别的搜索引擎
		categoryLi.select(1);
		categorySelect();

		//OPTIONS
		//改变语言
		changeLanguage(languageCh.getSelectedIndex());

		//ABOUT
		//决定是否读入*.txt,读入*.txt需要一定时间。
		if (getParameter("_readTxt").equals("Yes")) {
			copyingTe.append(getTxtFile("COPYING.TXT"));
			creditsTe.append(getTxtFile("CREDITS.TXT"));
		} else {
			copyingTe.append(getParameter("currUrl") + "COPYING.TXT" + "\n");
			creditsTe.append(getParameter("currUrl") + "CREDITS.TXT" + "\n");
		}
		
	}
	
	//从输入文件JSENGINES.TXT中整理出搜索引擎的信息
	Hashtable getEngData() {
		Hashtable 	engDataHt = new Hashtable();	//临时存入搜索引擎信息的HashTable,用于返回值。
		String 		engDataHtHead;
		String 		inLine[] = new String[6];
		try {
			BufferedReader engDataIn = new BufferedReader(new InputStreamReader((new URL(getParameter("currUrl") + "JSENGINES.TXT")).openStream()));
			while ((engDataHtHead = engDataIn.readLine()) != null) {
				for (int i=0;i<5;i++) inLine[i] = engDataIn.readLine();
				engDataIn.readLine();
				EnginesDetails engDataHtBody = new EnginesDetails();  //必须要单独创建对象,否则无法加入Hashtable中!!
				engDataHtBody.name      = inLine[0];
				engDataHtBody.category  = inLine[1];
				engDataHtBody.srchChain = inLine[2];
				engDataHtBody.srchBlkB  = inLine[3];
				engDataHtBody.srchBlkE  = inLine[4];
				engDataHt.put(engDataHtHead, engDataHtBody);
			}
			engDataIn.close();
		} catch(Exception ex) {
			messageTe.append("Exception: '" + ex.toString() + "' in JSApplet.getEngData().\n");
		}
		return engDataHt;
	} 
	
	//从输入文件JSENGINES.TXT中整理出搜索引擎的类别(间接通过getEngData()取得。)
	Vector getEngCateg(Hashtable engData) {
		Vector engCategory = new Vector();	//临时存入搜索引擎类别信息的Vector,用于返回值。
		String eleAdd;
		for (Enumeration e = engData.elements(); e.hasMoreElements();) {
			eleAdd = ((EnginesDetails)(e.nextElement())).category;
			if (!engCategory.contains(eleAdd)) engCategory.addElement(eleAdd);
		}
		return engCategory;
	}
	
	//从TXT文件中读出信息并生成字符串
	String getTxtFile(String txtFileName) {
		String retString	= "";	//临时变量
		String txtFileLine	= "";	//临时变量
		try {
			BufferedReader txtFileIn = new BufferedReader(new InputStreamReader((new URL(getParameter("currUrl") + txtFileName)).openStream()));
			while ((txtFileLine = txtFileIn.readLine()) != null) {
				retString += (txtFileLine + "\n");
			}
			txtFileIn.close();
		} catch (Exception ex) {
			messageTe.append("Exception: '" + ex.toString() + "' in JSApplet.getTxtFile().\n");
		}
		return retString;
	}
	
	//按钮状态设定
	static void buttonStatus(int Status) {
		switch (Status) {
		case 1: //按下findNowBu
			containingTf.setEnabled(false);
			findNowBu.setEnabled(false);
			stopBu.setEnabled(true);
			newSearchBu.setEnabled(false);
			break;
		case 2: //按下stopBu
			containingTf.setEnabled(true);
			findNowBu.setEnabled(true);
			stopBu.setEnabled(false);
			newSearchBu.setEnabled(true);
			break;
		}
	}
	
	//搜索引擎类别选择
	void categorySelect() {
		EnginesDetails	eleAdd;
		int				index = 0;
		searchEnginesLi.removeAll();
		for (Enumeration en = engDataTable.elements(); en.hasMoreElements();) {
			eleAdd = (EnginesDetails)(en.nextElement());
			if ((eleAdd.category).equals(categoryLi.getSelectedItem())) {
				searchEnginesLi.add(eleAdd.name);
				if (index < Integer.valueOf(smcCh.getSelectedItem()).intValue()) searchEnginesLi.select(index++);
			}
		}
	}
	
	//改变语言
	void changeLanguage(int languageIndex) {
		switch (languageIndex) { //之所以不再以外挂文件方式来增加支持语种,是因为外挂文件太长,会增加下载时间,若您有兴趣可以在以下自行加入 ;-)
		case 0: //English
			//设置总计
			totalLa.setText("Total:");

			//设置SEARCH区域
			searchTLa.setText("SEARCH");
			containingLa.setText("Containing:");
			keyLogicLa.setText("Keyword logic depends on selected search engines.");
			findNowBu.setLabel("Find Now");
			stopBu.setLabel("Stop Search");
			newSearchBu.setLabel("New Search");
			
			//设置RESULTS区域
			resultTLa.setText("RESULTS");
			titleLa.setText("Title");
			urlLa.setText("URL");
			
			//设置PREVIEW-STATUS-MESSAGES区域
			previewTLa.setText(">>PREVIEW");
			statusTLa.setText(">>STATUS");
			messageTLa.setText(">>MESSAGES");
			
			//设置ENGINES&OPTIONS&ABOUT区域
			enginesCb.setLabel("ENGINES");
			categoryLa.setText("Category");
			searchEnginesLa.setText("Search Engines");
			optionsCb.setLabel("OPTIONS");
			smcLa.setText("Search max connections:");
			smlLa.setText("Search max level:");
			smsLa.setText("Search max speed:");
			valurlLa.setText("Validate URL:");
			languageLa.setText("Language:");
			webBrowLa.setText("Web browser type:");
			webBrowPLa.setText("Web browser path:");
			aboutCb.setLabel("ABOUT");
			copyingLa.setText("COPYING");
			creditsLa.setText("CREDITS");
			break;
	  case 1: //Chinese
			//设置总计
			totalLa.setText("总计:");
			
			//设置SEARCH区域
			searchTLa.setText("搜  索");
			containingLa.setText("查询内容:");
			keyLogicLa.setText("搜索条件依所选搜索引擎而定。");
			findNowBu.setLabel("开始搜索");
			stopBu.setLabel("停止搜索");
			newSearchBu.setLabel("新建搜索");
			
			//设置RESULTS区域
			resultTLa.setText("结  果");
			titleLa.setText("主题");
			urlLa.setText("位置");
			
			//设置PREVIEW-STATUS-MESSAGES区域
			previewTLa.setText(">>预  览");
			statusTLa.setText(">>状  态");
			messageTLa.setText(">>消  息");
			
			//设置ENGINES&OPTIONS&ABOUT区域
			enginesCb.setLabel("引  擎");
			categoryLa.setText("类别");
			searchEnginesLa.setText("搜索引擎");
			optionsCb.setLabel("选  项");
			smcLa.setText("搜索最大连接数:");
			smlLa.setText("搜索最大层次:");
			smsLa.setText("搜索最大速度:");
			valurlLa.setText("网址有效性验证:");
			languageLa.setText("语言:");
			webBrowLa.setText("网络浏览器种类:");
			webBrowPLa.setText("网络浏览器路径:");
			aboutCb.setLabel("关  于");
			copyingLa.setText("许可协议");
			creditsLa.setText("谢启");
			break;
		}
	}
	
	//PREVIEW-STATUS-MESSAGES的显示状态切换
	void switchPSM(boolean p, boolean s, boolean m) {
		previewTLa.setBackground(new Color(p?3355647:25600));
		statusTLa.setBackground(new Color(s?3355647:25600));
		messageTLa.setBackground(new Color(m?3355647:25600));

		previewTe.setVisible(p);
		statusLi.setVisible(s);
		messageTe.setVisible(m);
	}
	
	//ENGINES&OPTIONS&ABOUT的显示状态切换
	void switchEOA(boolean e, boolean o, boolean a) {
		enginesCb.setBackground(new Color(e?3355647:25600));
		optionsCb.setBackground(new Color(o?3355647:25600));
		aboutCb.setBackground(new Color(a?3355647:25600));
	}
	
	//清除所有显示
	void clearAll() {
		//总计
		totalNumLa.setText("0");
		
		//PSM
		previewTe.setText("");
		statusLi.removeAll();
		messageTe.setText("");
		
		//RESULTS
		resultLi.removeAll();
		resultTable.clear();
		resultIndex.removeAllElements();
	}
	
	/*****与搜索/验证有关的方法*****/
	
	//开始搜索
	void startSearch() {
		try {
			if ((!(containingTf.getText().trim().equals(""))) && (searchEnginesLi.getSelectedIndexes().length != 0)) {
				//清除原先的显示
				clearAll();
				//设置按钮状态
				buttonStatus(1);
				//切换PSM
				switchPSM(false, true, false);
				//开始搜索
				_stop = false;
				
				//取得所选的搜索引擎
				String enginesSelected[] = searchEnginesLi.getSelectedItems();
				//选中的搜索引擎数
				int enginesSelectedCount = enginesSelected.length;
				//OPTIONS中充许的最多引擎数
				int searchMaxConnections = Integer.valueOf(smcCh.getSelectedItem()).intValue();
				//确定实际应打开的线程数
				actualSearchAllowed =(enginesSelectedCount<searchMaxConnections)?(enginesSelectedCount):(searchMaxConnections);
				//定义线程数组并初始化
				SearchThread	srchThread[] = new SearchThread[actualSearchAllowed];
				
				EnginesDetails engDtl;				//搜索引擎信息
				String srchChainConverted = "";		//存入变换后的搜索串
				char singleChar[] = new char[1];	//每次取得的字符
				int srchNo = 0;						//搜索线程号
				
				for (Enumeration en = engDataTable.elements(); en.hasMoreElements();) {
					engDtl = (EnginesDetails)(en.nextElement());
					if ((engDtl.name).equals(enginesSelected[srchNo])) {
						
						//将srchChain中的"^"置换成待搜索的字串
						srchChainConverted = "";
						StringReader strIn = new StringReader(engDtl.srchChain);
						while (strIn.read(singleChar,0,1) != -1) {
							if (singleChar[0] == '^') {
								srchChainConverted += URLEncoder.encode(containingTf.getText().trim());
							} else {
								srchChainConverted += singleChar[0];
							}
						}
						strIn.close();
						
						//准备搜索线程
						srchThread[srchNo] = new SearchThread(srchChainConverted, engDtl.srchBlkB, engDtl.srchBlkE, engDtl.name, srchNo);
						
						//在STATUS中加入信息
						statusLi.add("Starting Search From " + engDtl.name + " ...");
						
						//如果已经达到了实际的搜索数,就退出。
						if (++srchNo >= actualSearchAllowed) break;
					}
				}
				
				//开始搜索
				for (srchNo = 0; srchNo < actualSearchAllowed; srchNo ++) {
					//启动搜索线程
					srchThread[srchNo].start();
				}
				
			} else {
				messageTe.append("Search Starting Failed.\n");
			}
		} catch(Exception ex) {
			messageTe.append("Exception: '" + ex.toString() + "' in JSApplet.startSearch().\n");
		}
	}
	
	//停止搜索
	void stopSearch() {
		//先只设stopBu为false,等搜索线程全部停止后,通过buttonStatus(2)全面设置。
		stopBu.setEnabled(false);
		//关闭搜索线程
		_stop = true;
	}
  
	//新建搜索
	void newSearch() {
		//清除原先的显示
		clearAll();
	}
	
	//析构函数
	public void finalize() throws Throwable {
		super.finalize();
		System.gc();
		System.runFinalization();
	}
}

⌨️ 快捷键说明

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