Choiceコンポーネントと2次元配列を利用したDOS/V情報の表示


2つのChoiceボックスから,知りたい情報を選択すると,TextFieldに表示する。
(2次元配列の利用)
Java Appletです

ソースコード

import java.applet.*;
import java.awt.*;

public class ja50a extends Applet
{
  int si = 0;   		//Choice shopのIndex番号
  int sdi = 0;  		//Choice shopdataのIndex番号
  Choice shop = new Choice();
  Choice shopdata = new Choice();
  Label la_tf = new Label("ここに情報を表示します",0);
  TextField tf = new TextField(30);
  String data[][] = {   	//TextAreaに表示するデータを2次元配列で設定
    {"PC総合","06-634-4132","不定期","11:00-20:00"},
    {"PC総合","06-634-1211","水曜日","不明"},
    {"PC総合","06-647-2038","木曜日","10:30-19:30"},
    {"PC総合","06-635-5525","第1・3水曜日","不明"},
    {"パーツ中心","不明","第2木曜日","11:00-19:00"},
    {"ソフト専門","不明","第1・2水曜日","11:00-20:00"},
    {"パーツ専門","06-645-6720","年中無休","10:30-19:30"}
  };

  public void init(){
    Label la = new Label("ショップ名と知りたいショップ情報を選択して下さい",0);
    la.setFont(new Font("TimesRoman",Font.BOLD,14));
    Label la_shop = new Label("ショップ名  ",2);
    Label la_shopdata = new Label("ショップ情報  ",2);

    shop.addItem("ソフマップ7号店");      	//[ショップ名]に項目を追加
    shop.addItem("J&Pテクノランド(上新電気)");
    shop.addItem("ニノミヤNinox Pc Town");
    shop.addItem("T-ZONEマルチメディア館");
    shop.addItem("TWO-TOP大阪本店");
    shop.addItem("ヤマギワソフト");
    shop.addItem("DOS/Vパラダイス");

    shopdata.addItem("種別");   	//[ショップ情報]に項目を追加
    shopdata.addItem("電話番号");
    shopdata.addItem("定休日");
    shopdata.addItem("営業時間");

    setLayout(null);  	//レイアウトマネージャーを使わず,以下各コンポーネントをreshape()で配置
    add(la);
    la.reshape(10,5,350,15);
    add(la_shop);
    la_shop.reshape(20,33,80,15);
    add(shop);
    shop.reshape(105,30,150,20);
    add(la_shopdata);
    la_shopdata.reshape(270,33,100,15);
    add(shopdata);
    shopdata.reshape(375,30,80,20);
    add(la_tf);
    la_tf.reshape(20,60,300,20);
    add(tf);
    tf.reshape(30,80,200,20);
  }

  public boolean action(Event e,Object o){
    if(e.target.equals(shop)){     	//[ショップ名]選択Boxで選択された場合
      si = shop.getSelectedIndex();   	//選択された項目のIndex番号を取得
      tf.setText(data[si][sdi]);      	//TextAreaに2次元配列dataのデータを表示する
      la_tf.setText(shop.getSelectedItem() + "の情報は"); //ラベルも変更
    }else if(e.target.equals(shopdata)){  //[ショップ情報]選択Boxで選択された場合
      sdi = shopdata.getSelectedIndex();
      tf.setText(data[si][sdi]);
    }
    return true;
  }
}

末尾