// // exText1 2001/12/01 by ONOZATO Takehisa // // サンプル:テキストフィールド(最大公約数の計算) // // // import java.awt.*; import java.applet.*; import java.awt.event.*; public class exText1 extends Applet implements ActionListener{ Image ofs; Graphics grf; //オフスクリーン int ofsWidth=400; int ofsHeight=300; Color ofsBG=new Color(255,255,255); //背景色(白) TextField tf[]=new TextField[2]; //テキストフィールド int tfLeft[]={100,100}; int tfTop[]={50,80}; int tfWidth=80; int tfHeight=20; Button btn[]=new Button[2]; //ボタン int btnLeft[]={220,220}; int btnTop[]={50,80}; int btnWidth=80; int btnHeight=20; String btnCaption[]={"計算","クリア"}; String btnAction[]={"0","1"}; int btnIndex; //押されたボタン Font fnt; String fntName; int fntStyle; //フォント int fntSize=16; String str; //表示する文字列 int strLeft=50; int strTop=150; boolean flgError; //エラー public void init() { ofs=createImage(ofsWidth,ofsHeight); grf=ofs.getGraphics(); for(int i=0; ip){p=Math.abs(qq); q=Math.abs(pp);} //絶対値の小さくない方をpとする if(p==0){return r;} //ともに0ならば1を返す if(q==0){return p;} //一方が0ならば他方の絶対値を返す while(r!=0){r = p % q; p = q; q = r;} //互除法 return p; } }