?? jsapplet.java
字號:
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("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區(qū)域
add(searchTLa);
add(searchPa);
searchPa.add(containingLa);
searchPa.add(containingTf);
searchPa.add(keyLogicLa);
searchPa.add(findNowBu);
searchPa.add(stopBu);
searchPa.add(newSearchBu);
//加入RESULTS區(qū)域
add(resultTLa);
add(titleLa);
add(urlLa);
add(resultLi);
//加入PREVIEW-STATUS-MESSAGES區(qū)域
//PREVIEW
add(previewTLa);
add(previewTe);
//STATUS
add(statusTLa);
add(statusLi);
//MESSAGES
add(messageTLa);
add(messageTe);
//加入ENGINES&OPTIONS&ABOUT區(qū)域
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
//設(shè)置按鈕狀態(tài)
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()));
//選中相應(yīng)類別的搜索引擎
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(); //必須要單獨(dú)創(chuàng)建對象,否則無法加入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;
}
//按鈕狀態(tài)設(shè)定
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) { //之所以不再以外掛文件方式來增加支持語種,是因?yàn)橥鈷煳募L,會增加下載時間,若您有興趣可以在以下自行加入 ;-)
case 0: //English
//設(shè)置總計
totalLa.setText("Total:");
//設(shè)置SEARCH區(qū)域
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");
//設(shè)置RESULTS區(qū)域
resultTLa.setText("RESULTS");
titleLa.setText("Title");
urlLa.setText("URL");
//設(shè)置PREVIEW-STATUS-MESSAGES區(qū)域
previewTLa.setText(">>PREVIEW");
statusTLa.setText(">>STATUS");
messageTLa.setText(">>MESSAGES");
//設(shè)置ENGINES&OPTIONS&ABOUT區(qū)域
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
//設(shè)置總計
totalLa.setText("總計:");
//設(shè)置SEARCH區(qū)域
searchTLa.setText("搜 索");
containingLa.setText("查詢內(nèi)容:");
keyLogicLa.setText("搜索條件依所選搜索引擎而定。");
findNowBu.setLabel("開始搜索");
stopBu.setLabel("停止搜索");
newSearchBu.setLabel("新建搜索");
//設(shè)置RESULTS區(qū)域
resultTLa.setText("結(jié) 果");
titleLa.setText("主題");
urlLa.setText("位置");
//設(shè)置PREVIEW-STATUS-MESSAGES區(qū)域
previewTLa.setText(">>預(yù) 覽");
statusTLa.setText(">>狀 態(tài)");
messageTLa.setText(">>消 息");
//設(shè)置ENGINES&OPTIONS&ABOUT區(qū)域
enginesCb.setLabel("引 擎");
categoryLa.setText("類別");
searchEnginesLa.setText("搜索引擎");
optionsCb.setLabel("選 項(xiàng)");
smcLa.setText("搜索最大連接數(shù):");
smlLa.setText("搜索最大層次:");
smsLa.setText("搜索最大速度:");
valurlLa.setText("網(wǎng)址有效性驗(yàn)證:");
languageLa.setText("語言:");
webBrowLa.setText("網(wǎng)絡(luò)瀏覽器種類:");
webBrowPLa.setText("網(wǎng)絡(luò)瀏覽器路徑:");
aboutCb.setLabel("關(guān) 于");
copyingLa.setText("許可協(xié)議");
creditsLa.setText("謝啟");
break;
}
}
//PREVIEW-STATUS-MESSAGES的顯示狀態(tài)切換
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的顯示狀態(tài)切換
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();
}
/*****與搜索/驗(yàn)證有關(guān)的方法*****/
//開始搜索
void startSearch() {
try {
if ((!(containingTf.getText().trim().equals(""))) && (searchEnginesLi.getSelectedIndexes().length != 0)) {
//清除原先的顯示
clearAll();
//設(shè)置按鈕狀態(tài)
buttonStatus(1);
//切換PSM
switchPSM(false, true, false);
//開始搜索
_stop = false;
//取得所選的搜索引擎
String enginesSelected[] = searchEnginesLi.getSelectedItems();
//選中的搜索引擎數(shù)
int enginesSelectedCount = enginesSelected.length;
//OPTIONS中充許的最多引擎數(shù)
int searchMaxConnections = Integer.valueOf(smcCh.getSelectedItem()).intValue();
//確定實(shí)際應(yīng)打開的線程數(shù)
actualSearchAllowed =(enginesSelectedCount<searchMaxConnections)?(enginesSelectedCount):(searchMaxConnections);
//定義線程數(shù)組并初始化
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();
//準(zhǔn)備搜索線程
srchThread[srchNo] = new SearchThread(srchChainConverted, engDtl.srchBlkB, engDtl.srchBlkE, engDtl.name, srchNo);
//在STATUS中加入信息
statusLi.add("Starting Search From " + engDtl.name + " ...");
//如果已經(jīng)達(dá)到了實(shí)際的搜索數(shù),就退出。
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() {
//先只設(shè)stopBu為false,等搜索線程全部停止后,通過buttonStatus(2)全面設(shè)置。
stopBu.setEnabled(false);
//關(guān)閉搜索線程
_stop = true;
}
//新建搜索
void newSearch() {
//清除原先的顯示
clearAll();
}
//析構(gòu)函數(shù)
public void finalize() throws Throwable {
super.finalize();
System.gc();
System.runFinalization();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -