/***********************************************************************************/ /** **/ /** Java Chat applet **/ /** source file : Chat_12.java **/ /** classes : Chat_12.class **/ /** Comthread_12.class **/ /** Optionwindow_12.class **/ /** Boardcanvas_12.class **/ /** window size : 600 x 380 or larger **/ /** working : Javaチャット アプレット **/ /** (日本語対応Java簡易チャット) **/ /** param : "title" = タイトル テキスト **/ /** "numbers" = チャンネル数 **/ /** "default" = 初期選択チャンネル **/ /** "page0" = チャンネル0情報 **/ /** | | **/ /** "pagen" = チャンネルn情報 **/ /** (情報:名称,データファイル,cgiファイル ) **/ /** host file : by param **/ /** host CGI : by param **/ /** **/ /** 1997/09/17 ver1.0 created by H.Machida **/ /** 1998/06/27 ver1.1 updated by H.Machida **/ /** 1998/07/15 ver1.2 updated by H.Machida **/ /** **/ /** Copyright (c) 1997-98 Hiroyuki Machida. All Rights Reserved. **/ /** **/ /***********************************************************************************/ import java.awt.*; import java.util.*; import java.net.*; import java.io.*; public class Chat_12 extends java.applet.Applet implements Runnable { /********** instance valiable **********/ Comthread_12 com; // 通信スレッド Optionwindow_12 window; // オプション ウインドウ Boardcanvas_12 canvas; // ボードキャンバス Thread thread; // スレッド Button reload; // ボタン("RELOAD") Button stop; // ボタン("STOP") Button option; // ボタン("OPTION") Button submit; // ボタン("SUBMIT") TextArea textarea; // テキストエリア(掲示板) TextField name; // テキストフィールド(name) TextField comment; // テキストフィールド(comment) Choice page; // ポップアップメニュー(page) Label addto; // ラベル(addto) boolean reload_f; // "RELOAD"押下フラグ boolean submit_f; // "SUBMIT"押下フラグ String title; // 掲示板タイトル int numbers; // 掲示板ページ数 int actpage; // 選択ページ String page_name[]; // ページ名称(配列) String host_file[]; // host data file (配列) String host_cgi[]; // host CGI file (配列) int commode = 2; // 通信モード int dispmode = 1; // 表示(ソート)モード int timer; // リロードタイマ int reloadtime = 15; // リロード時間設定値 String lastdata = ""; // 直前までの発言データ int columns = 78; // カラム数(自動改行文字数) final String TITLE = "JAVA CHAT 1.2"; // default title /********** init **********/ public void init() { getparam(); // >> アプレットタグのparam情報を取得 // オプションウインドウを初期化 window = new Optionwindow_12("JAVA CHAT Option Window", this); // ボードキャンバスを初期化 canvas = new Boardcanvas_12(title); textarea = new TextArea(); // テキストエリア(掲示板)を設定 textarea.setEditable(false); textarea.setFont(new Font("Dialog", Font.PLAIN, 14)); textarea.setBackground(Color.white); name = new TextField(16); // テキストフィールド(name)を設定 name.setEditable(true); name.setFont(new Font("Dialog", Font.PLAIN, 14)); name.setBackground(Color.white); comment = new TextField(); // テキストフィールド(comment)を設定 comment.setEditable(true); comment.setFont(new Font("Dialog", Font.PLAIN, 14)); comment.setBackground(Color.white); reload = new Button("RELOAD"); // "RELOAD"ボタンを設定 reload.setBackground(Color.lightGray); stop = new Button("STOP"); // "STOP"ボタンを設定 stop.setBackground(Color.lightGray); option = new Button("OPTION"); // "OPTION"ボタンを設定 option.setBackground(Color.lightGray); submit = new Button("SUBMIT"); // "SUBMIT"ボタンを設定 submit.setBackground(Color.lightGray); page = new Choice(); // ポップアップメニュー(page)を初期化 page.setFont(new Font("Dialog", Font.PLAIN, 14)); page.setBackground(Color.lightGray); for (int i = 0 ; i < numbers ; i++) { page.addItem(page_name[i]); // (メニュー項目追加) } page.select(actpage); // (メニュー初期選択項目を指定) addto = new Label(); // ラベル(addto)を設定 addto.setFont(new Font("Dialog", Font.PLAIN, 14)); addto.setForeground(Color.red); setlayout(); // >> アプレット内のUIレイアウトを設定 setBackground(Color.pink); // アプレットの背景色を設定 reload_f = false; // "RELOAD"押下フラグ初期化 submit_f = false; // "SUBMIT"押下フラグ初期化 hostselect(); // >> ホストファイルを選択 com_control(0); // >> ホストファイルのデータを読み出す timer = 0; // リロードタイマを初期化 } /********** insets **********/ public Insets insets() { // インセットを設定 return new Insets(8,8,8,8); } /********** start **********/ public void start() { thread = new Thread(this); thread.start(); timer = 0; // リロードタイマを初期化 } /********** stop **********/ public void stop() { thread.stop(); thread = null; if (com != null) { com.stop(); com = null; } name.setText(""); // テキストフィールド(name)をクリア comment.setText(""); // テキストフィールド(comment)をクリア window.hide(); // オプションウインドウを隠す } /********** paint **********/ public void paint(Graphics scr) { scr.clearRect(0,0, size().width,size().height); // アプレット領域をクリア } /********** run **********/ public void run() { while( true ) { // ----- ベースレベル ----- try { Thread.currentThread().sleep(100);} // 100msスリープ catch (InterruptedException e) {}; if (reload_f == true) { reload_work(); // >> "RELOAD"ボタン対応処理 reload_f = false; } if (submit_f == true) { if (commode == 2) { // (通信中は待ち合わせする) submit_work(); // >> "SUBMIT"ボタン対応処理 submit_f = false; } } auto_reload(); // >> 自動リロード処理 com_watch(); // >> 通信監視(ステータス表示) } } /********** keyDown **********/ public boolean keyDown(Event evt, int key) { if (evt.target instanceof TextField) { // テキストフィールド内キーダウン ? if (key == '\n' || key == '\r') { // 改行キー ? if (evt.target == name) { // nameエリア ? comment.requestFocus(); // commentエリアへの入力フォーカスを要求 return true; } else if (evt.target == comment) { // commentエリア ? submit_f = true; // SUBMITした事にする return true; } } } return false; } /********** action **********/ public boolean action(Event evt, Object o) { if (evt.target instanceof Button) { // ボタン アクション ? if ("RELOAD".equals(o)) { // "RELOAD"ボタン押下か ? reload_f = true; return true; } if ("SUBMIT".equals(o)) { // "SUBMIT"ボタン押下か ? submit_f = true; return true; } if ("STOP".equals(o)) { // "STOP"ボタン押下か ? com_control(2); // >> ホストとの通信をストップする return true; } if ("OPTION".equals(o)) { // "OPTION"ボタン押下か ? window.resize(460,280); // オプションウインドウのサイズを設定 window.move(200,150); // オプションウインドウの位置を設定 window.show(); // オプションウインドウを画面に表示 window.requestFocus(); // オプションウインドウのフォーカスを要求 return true; } } if (evt.target instanceof Choice) { // ポップアップメニュー アクション ? if (evt.target == page) { // ポップアップメニュー = page ? reload_f = true; // (pageが再選択されたら再読込を行う) return true; } } return false; } /********** method reload_work **********/ void reload_work() { // "RELOAD"ボタン対応処理 hostselect(); // >> ホストファイルを選択 com_control(0); // >> ホストファイルのデータを読み出す } /********** method submit_work **********/ void submit_work() { // "SUBMIT"ボタン対応処理 page.select(actpage); // 選択ページのリスト項目を選択 if (host_cgi[actpage] != null) { // 選択ページ = 書き込み対応 ? String str1 = name.getText(); // name入力データ String str2 = comment.getText(); // comment入力データ if (str1.equals("")) { // 入力データ = 無し ? canvas.disp_status("Please input your name!"); // 通信ステータスを表示 name.requestFocus(); // nameエリアへの入力フォーカスを要求 } else if (str2.equals("")) { canvas.disp_status("Please input your comment!"); // 通信ステータスを表示 comment.requestFocus(); // commentエリアへの入力フォーカスを要求 } else { com_control(1); // >> ホストファイルにデータを書き出す(CGI経由) comment.requestFocus(); // commentエリアへの入力フォーカスを要求 } } else { canvas.disp_status("This page is read only!"); // 通信ステータスを表示 } } /********** method auto_reload **********/ void auto_reload() { // 自動リロード処理 if (commode == 2 && reloadtime < 100) { // 通信待機かつリロード時間設定有ならば timer++; if (timer >= reloadtime * 10) { com_control(0); // >> ホストファイルのデータを読み出す timer = 0; } } else { timer = 0; } } /********** method getparam **********/ void getparam() { // アプレットタグのparam情報を取得する String param = null; param = getParameter("title"); // 掲示板タイトルを読み出す if (param == null) param = TITLE; title = param; param = getParameter("numbers"); // 掲示板ページ数を読み出す if (param == null) param = "1"; numbers = Integer.valueOf(param).intValue(); param = getParameter("default"); // 初期選択ページを読み出す if (param == null) param = "0"; actpage = Integer.valueOf(param).intValue(); page_name = new String[numbers]; // 各種ページ情報[配列]を初期化 host_file = new String[numbers]; host_cgi = new String[numbers]; for (int i = 0 ; i < numbers ; i++) { // ページ数分のページ情報を全て読み出す page_name[i] = "CH " + i; host_file[i] = "chat1-" + i + ".dat"; host_cgi[i] = null; param = getParameter("page" + i); if (param != null) { StringTokenizer st = new StringTokenizer(param, ","); if (st.hasMoreTokens()) { page_name[i] = st.nextToken(); // (ページ名) } if (st.hasMoreTokens()) { host_file[i] = st.nextToken(); // (データファイル名) } if (st.hasMoreTokens()) { host_cgi[i] = st.nextToken(); // (CGIファイル名) } } } } /********** method setlayout **********/ void setlayout() { // アプレット内のUIレイアウトを設定する setLayout(new BorderLayout()); // アプレットのレイアウトを設定 Panel panel0 = new Panel(); // パネル0を設定 ---------------- panel0 panel0.setLayout(new BorderLayout()); panel0.setBackground(Color.yellow); Panel sp0 = new Panel(); // sp0パネル(サブパネル)を設定 sp0.setLayout(new FlowLayout()); sp0.setFont(new Font("Dialog", Font.PLAIN, 14)); sp0.setBackground(Color.cyan); sp0.add(page); // ポップアップメニュー(page)を追加 sp0.add(reload); // ボタン(reload)を追加 sp0.add(stop); // ボタン(reload)を追加 sp0.add(option); // ボタン(reload)を追加 panel0.add("West",canvas); // パネル0左部にcanvasを追加 panel0.add("East",sp0); // パネル0右部にsp0パネルを追加 Panel panel2 = new Panel(); // パネル2を設定 ---------------- panel2 panel2.setLayout(new BorderLayout(5,0)); panel2.setFont(new Font("Dialog", Font.PLAIN, 14)); panel2.setBackground(Color.lightGray); Panel sp2 = new Panel(); // sp2パネル(サブパネル)を設定 sp2.setLayout(new BorderLayout()); sp2.setBackground(Color.lightGray); Panel ssp21 = new Panel(); // ssp21パネル(サブサブパネル)を設定 ssp21.setLayout(new FlowLayout(FlowLayout.LEFT, 0,3)); ssp21.add(new Label("Your Name")); // ラベル(タイトル)を追加 ssp21.add(name); // テキストフィールド(name)を追加 ssp21.add(addto); // ラベル(addto)を追加 Panel ssp22 = new Panel(); // ssp22パネル(サブサブパネル)を設定 ssp22.setLayout(new BorderLayout()); ssp22.add("West", new Label("Comment")); // ラベル(タイトル)を追加 ssp22.add("Center", comment); // テキストフィールド(comment)を追加 sp2.add("North", ssp21); // sp2パネル上部にssp21パネルを追加 sp2.add("South", ssp22); // sp2パネル下部にssp22パネルを追加 panel2.add("Center", sp2); // パネル2中央部にsp2パネルを追加 panel2.add("East", submit); // パネル2右部にボタン(submit)を追加 add("North", panel0); // アプレット上部にパネル0を追加 add("Center", textarea); // アプレット中部にテキストエリア(掲示板)を追加 add("South", panel2); // アプレット下部にパネル2を追加 } /********** method hostselect **********/ void hostselect() { // ポップアップメニューよりホストファイルを選択する int i = page.getSelectedIndex(); // ポップアップメニューの選択項目を抽出 actpage = i; // 選択ページを設定 if (host_cgi[i] != null) { // ラベル(addto)を設定 addto.setText(" ... Add to " + page_name[i] + " "); } else { addto.setText(" ... Read only " + page_name[i]); } } /********** com_control **********/ void com_control(int cont) { // 通信スレッドの起動制御を行う switch (cont) { case 0: // ホスト上のデータファイルを読み出す if (commode == 2) { // 通信モード = 停止中 ? // (通信スレッド初期化) com = new Comthread_12("receive", this, host_file[actpage]); com.start(); // (通信スレッド開始) commode = 0; // 通信モード = 受信 canvas.disp_status("Now reading..."); // 通信ステータスを表示 } break; case 1: // ホスト上のデータファイルに書き込む if (commode == 2) { // 通信モード = 停止中 ? // (通信スレッド初期化) com = new Comthread_12("transmit", this, host_cgi[actpage]); com.start(); // (通信スレッド開始) commode = 1; // 通信モード = 送信 canvas.disp_status("Now writing..."); // 通信ステータスを表示 } break; case 2: // 通信キャンセル if (com != null) { com.stop(); // (通信スレッド停止) com = null; } commode = 2; // 通信モード = 停止 canvas.disp_status(""); // 通信ステータスを表示 break; } } /********** com_watch **********/ void com_watch() { // 通信スレッドの監視を行う if (com != null && com.isAlive() == true) { // 通信スレッド = 動作中の場合 ..... if (com.getName().equals("receive")) { canvas.disp_status("Now reading..."); // 通信ステータスを表示 } else { canvas.disp_status("Now writing..."); // 通信ステータスを表示 } } else { // 通信スレッド = 停止中の場合 ..... switch (commode) { case 0: // 通信モード = 受信 ? canvas.disp_status(""); // 通信ステータスをクリア commode = 2; // (通信モード = 停止) break; case 1: // 通信モード = 送信 ? comment.setText(""); // テキストフィールド(comment)をクリア commode = 2; // (通信モード = 停止) com_control(0); // >> 通信スレッドを再度起動する(受信) break; } } } /********** set_data **********/ void set_data(String str) { // 通信スレッドとのアクセスメソッド if (str.equals(lastdata) == false) { // 発言データ更新 ? textarea.setText(insert_LF(str)); // テキストエリアに自動改行付きデータをセットする textarea.insertText("----------\n", 0); // テキストエリア先頭にトップラインを挿入する // (トップラインは、Netscape時の対策) lastdata = str; // lastdata更新 } } /********** insert_LF **********/ String insert_LF(String str) { // カラム数毎に改行を挿入(長文自動改行) // (Latin-1は1文字、他は2文字で計算) int cols = 0; String st =""; for (int i = 0 ; i < str.length() ; i++) { st += str.charAt(i); if (str.charAt(i) == '\n') { cols = 0; } else { if (str.charAt(i) > '\u007F') cols++; cols++; if (cols >= columns) { st += "\n"; cols = 0; } } } return st; } /********** get_data **********/ String get_data() { // 通信スレッドとのアクセスメソッド return name.getText() + " : " + comment.getText() + "\n"; // (入力データをリターンする) } /********** set_reloadtime **********/ void set_reloadtime(int sec) { // オプションウインドウとのアクセスメソッド reloadtime = sec; // (リロード時間設定値を設定) } /********** set_textfont **********/ void set_font(String name, int style, int size) { // オプションウインドウとのアクセスメソッド textarea.setFont(new Font(name, style, size)); // (テキストエリアの表示フォントを設定) } /********** set_columns **********/ void set_columns(int cols){ // オプションウインドウとのアクセスメソッド columns = cols; // テキストエリアのカラム数を設定 String str = insert_LF(lastdata); // カラム数毎に改行を挿入(長文自動改行) textarea.setText(str); // (テキストエリアにデータをセットする) textarea.insertText("----------\n", 0); // (テキストエリア先頭にトップラインを挿入する) } /********** get_columns **********/ int get_columns() { // オプションウインドウとのアクセスメソッド return columns; // テキストエリアのカラム数をリターン } } /************************************************************************************/ /** **/ /** class Comthread_12 **/ /** **/ /************************************************************************************/ // スレッドクラスから通信スレッドクラスを作成 class Comthread_12 extends Thread { /********** instance **********/ Chat_12 parent; // 親アプレット String theurl; // ホストファイル名 /********** construtor **********/ public Comthread_12(String name, Chat_12 target, String strurl) { super(name); parent = target; theurl = strurl; } /********** run **********/ public void run() { if (this.getName().equals("receive")) { receive(); // >> ホスト上のデータファイルを読み出す } if (this.getName().equals("transmit")) { transmit(); // >> ホスト上のデータファイルに書き出す } } /********** method receive **********/ void receive() { // ホスト上のデータファイルを読み出す StringBuffer strbuf = new StringBuffer(""); try { URL host; // URLを作成 host = new URL(parent.getDocumentBase(), theurl); URLConnection urlc; // URLConnectionを作成 urlc = host.openConnection(); urlc.setDoInput(true); // 入力許可 urlc.setUseCaches(false); // キャッシュ無効 DataInputStream dis; // 入力ストリームを作成 dis = new DataInputStream(urlc.getInputStream()); char rd_data; // ストリームからデータを入力 [Unicode Chars] String data = ""; while ((rd_data = dis.readChar()) != '\f') { if (rd_data == '\u0000') rd_data='?'; // (無効文字の\u0000を'?'に置換) if (rd_data == '\r') { data = data + '\n'; // (\rを\nに置換してまとめる) } else { data = data + rd_data; // (1件分データにまとめる) } if (rd_data == '\n') { // 1件分データ区切り記号の'\n'か ? data = data + "\n"; // (データに空白行を付加) if (parent.dispmode == 0) { // 表示モードによりソート strbuf.append(data); // (昇順) } else { strbuf.insert(0,data); // (降順) } data = ""; } } System.out.println("Chat -- Data input end by \f"); dis.close(); // ストリームを閉じる } catch (MalformedURLException murle) { System.out.println("Chat -- MalformedURLException [Receive] " + murle); } catch (IOException ioe) { System.out.println("Chat -- " + ioe + " (Data input completed)"); } parent.set_data(strbuf.toString()); // (テキストエリアに読出データをセットする) } /********** method transmit **********/ void transmit() { // ホスト上のデータファイルに書き出す(CGI経由) try { URL host; // URLを作成 host = new URL(parent.getDocumentBase(), theurl); URLConnection connection; // URLConnectionを作成 connection = host.openConnection(); connection.setDoInput(true); // 入力許可 connection.setDoOutput(true); // 出力許可 connection.setUseCaches(false); // キャッシュ無効 DataOutputStream outstream; // 出力ストリームを作成 outstream = new DataOutputStream(connection.getOutputStream()); outstream.writeChars(parent.get_data()); // ストリームにデータを出力 [Unicode String] outstream.close(); // 出力ストリームを閉じる DataInputStream instream; // 入力ストリームを作成 instream = new DataInputStream(connection.getInputStream()); String readdata; // ストリームからデータを入力 [Ascii Lines] while ((readdata = instream.readLine()) != null) { // (入力データの処理はしない) } instream.close(); // 入力ストリームを閉じる } catch (MalformedURLException murle) { System.out.println("Chat -- MalformedURLException [Transmit] " + murle); } catch (IOException ioe) { System.out.println("Chat -- IOException [Transmit] " + ioe); } } } /************************************************************************************/ /** **/ /** class Optionwindow_12 **/ /** **/ /************************************************************************************/ // フレームクラスからオプションウインドウクラスを作成 class Optionwindow_12 extends Frame { /********** instance **********/ Chat_12 parent; // 親アプレット CheckboxGroup reload; // チェックボックスグループ TextField column; // テキストフィールド Button set; // ボタン Choice fontname; // ポップアップメニュー Choice fontstyle; // ポップアップメニュー Choice fontsize; // ポップアップメニュー Button ok; // ボタン final String VERSION_E = // 各バージョン情報テキスト " JAVA CHAT ver1.2 "; final String VERSION_J = " \u65E5\u672c\u8A9E\u5BFE\u5FDCJAVA\u30C1\u30E3\u30C3\u30C8 ver1.2 "; final String COPYRIGHT = " Copyright (c) 1997-98 Hiroyuki Machida "; final String INFORMATION = " http://village.infoweb.ne.jp/~fwbc6098/java/ "; /********** constructor **********/ public Optionwindow_12(String title, Chat_12 target) { super(title); parent = target; init(); pack(); } /********** init **********/ public void init() { setLayout(new BorderLayout()); // ウインドウのレイアウトを設定 setFont(new Font("Dialog", Font.PLAIN, 14)); setBackground(Color.lightGray); reload = new CheckboxGroup(); // チェックボックスグループを初期化 fontname = new Choice(); // ポップアップメニューを初期化 fontname.setBackground(Color.lightGray); fontname.addItem("Dialog"); fontname.addItem("Helvetica"); fontname.addItem("TimesRoman"); fontname.addItem("Courier"); fontname.addItem("DialogInput"); fontname.select("Dialog"); fontstyle = new Choice(); // ポップアップメニューを初期化 fontstyle.setBackground(Color.lightGray); fontstyle.addItem("Plain"); fontstyle.addItem("Bold"); fontstyle.addItem("Italic"); fontstyle.addItem("Bold + Italic"); fontstyle.select("Plain"); fontsize = new Choice(); // ポップアップメニューを初期化 fontsize.setBackground(Color.lightGray); fontsize.addItem("12"); fontsize.addItem("14"); fontsize.addItem("16"); fontsize.addItem("18"); fontsize.addItem("20"); fontsize.select("14"); column = new TextField("78",4); // テキストフィールドを初期化 column.setBackground(Color.white); set = new Button("SET"); // ボタンを初期化("SET"ボタン) set.setBackground(Color.lightGray); ok = new Button(" OK "); // ボタンを初期化(" OK "ボタン) ok.setBackground(Color.lightGray); Panel p0 = new Panel(); // 上部パネルを設定 p0.setBackground(Color.lightGray); p0.setLayout(new GridLayout(3,0)); Panel sp0 = new Panel(); // (サブパネルを設定) sp0.setLayout(new FlowLayout(FlowLayout.LEFT)); sp0.add(new Label("Reload time")); sp0.add(new Checkbox("5s", reload, false)); sp0.add(new Checkbox("10s", reload, false)); sp0.add(new Checkbox("15s", reload, true)); sp0.add(new Checkbox("20s", reload, false)); sp0.add(new Checkbox("30s", reload, false)); sp0.add(new Checkbox("OFF", reload, false)); Panel sp1 = new Panel(); // (サブパネルを設定) sp1.setLayout(new FlowLayout(FlowLayout.LEFT)); sp1.add(new Label("Columns (Auto Line Feed)")); sp1.add(column); sp1.add(set); sp1.add(new Label("[40...400]")); Panel sp2 = new Panel(); // (サブパネルを設定) sp2.setLayout(new FlowLayout(FlowLayout.LEFT)); sp2.add(new Label("Board Font")); sp2.add(fontname); sp2.add(fontstyle); sp2.add(fontsize); p0.add(sp0); p0.add(sp1); p0.add(sp2); Panel p1 = new Panel(); // 中部パネルを設定 p1.setBackground(new Color(0xFF,0xEF,0xB0)); p1.setLayout(new GridLayout(4,0)); p1.add(new Label(VERSION_E, Label.CENTER)); p1.add(new Label(VERSION_J, Label.CENTER)); p1.add(new Label(COPYRIGHT, Label.CENTER)); p1.add(new Label(INFORMATION, Label.CENTER)); Panel p2 = new Panel(); // 下部パネルを設定 p2.setBackground(Color.lightGray); p2.setLayout(new FlowLayout()); p2.add(ok); add("North", p0); // 各パネルをウインドウに追加 add("Center", p1); add("South", p2); } /********** action **********/ public boolean action(Event e, Object o) { if (e.target instanceof Button) { // ボタン アクション if ("SET".equals(o)) { // "SET"ボタン押下か ? set_columns(); // (テキストエリアのカラム数を設定する) return true; } if (" OK ".equals(o)) { // " OK "ボタン押下か ? hide(); // オプションウインドウを隠す return true; } } if (e.target instanceof Choice) { // ポップアップメニュー アクション String fn = fontname.getSelectedItem(); // (テキストエリアの表示フォントを変更する) String ft = fontstyle.getSelectedItem(); String fs = fontsize.getSelectedItem(); int ftv; if (ft.equals("Plain")) { ftv = Font.PLAIN; } else if (ft.equals("Bold")) { ftv = Font.BOLD; } else if (ft.equals("Italic")) { ftv = Font.ITALIC; } else { ftv = Font.BOLD + Font.ITALIC; } int fsv = Integer.valueOf(fs).intValue(); parent.set_font(fn, ftv, fsv); return true; } if (e.target instanceof Checkbox) { // チェックボックス(グループ) アクション String rt = (reload.getCurrent()).getLabel(); if ("5s".equals(rt)) { // (リロード時間設定値を変更する) parent.set_reloadtime(5); } else if ("10s".equals(rt)) { parent.set_reloadtime(10); } else if ("15s".equals(rt)) { parent.set_reloadtime(15); } else if ("20s".equals(rt)) { parent.set_reloadtime(20); } else if ("30s".equals(rt)) { parent.set_reloadtime(30); } else if ("OFF".equals(rt)) { parent.set_reloadtime(999); } return true; } if (e.target instanceof TextField) { // テキストフィールド アクション set_columns(); // (テキストエリアのカラム数を設定する) return true; } return false; } /********** handleEvent **********/ public boolean handleEvent(Event evt) { if (evt.id == Event.WINDOW_DESTROY) { // ウインドウ閉じるか ? hide(); // オプションウインドウを隠す return true; } return super.handleEvent(evt); // (他のイベントアクションを有効にする) } /********** set_columns **********/ void set_columns() { // テキストフィールド上のデータを取得し、 // テキストエリアのカラム数を設定する int cols; try { // (例外チェック開始) cols = Integer.valueOf(column.getText()).intValue(); if (cols > 400) cols = 400; if (cols < 40) cols = 40; parent.set_columns(cols); } catch (Exception e) { // (例外対応処理) } column.setText("" + parent.get_columns()); // (テキストフィールドにカラム数設定値を再表示) } } /************************************************************************************/ /** **/ /** class Boardcanvas_12 **/ /** **/ /************************************************************************************/ // キャンバスクラスからボードキャンバスを作成 class Boardcanvas_12 extends Canvas { /********** instance **********/ String title; // タイトル String status; // ステータス // タイトルフォントとステータスフォント(定数) final Font TF = new Font("Dialog", Font.BOLD, 14); final Font SF = new Font("Helvetica", Font.ITALIC, 14); /********** constructor **********/ public Boardcanvas_12(String str) { super(); resize(250,33); title = str; status = ""; } /********** paint **********/ public void paint(Graphics g) { g.setColor(Color.black); // タイトルを表示 g.setFont(TF); g.drawString(title, 5,14); g.setColor(Color.blue); // ステータスを表示 g.setFont(SF); g.drawString(status, 45,30); } /********** disp_status **********/ void disp_status(String str) { // 親アプレットとのアクセスメソッド status = str; repaint(); } }