📄 dictionary.java
字号:
/* * Dictionary.java * * Created on 2007-7-4, 18:45:51 * * To change this template, choose Tools | Templates * and open the template in the editor. */package dyno.swing.beans;import java.io.IOException;import java.io.InputStream;import java.util.HashMap;import java.util.logging.Level;import java.util.logging.Logger;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.parsers.ParserConfigurationException;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.NodeList;import org.xml.sax.SAXException;/** * * @author William Chen */public class Dictionary extends HashMap<String, String> { private static Dictionary instance; static { loadDict(); } private static void loadDict() { try { instance = new dyno.swing.beans.Dictionary(); InputStream input = Dictionary.class.getResourceAsStream("dictionary.xml"); Document root = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(input); Element rootElement = root.getDocumentElement(); NodeList list = rootElement.getElementsByTagName("word"); if (list != null) { for (int i = 0; i < list.getLength(); i++) { Element wordElement = (org.w3c.dom.Element) list.item(i); String english = wordElement.getAttribute("english"); String chinese = wordElement.getAttribute("chinese"); instance.put(english, chinese); } } } catch (ParserConfigurationException ex) { Logger.getLogger("global").log(Level.SEVERE, null, ex); } catch (SAXException ex) { Logger.getLogger("global").log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger("global").log(Level.SEVERE, null, ex); } } public static Dictionary getInstance() { return instance; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -