NTTドコモ FOMA iアプリ版 日蒙簡易辞書
NTTドコモ FOMA iアプリ版 日蒙簡易辞書
package net.hinekure.ijmdic;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import javax.microedition.io.Connector;import com.nttdocomo.ui.Button;import com.nttdocomo.ui.Component;import com.nttdocomo.ui.ComponentListener;import com.nttdocomo.ui.Display;import com.nttdocomo.ui.IApplication;import com.nttdocomo.ui.Label;import com.nttdocomo.ui.Panel;import com.nttdocomo.ui.TextBox;public class Launcher extends IApplication {public void start() {TxtPanel myPanel;myPanel = new TxtPanel();Display.setCurrent(myPanel);}}class TxtPanel extends Panel {Label lblLabel;TextBox txtBox;Button btn;Label lblLabel2;TextBox txtBox2;// コンストラクタTxtPanel() {lblLabel = new Label("日蒙簡易辞書 Ver 1.00");lblLabel.setSize(240, 14);// テキストボックスのインスタンス生成txtBox = new TextBox("", 100, 1, TextBox.DISPLAY_ANY);txtBox2 = new TextBox("", 100, 10, TextBox.DISPLAY_ANY);// txtBox2.setEditable(false);btn = new Button("検索");btn.setSize(240, 20);lblLabel2 = new Label("");lblLabel2.setSize(240, 12);// コンポーネントの貼り付けthis.add(lblLabel);this.add(txtBox);this.add(btn);this.add(lblLabel2);this.add(txtBox2);// コンポーネントリスナーの設定this.setComponentListener(new ListenerObj(lblLabel2, txtBox, txtBox2,btn));}}class ListenerObj implements ComponentListener {private Label myLbl;private TextBox myTxt;private TextBox myTxt2;private Button myBtn;public ListenerObj(Label receLbl, TextBox recetxt, TextBox recetxt2,Button receBtl) {myLbl = receLbl;myTxt = recetxt;myTxt2 = recetxt2;myBtn = receBtl;}public void componentAction(Component c, int type, int param) {if ((c == myBtn) && (type == BUTTON_PRESSED)) {Search();}}private void Search() {InputStream is = null;com.nttdocomo.io.BufferedReader br = null;String out = null;out = "";String str;int result_num = 0;String keywords;keywords = myTxt.getText();myLbl.setText("");try {try {is = Connector.openInputStream("resource:///jmdic_sjis.txt");br = new com.nttdocomo.io.BufferedReader(new InputStreamReader(is));str = br.readLine();while ((str = br.readLine()) != null) {// キーワードに一致 もしくは 空欄の場合if ((str.indexOf(keywords) != -1) || (keywords == "")) {out += str + "\n";result_num++;myLbl.setText("" + result_num + "件見つけました!");}}} finally {if (br != null)br.close();}if (result_num == 0) {out = "検索ヒント:\n別の言い回しで検索すると出る場合があります。\n漢字をひらがなにしたり単漢字で検索しても出る可能性があります。";}} catch (IOException e) {out = "読み込みが失敗しました...";}myTxt2.setText(out);}}