//
/* ---------------------------------------------------------------------------------------------- isbn.java ISBN ver. 1.00 (JDK 1.02) ueyama@infonet.co.jp 2002.08.19 update: 2008.05.18 ---------------------------------------------------------------------------------------------- */ import java.applet.*; import java.awt.*; public class isbn extends Applet { int Bx=25, By=60; // ボタン表示 原点XY座標 int Ox[]={ 0, 0,40,80, 0,40,80, 0,40,80,80,125,125}; // ボタン表示 Xオフセット int Oy[]={90,60,60,60,30,30,30, 0, 0, 0,90, 90, 60}; // ボタン表示 Yオフセット boolean Md=true; // true: 新 ISBN false: 旧 ISBN String Isbn=(Md)?"978-":""; // ISBN文字列, 計算式 (ステータスバー表示用) int Sl=(Md)?4:0, Nq=0, Cs=0; // ISBN文字列 長さ,入力数字数, 検査数字 int Btn=-1; // クリックされたボタン No. Image Img; 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")); // gif ファイルの読み込み mt.addImage(Img, 0); try { mt.waitForID(0); } catch(InterruptedException e){}; } 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_p(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=14; h=18; ox= 0; oy= 0; break; // 数字 (ボタン用) case 1 : w=11; h=14; ox= 0; oy=18; break; // 数字 (ISBN 用) case 2 : w=36; h=26; ox= 0; oy=46; break; // ボタン case 3 : w=44; h=15; ox=132; oy=18; break; // "ISBN" case 4 : w=30; h=13; ox= 72; oy=46; break; // ラジオボタン(新・旧) } gx.clipRect(x,y,w,h); gx.drawImage(Img,x-(ox+m*w),y-(oy+n*h),this); gx.dispose(); } public void dsp_isbn() // ISBN 文字列の表示 { int i,n; Graphics gx=getGraphics(); gx.setColor(new Color(0xffffff)); // 表示領域のクリア gx.fillRect(1, 21, 229, 26); for(i=0; i戻る0) // "BS" キーが押された { if(!"-".equals(Isbn.substring(Sl-1,Sl))) Nq--; Isbn=Isbn.substring(0, Sl-1); Sl--; break; } default: if(inside(Btn, 0, 10) && Nq<9) // "0〜9,-" キーが押された { if(Btn==10) Isbn+="-"; // "-" キーが押された else Isbn+=""+Btn; // 数字 キーが押された if(Btn<10) Nq++; Sl++; } } dsp_isbn(); // ISBN の表示 dsp_p(Bx+Ox[Btn], By+Oy[Btn], (Btn<12)? 0:1, 0, 2); // ボタンの表示 dsp_p(Bx+Ox[Btn]+13, By+Oy[Btn]+5, Btn, 0, 0); // ボタンの数字をずらせて表示 chk_s(); if(Nq==9) // 9 桁入力終了 { dsp_p(Sl*13+6, 27, 11, 0, 1); // "-" の表示 dsp_p((Sl+1)*13+6, 27, Cs, 1, 1); // 検査数字の表示 } } if(x>195 && y>150) // ラジオボタンをクリック { Md=(inside(y, 150, 163))? true: false; Isbn=(Md)?"978-":""; Sl=(Md)?4:0; Nq=0; // 初期化 repaint(); // 再描画 } return true; } public boolean mouseUp(Event e, int x, int y) // マウスボタンが離されたときの処理 { if(inside(Btn, 0, 13)) { dsp_p(Bx+Ox[Btn], By+Oy[Btn], (Btn<12)? 0:1, 0, 2); // ボタンの数字を元に戻す dsp_p(Bx+Ox[Btn]+12, By+Oy[Btn]+4, Btn, 0, 0); } return true; } } //