//
/* ---------------------------------------------------------------------------------------------- logic.java 論理回路 ver. 1.01 (JDK 1.02) ueyama@infonet.co.jp 1999.08.31 update: 2008.01.02 ---------------------------------------------------------------------------------------------- */ import java.applet.*; import java.awt.*; public class logic extends Applet { int Dt[]={1,1,0,0,0,1,0,0}; // データ int Bx[]={95,95,95, 95,219,219,219,374}; // データ表示 X 座標 int By[]={14,59,83,111, 2, 59, 99, 71}; // データ表示 Y 座標 Image Img; AudioClip Ac; public void init() { String bg=getParameter("bgcolor"); // 背景色の読み込み int bgc=Integer.valueOf(bg,16).intValue(); setBackground(new Color(bgc)); MediaTracker mt=new MediaTracker(this); // 画像ファイルの読み込み Img=getImage(getCodeBase(), getParameter("figure")); mt.addImage(Img, 0); try { mt.waitForID(0); } catch(InterruptedException e){}; Ac=getAudioClip(getCodeBase(), getParameter("audioclip")); // ブザー音ファイルの読み込み } public boolean inside(int x, int a, int b) { return (x<=Math.max(a,b) && x>=Math.min(a,b)) ? true:false; } public void dsp_g(int x, int y, int m, int n, int c) // 図、文字の表示 { Graphics gx=getGraphics(); int w=0, h=0, ox=0, oy=0; switch(c) { case 0: w=248; h=120; ox= 0; oy= 0; break; // 回路図 case 1: w= 50; h= 11; ox=248; oy= 0; break; // エンジン, キー, ライト, ドア, ブザー case 2: w= 26; h= 11; ox=248; oy=55; break; // 停止/回転, 抜く/挿入, 消灯/点灯, 閉/開 case 3: w= 12; h= 16; ox=248; oy=99; break; // 0,1 (黒) case 4: w= 12; h= 16; ox=272; oy=99; break; // 0,1 (灰) } gx.clipRect(x,y,w,h); gx.clearRect(x,y,w,h); gx.drawImage(Img,x-(ox+m*w),y-(oy+n*h),this); gx.dispose(); } public void dsp_s() // データの表示 { int i; Dt[4]=(Dt[0]==0)?1:0; // エンジンの NOT 回路出力 Dt[5]=(Dt[1]+Dt[2]==0)? 0:1; // OR 回路出力 Dt[6]=Dt[3]; // ドア と同じデータ Dt[7]=(Dt[4]+Dt[5]+Dt[6]==3)? 1:0; // ブザー for(i=0;i<8;i++) dsp_g(Bx[i],By[i],Dt[i],0,(inside(i,4,6))?4:3); // データの表示 for(i=0;i<4;i++) dsp_g(60,By[i]+2,Dt[i],i,2); // 状態の表示 } public void paint(Graphics g) { int i; g.clearRect(0,0,size().width,size().height); dsp_g(113,0,0,0,0); // 回路図の表示 for(i=0;i<4;i++) dsp_g(0,By[i]+2,0,i,1); // 名称の表示 dsp_g(362,54,0,i,1); // "ブザー" の表示 dsp_s(); // データを表示 } public boolean mouseDown(Event e, int x, int y) { int i; if(x<130) { for(i=0;i<4;i++) if(inside(y,By[i]-2,By[i]+18)) Dt[i]=(Dt[i]==0)? 1:0; // データの反転 if(Dt[1]==0 && Dt[0]==1) Dt[0]=0; // キーを挿入しないとエンジンはかからない dsp_s(); // データを表示 if(Dt[7]==1) Ac.loop(); // ブザーを鳴らす else Ac.stop(); // ブザーを止める } return true; } } //戻る