一
二
public Hashtable(int initialCapacity
public Hashtable(int initialCapacity)
public Hashtable()
在本文的實例中
Hashtable stockInfo = new Hashtable();
public int size();
//返回散列表中的結點數目
public boolean isEmpty();
//判斷散列表是否為空
public boolean containsValue(Object value);
//判斷散列表中是否含有某值
public synchronized boolean containsKey(Object key);
//判斷散列表中是否含有某個結點
public synchronized void clear();
//清空整個散列表
三
public StringTokenizer(String str
String delim
public StringTokenizer(String str
public StringTokenizer(String str);
其中
Tokens描述是否將定界符作為一個token
public boolean hasMoreTokens() ;
//判斷字符串中是否還有token
public String nextToken();//
StringTokenizer對象的下一個token
四
import java
import java
import java
import java
import java
public class StockQuote extends Applet
implements ActionListener
{
private static final File INFO_FILE =
new File(
private Hashtable stockInfo;
TextField stockID;
Button button
private String quoteid
public void init()
{
add(new Label(
stockID = new TextField(
add(stockID);
button
button
add(button
resize(
}
public void start()
{
loadinfo();
}
protected boolean loadinfo()
{
String fileLine;
StringTokenizer tokenize;
String id;
StringBuffer name;
try {
// 創建一個訪問數據文件的stream
BufferedReader stockInput = new
BufferedReader(new FileReader(INFO_FILE));
// 創建Hashtable對象
stockInfo = new Hashtable();
// 每次從文件中讀一行數據
while ((fileLine = stockInput
// 將每一行數據分解為tokens
tokenize = new StringTokenizer(fileLine);
try {
id = tokenize
// 創建一個放置股票信息的buffer
name = new StringBuffer();
while(tokenize
name
if (tokenize
name
}
}
// 向Hashtable中充填記錄
stockInfo
} catch(NullPointerException excpt) {
System
} catch(NoSuchElementException excpt) {
System
}
}
stockInput
} catch(FileNotFoundException excpt) {
System
return false;
} catch(IOException excpt) {
System
return false;
}
return true;
}
protected String getQuote(String StockID)
{
String info;
// 從Hashtable得到數據
info = (String)stockInfo
if (info != null)
return info;
else
return
}
public void paint(Graphics g)
{
g
g
+
g
}
public void actionPerformed(ActionEvent ev)
{
String label = ev
if (label
{
quoteid = stockID
if(quoteid != null)
quotename = getQuote(quoteid);
else quotename =
repaint();
}
}
}
d:\jdk
From:http://tw.wingwit.com/Article/program/Java/Javascript/201311/25401.html