< F2D82518CC282CC D2E6A7464>

Similar documents
< F2D82B682E182F182AF82F12E6A7464>

< F2D825282CC947B909482CC A815B83682E6A>

< F2D92DE82E8914B82CC977088D32E6A7464>

< F2D F B834E2E6A7464>

< F2D B838A835882CC8CF68EAE2E6A7464>

< F2D834F838C A815B A CC>

< F2D89BA8EE882C E6A7464>

< F2D82518E9F8AD CC834F CC8CFC82AB82C68D4C>

< F2D8EA CE909482CC92EA82852E6A7464>

< F2D A839382CC906A2E6A7464>

< F2D82518E9F8AD CC95BD8D7388DA93AE2E6A7464>

< F2D A838B838D96402E6A7464>

< F2D E E6A7464>

< F2D BCA82CC978E89BA82CC8EC08CB12E6A7464>

< F2D B825082CC96E291E82E6A7464>

Microsoft PowerPoint - OOP.pptx


Java言語 第1回

Microsoft PowerPoint prog1_doc2x.pptx

Local variable x y i paint public class Sample extends Applet { public void paint( Graphics gc ) { int x, y;... int i=10 ; while ( i < 100 ) {... i +=

try catch Exception Java try catch try { } catch ( Exception e ) { } e 16-1 try catch 0 try { int x = 0; int y = 10 / x; } catch ( Exception e ) { Sys

アプレットの作成

Safari AppletViewer Web HTML Netscape Web Web 15-1 Applet Web Applet init Web paint Web start Web HTML stop destroy update init Web paint start Web up

Chapter 20. [ ] ; [ ] = new [ ] ; Color colors [ ] = new Color[ 20 ]; // 20 Button operations [ ] = new Button[ 10 ]; // 10 colors[ 3 ] = new Color( 1

text_13.dvi

untitled

ガイダンス

アプレットⅤ

ガイダンス

ガイダンス

ガイダンス

Microsoft PowerPoint prog1_doc2.pptx

Applet java.lang.object java.awt.component java.awt.container java.awt.panel java.applet.applet

表示の更新もそういた作業のひとつに当たる スレッドの使用アニメーション アニメーションやシミュレーションなどは画面の更新が一定のタイミングで行われていく この連続した画面の更新をスレッドを利用して行う しかし paint() メソッドを直接呼び出して表示を更新することはできない その理由

ガイダンス

KeyListener init addkeylistener addactionlistener addkeylistener addkeylistener( this ); this.addkeylistener( this ); KeyListener public void keytyped

2

Microsoft PowerPoint - prog11.ppt

text_12.dvi

I. (i) Java? (A). 2Apples (B). Vitamin-C (C). Peach21 (D). Pine_Apple (ii) Java? (A). Java (B). Java (C). Java (D). JavaScript Java JavaScript Java (i

Microsoft PowerPoint - prog11.ppt

IE6 2 BMI chapter1 Java 6 chapter2 Java 7 chapter3 for if 8 chapter4 : BMI 9 chapter5 Java GUI 10 chapter6 11 chapter7 BMI 12 chap

GUIプログラムⅣ

Java言語 第1回

Java言語 第1回

教材ドットコムオリジナル教材 0から始めるiアフ リ リファレンス i アプリ簡易リファレンス ver i アプリ Java 独自のメソッド (1)iアプリの命令を使えるようにする import com.nttdocomo.ui.*; (2) 乱数を使う import java.u

Microsoft PowerPoint ppt

問題1 以下に示すプログラムは、次の処理をするプログラムである

Thread

r2.dvi

GUIプログラムⅤ

r3.dvi

Taro-korattsu.jtd

Java演習(4) -- 変数と型 --

Prog1_12th

2

Assignment_.java /////////////////////////////////////////////////////////////////////// // 課題 星の画像がマウスカーソルを追従するコードを作成しなさい 次 ///////////////////

Microsoft PowerPoint - prog10.ppt

I HTML HashMap (i) (ii) :.java import java.net.*; import java.io.*; import java.util.hashmap; public class SimpleStopWatch { public static voi

6 p.1 6 Java GUI GUI paintcomponent GUI mouseclicked, keypressed, actionperformed mouseclicked paintcomponent thread, 1 GUI 6.0.2, mutlithread C

問1

Color.cyan, Color.yellow, Color.pink, Color.orange, Color.white, Color.black, Color.gray, Color.darkGray, Color.lightGray ; Button barray [ ] = new Bu

Microsoft PowerPoint - prog10.ppt


PowerPoint Presentation

2 p.2 2 Java Hello0.class JVM Hello0 java > java Hello0.class Hello World! javac Java JVM java JVM : Java > javac 2> Q Foo.java Java : Q B

( ) p.1 x y y = ( x ) 1 γ γ = filtergamma.java import java.applet.*; public class filtergamma extends Applet{ Image img; Image new_img; publi

Prog2_11th

vol.30.}...`.X...b.h

Microsoft PowerPoint - prog12.ppt

2008 e-learning T050050

I. java.awt.rectangle java.lang.math random Java TM API java.awt Rectangle Rectangle (x,y)... public int x Rectangle X public int y Rectangle Y public

PowerPoint Presentation

問題1 以下に示すプログラムは、次の処理をするプログラムである

II Java :30 12:00 I. I IV II. III. IV. ( a d) V. : this==null, T == N A ActionListener C class D actionperformed G getsource I implements K

Object MenuComponent MenuBar MenuItem Menu CheckboxMenuItem

Java演習(2) -- 簡単なプログラム --

Prog1_12th

I. (i) Foo public (A). javac Foo.java java Foo.class (C). javac Foo java Foo (ii)? (B). javac Foo.java java Foo (D). javac Foo java Foo.class (A). Jav

2 p.2 2 Java Hello0.class JVM Hello0 java > java Hello0.class Hello World! javac Java JVM java JVM : Java > javac 2> Q Foo.java Java : Q B

r4.dvi

awt の主要なクラスを下記に示す クラス Component Container Button Label Panel Frame 説明画面にユーザインターフェイス要素として表示し, ユーザとのやり取りを行うコンポーネントを表すすべてのコンポーネントのスーパークラスになる ほかのコンポーネントを含

JAVA入門

アプレットⅣ

226

Java 2 p.2 2 Java Hello0.class JVM Hello0 java > java Hello0.class Hello World! javac Java JVM java JVM : Java > javac 2> Q Foo.java Java : Q 2.

次の演習課題(1),(2)のプログラムを完成させよ

ÿþ˜u#u·0¹0Æ0à0

2 p.2 2 Java Hello0.class JVM Hello0 java > java Hello0.class Hello World! javac Java JVM java JVM : Java > javac 2> Q Foo.java Java : Q B

(Microsoft PowerPoint - \223\306\217KJAVA\221\346\202R\224\ ppt)

19 3!! (+) (>) (++) (+=) for while 3.1!! (20, 20) (1)(Blocks1.java) import javax.swing.japplet; import java.awt.graphics;

public class Kadai _02 { public static void main(string[] args) { MyFrame frame = new MyFrame("Kadai _02"); (2) フレームのクラス名は MyFrame とし 以下

2 static final int DO NOTHING ON CLOSE static final int HIDE ON CLOSE static final int DISPOSE ON CLOSE static final int EXIT ON CLOSE void setvisible

r6.dvi

PowerPoint プレゼンテーション

新・明解Java入門

Microsoft PowerPoint - prog13.ppt

<4D F736F F F696E74202D AC C8899E D834F E >

Microsoft PowerPoint - prog13.ppt

Java演習(9) -- クラスとメソッド --

Transcription:

2 個のさいころ 1. はじめに [Java アプレット ] [Java アプリケーション ] 2 個のさいころを同時に投げたときの目の出方を考えてみましょう この 2 個のさいころをそれぞれ さいころ Ⅰ さいころ Ⅱ とすると その目の出方は順に 1 1 2 1 3 1 4 1 5 1 6 1 1 2 2 2 3 2 4 2 5 2 6 2 1 3 2 3 3 3 4 3 5 3 6 3 1 4 2 4 3 4 4 4 5 4 6 4 1 5 2 5 3 5 4 5 5 5 6 5 1 6 2 6 3 6 4 6 5 6 6 6 以上 36 通りあります ここで さいころⅠの目とさいころⅡの目の積が奇数になる場合を考えてみると 1 1 3 1 5 1 1 3 3 3 5 3 1 5 3 5 5 5の9 通りになります つまり さいころⅠの目とさいころⅡの目の積が奇数になる確率は 数学的には 9/36 約分して1/4 になります しかし 実際には 2 個のさいころを同時に投げることを4 回行なったら 目の積が奇数になる場合がちょうど1 回だけ起こるとは限りませんね では 数学的に求めた理論上の確率の 1/4 との関係はどうなっているんでしょうか シミュレーションソフト 2 個のさいころ を使って 2 個のさいころを投げたときの目の出方を観察してみてください 2.Java アプレット (1) Java プログラムリスト //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // // 2 個のさいころ Copyright ( C) K.Niwa 2001.12.20 // // // ( アプレット ) // // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -23-

/****** クラスの読み込み *****************************************************************/ import java.applet.applet; //java.applet パッケージから Applet クラスを読み込む import java.awt.*; //java.awt パッケージから全てのクラスを読み込む import java.awt.event.*; //java.awt.event パッケージから全てのクラスを読み込む import java.lang.math; //java.lang パッケージから.Math クラスを読み込む /****** public class Saikoro2 extends Applet implements Runnable *********************************/ public class Saikoro2 extends Applet implements Runnable { // スレッドを使えるようにする Thread myth; // スレッド型として宣言する Button[] mybtn; // ボタン型として宣言する Panel mypanel; // パネル型として宣言する int imgno; // 整数型として宣言する Image[] img; MediaTracker mymt; // イメージ型として宣言する // メディアトラッカー型として宣言する int flag=0; // 整数型として宣言し初期化する int r1=1,r2=1; int ct1; // 乱数 // 実験回数 long t; // 時間かせぎ int d11=0,d21=0,d31=0,d41=0,d51=0,d61=0; int d12=0,d22=0,d32=0,d42=0,d52=0,d62=0; int d13=0,d23=0,d33=0,d43=0,d53=0,d63=0; int d14=0,d24=0,d34=0,d44=0,d54=0,d64=0; int d15=0,d25=0,d35=0,d45=0,d55=0,d65=0; int d16=0,d26=0,d36=0,d46=0,d56=0,d66=0; int d=0; // 積が奇数の度数 float ritu; // 積が奇数の割合 int ct; // ループカウンター int N=1000; // 速度 int yy,xx; // 枠の作成 int count; // ループカウンター /****** public void init () メソット **************************************************************/ public void init(){ myth=null; // スレッドの初期化 imgno=0; r1=1;r2=1; // さいころの目はどちらも1 img=new Image[ 6 ]; // イメージの実体化 img[ 0 ] =getimage( getdocumentbase (),"sai1.jpg"); // さいころ1 画像読み込み img[ 1 ] =getimage( getdocumentbase (),"sai2.jpg"); // さいころ2 画像読み込み img[ 2 ] =getimage( getdocumentbase (),"sai3.jpg"); img[ 3 ] =getimage( getdocumentbase (),"sai4.jpg"); // さいころ3 画像読み込み // さいころ4 画像読み込み img[ 4 ] =getimage( getdocumentbase (),"sai5.jpg"); // さいころ5 画像読み込み img[ 5 ] =getimage( getdocumentbase (),"sai6.jpg"); // さいころ6 画像読み込み mymt=new MediaTracker( this ); // メディアトラッカーの実体化 for ( count=0;count < =5;count++ ){ mymt.addimage( img[ count ],0);// メディアトラッカーへのイメージの貼り付け try{ mymt.waitforid( 0 ); // 例外処理 catch( InterruptedException e){ mybtn=new Button[ 4 ]; // ボタンの実体化 mybtn[ 0 ] =new Button (" 初期化 "); mybtn[ 1 ] =new Button (" 高 速 "); mybtn[ 2 ] =new Button (" 低 mybtn[ 3 ] =new Button (" 停 速 "); 止 "); -24-

mypanel=new Panel (); mypanel.setlayout( new GridLayout( 1,4 )); // パネルをグリッドレイアウトにする for ( count=0;count < =3;count++ ){ mypanel.add( mybtn[ count ]); // パネルにボタンを貼り付ける setlayout( new BorderLayout ()); // 全体をボーダーレイアウトにする add ("South",myPanel); // パネルを南に貼り付ける mybtn[ 0 ].addactionlistener( new ActionListener (){ // 初期化ボタン public void actionperformed( ActionEvent e){ flag=0; // 識別子 r1=1;r2=1; // さいころの目はどちらも1 repaint (); //paint() メソッドを呼び出す ); mybtn[ 1 ].addactionlistener( new ActionListener (){ // 高速ボタン public void actionperformed( ActionEvent e){ flag=1; // 識別子 N=100; // 速度 ( 0.1 秒 ) repaint (); //paint() メソッドを呼び出す ); mybtn[ 2 ].addactionlistener( new ActionListener (){ // 低速ボタン public void actionperformed( ActionEvent e){ flag=2; // 識別子 N=1000; // 速度 ( 1 秒 ) repaint (); //paint() メソッドを呼び出す ); mybtn[ 3 ].addactionlistener( new ActionListener (){ // 停止ボタン public void actionperformed( ActionEvent e){ flag=3; // 識別子 repaint (); //paint() メソッドを呼び出す ); //public void init() /****** public void start () メソット *************************************************************/ public void start(){ if ( myth==null){ myth=new Thread( this ); // スレッドを実体化する myth.start (); // スレッドをスタートする /****** public void run () メソット **************************************************************/ public void run (){ // イベントがなくても処理が行われる while ( true ){ try{ myth.sleep( N ); catch ( InterruptedException e){ if ( flag==1 flag==2){ repaint (); -25-

/****** public void paint( Graphics g ) メソット ***************************************************/ public void paint( Graphics g){ if ( mymt.checkid( 0)){ // 初期状態と初期化ボタンを押したとき if ( flag==0){ g.clearrect( 0,0,300,350 ); // 全体のクリア d11=0;d21=0;d31=0;d41=0;d51=0;d61=0; の初期化 d12=0;d22=0;d32=0;d42=0;d52=0;d62=0; の初期化 d13=0;d23=0;d33=0;d43=0;d53=0;d63=0; の初期化 d14=0;d24=0;d34=0;d44=0;d54=0;d64=0; の初期化 d15=0;d25=0;d35=0;d45=0;d55=0;d65=0; d16=0;d26=0;d36=0;d46=0;d56=0;d66=0; の初期化 の初期化 ct1=0; // 実験回数の初期化 // さいころ1の画像の表示 g.drawimage( img[ 0 ],100,30,this); g.drawstring (" さいころⅠ ",90,75); // さいころ2の画像の表示 g.drawimage( img[ 0 ],190,30,this); g.drawstring (" さいころⅡ ",180,75); // 枠の項目 g.drawstring (" さいころⅡ 1 2 3 4 g.drawstring (" さいころⅠ ",50,130); g.drawstring (1 " ",70,150); g.drawstring (2 " ",70,170); g.drawstring (3 " ",70,190); g.drawstring (4 " ",70,210); g.drawstring (5 " ",70,230); g.drawstring (6 " ",70,250); 5 6 ",60,110); g.setcolor( Color.blue );g.drawstring(""+d11,125,150); g.setcolor( Color.black );g.drawstring(""+d12,149,150); g.drawstring (""+d21,125,170);g.drawstring(""+d22,149,170); g.setcolor( Color.blue );g.drawstring(""+d31,125,190); g.setcolor( Color.black );g.drawstring(""+d32,149,190); g.drawstring (""+d41,125,210);g.drawstring(""+d42,149,210); g.setcolor( Color.blue );g.drawstring(""+d51,125,230); g.setcolor( Color.black );g.drawstring(""+d52,149,230); g.drawstring (""+d61,125,250);g.drawstring(""+d62,149,250); g.setcolor( Color.blue );g.drawstring(""+d13,173,150); g.setcolor( Color.black );g.drawstring(""+d14,197,150); g.drawstring (""+d23,173,170);g.drawstring(""+d24,197,170); g.setcolor( Color.blue );g.drawstring(""+d33,173,190); g.setcolor( Color.black );g.drawstring(""+d34,197,190); g.drawstring (""+d43,173,210);g.drawstring(""+d44,197,210); g.setcolor( Color.blue );g.drawstring(""+d53,173,230); g.setcolor( Color.black );g.drawstring(""+d54,197,230); g.drawstring (""+d63,173,250);g.drawstring(""+d64,197,250); g.setcolor( Color.blue );g.drawstring(""+d15,221,150); g.setcolor( Color.black );g.drawstring(""+d16,245,150); g.drawstring (""+d25,221,170);g.drawstring(""+d26,245,170); g.setcolor( Color.blue );g.drawstring(""+d35,221,190); g.setcolor( Color.black );g.drawstring(""+d36,245,190); g.drawstring (""+d45,221,210);g.drawstring(""+d46,245,210); g.setcolor( Color.blue );g.drawstring(""+d55,221,230); g.setcolor( Color.black );g.drawstring(""+d56,245,230); g.drawstring (""+d65,221,250);g.drawstring(""+d66,245,250); -26-

// 枠の線 g.drawline( 30+10,95,255+10,95 ); g.drawline( 30+10,115,105,115 ); g.drawline( 105,115,121,135 ); for ( yy=135;yy < =255;yy=yy+20){ g.drawline( 30+10,yy,255+10,yy ); for ( xx=255+10;xx> 110+10;xx=xx-24){ g.drawline( xx,95,xx,255 ); g.drawline( 30+10,95,30+10,255 ); // 積が奇数の度数 d=d11+d13+d15+d31+d33+d35+d51+d53+d55; g.drawstring (" 積が奇数の回数 = "+d,40,280); // 積が奇数の割合 if ( ct1!=0){ ritu= float d/ float ct1; ( ) ( ) g.drawstring (" 積が奇数の割合 = "+ritu,40,300); // 実験回数の表示 g.drawstring (" 実験回数 = "+ct1,110+10,20); // 作者表示 g.drawstring ("Copyright( C) K.Niwa 2001.12",80,325 ); //if ( flag==0) // 高速ボタンまたは低速ボタンを押したとき else if ( flag==1 flag==2){ ct1++; // 実験回数 // さいころ1の画像の表示 g.drawimage( img[ 0 ],100,30,this); g.drawstring (" さいころⅠ ",90,75); // さいころ2の画像の表示 g.drawimage( img[ 0 ],190,30,this); g.drawstring (" さいころⅡ ",180,75); // 枠の項目 g.drawstring (" さいころⅡ 1 2 3 4 g.drawstring (" さいころⅠ ",50,130); g.drawstring (1 " ",70,150); g.drawstring (2 " ",70,170); g.drawstring (3 " ",70,190); g.drawstring (4 " ",70,210); g.drawstring (5 " ",70,230); g.drawstring (6 " ",70,250); 5 6 ",60,110); g.setcolor( Color.blue );g.drawstring(""+d11,125,150); g.setcolor( Color.black );g.drawstring(""+d12,149,150); g.drawstring (""+d21,125,170);g.drawstring(""+d22,149,170); g.setcolor( Color.blue );g.drawstring(""+d31,125,190); g.setcolor( Color.black );g.drawstring(""+d32,149,190); g.drawstring (""+d41,125,210);g.drawstring(""+d42,149,210); g.setcolor( Color.blue );g.drawstring(""+d51,125,230); g.setcolor( Color.black );g.drawstring(""+d52,149,230); g.drawstring (""+d61,125,250);g.drawstring(""+d62,149,250); g.setcolor( Color.blue );g.drawstring(""+d13,173,150); g.setcolor( Color.black );g.drawstring(""+d14,197,150); g.drawstring (""+d23,173,170);g.drawstring(""+d24,197,170); -27-

g.setcolor( Color.blue );g.drawstring(""+d33,173,190); g.setcolor( Color.black );g.drawstring(""+d34,197,190); g.drawstring (""+d43,173,210);g.drawstring(""+d44,197,210); g.setcolor( Color.blue );g.drawstring(""+d53,173,230); g.setcolor( Color.black );g.drawstring(""+d54,197,230); g.drawstring (""+d63,173,250);g.drawstring(""+d64,197,250); g.setcolor( Color.blue );g.drawstring(""+d15,221,150); g.setcolor( Color.black );g.drawstring(""+d16,245,150); g.drawstring (""+d25,221,170);g.drawstring(""+d26,245,170); g.setcolor( Color.blue );g.drawstring(""+d35,221,190); g.setcolor( Color.black );g.drawstring(""+d36,245,190); g.drawstring (""+d45,221,210);g.drawstring(""+d46,245,210); g.setcolor( Color.blue );g.drawstring(""+d55,221,230); g.setcolor( Color.black );g.drawstring(""+d56,245,230); g.drawstring (""+d65,221,250);g.drawstring(""+d66,245,250); // 枠の線 g.drawline( 30+10,95,255+10,95 ); g.drawline( 30+10,115,105,115 ); g.drawline( 105,115,121,135 ); for ( yy=135;yy < =255;yy=yy+20){ g.drawline( 30+10,yy,255+10,yy ); for ( xx=255+10;xx> 110+10;xx=xx-24){ g.drawline( xx,95,xx,255 ); g.drawline( 30+10,95,30+10,255 ); // 積が奇数の度数 d=d11+d13+d15+d31+d33+d35+d51+d53+d55; g.drawstring (" 積が奇数の回数 = "+d,40,280); // 積が奇数の割合 if ( ct1!=0){ ritu= ( float) d/ ( float) ct1; g.drawstring (" 積が奇数の割合 = "+ritu,40,300); // 実験回数の表示 g.drawstring (" 実験回数 = "+ct1,110+10,20); // 作者表示 g.drawstring ("Copyright( C) K.Niwa 2001.12",80,325 ); // 判断前のさいころⅠとさいころⅡの点滅 for ( ct=1;ct < =6;ct++ ){ r1= ( int)( 1+6*Math.random ()); switch ( r1){ case 1:g.drawImage( img[ 0 ],100,30,this);break; case 2:g.drawImage( img[ 1 ],100,30,this);break; case 3:g.drawImage( img[ 2 ],100,30,this);break; case 4:g.drawImage( img[ 3 ],100,30,this);break; case 5:g.drawImage( img[ 4 ],100,30,this);break; case 6:g.drawImage( img[ 5 ],100,30,this);break; g.drawstring (" さいころⅠ ",90,75); r2= ( int)( 1+6*Math.random ()); switch ( r2){ case 1:g.drawImage( img[ 0 ],190,30,this);break; case case 2:g.drawImage( img[ 1 ],190,30,this);break; 3:g.drawImage( img[ 2 ],190,30,this);break; case case 4:g.drawImage( img[ 3 ],190,30,this);break; 5:g.drawImage( img[ 4 ],190,30,this);break; -28-

case 6:g.drawImage( img[ 5 ],190,30,this);break; g.drawstring (" さいころⅡ ",180,75); for ( t=1;t < =1000000;t++ ){ のカウント if ( r1==1 && r2==1){ d11=d11+1; else if ( r1==2 && r2==1){ d21=d21+1; else if ( r1==3 && r2==1){ d31=d31+1; else if ( r1==4 && r2==1){ d41=d41+1; else if ( r1==5 && r2==1){ d51=d51+1; else if ( r1==6 && r2==1){ d61=d61+1; //----------------------- else if ( r1==1 && r2==2){ d12=d12+1; else if ( r1==2 && r2==2){ d22=d22+1; else if ( r1==3 && r2==2){ d32=d32+1; else if ( r1==4 && r2==2){ d42=d42+1; else if ( r1==5 && r2==2){ d52=d52+1; else if ( r1==6 && r2==2){ d62=d62+1; //----------------------- else if ( r1==1 && r2==3){ d13=d13+1; else if ( r1==2 && r2==3){ d23=d23+1; else if ( r1==3 && r2==3){ d33=d33+1; else if ( r1==4 && r2==3){ d43=d43+1; else if ( r1==5 && r2==3){ d53=d53+1; else if ( r1==6 && r2==3) { d63=d63+1; -29-

//----------------------- else if ( r1==1 && r2==4){ d14=d14+1; else if ( r1==2 && r2==4){ d24=d24+1; else if ( r1==3 && r2==4){ d34=d34+1; else if ( r1==4 && r2==4){ d44=d44+1; else if ( r1==5 && r2==4){ d54=d54+1; else if ( r1==6 && r2==4){ d64=d64+1; //----------------------- else if ( r1==1 && r2==5){ d15=d15+1; else if ( r1==2 && r2==5){ d25=d25+1; else if ( r1==3 && r2==5){ d35=d35+1; else if ( r1==4 && r2==5){ d45=d45+1; else if ( r1==5 && r2==5){ d55=d55+1; else if ( r1==6 && r2==5){ d65=d65+1; //----------------------- else if ( r1==1 && r2==6){ d16=d16+1; else if ( r1==2 && r2==6){ d26=d26+1; else if ( r1==3 && r2==6){ d36=d36+1; else if ( r1==4 && r2==6){ d46=d46+1; else if ( r1==5 && r2==6){ d56=d56+1; else if ( r1==6 && r2==6){ d66=d66+1; g.clearrect( 0,0,300,300 ); // 枠の消去 switch ( r1){ case 1:g.drawImage( img[ 0 ],100,30,this);break; case 2:g.drawImage( img[ 1 ],100,30,this);break; case 3:g.drawImage( img[ 2 ],100,30,this);break; -30-

case 4:g.drawImage( img[ 3 ],100,30,this);break; case 5:g.drawImage( img[ 4 ],100,30,this);break; case 6:g.drawImage( img[ 5 ],100,30,this);break; g.drawstring (" さいころⅠ ",90,75); switch ( r2){ case 1:g.drawImage( img[ 0 ],190,30,this);break; case 2:g.drawImage( img[ 1 ],190,30,this);break; case 3:g.drawImage( img[ 2 ],190,30,this);break; case 4:g.drawImage( img[ 3 ],190,30,this);break; case 5:g.drawImage( img[ 4 ],190,30,this);break; case 6:g.drawImage( img[ 5 ],190,30,this);break; g.drawstring (" さいころⅡ ",180,75); // 枠の項目 g.drawstring (" さいころⅡ 1 2 3 4 5 6 ",60,110); g.drawstring (" さいころⅠ ",50,130); g.drawstring (1 " ",70,150); g.drawstring (2 " ",70,170); g.drawstring (3 " ",70,190); g.drawstring (4 " ",70,210); g.drawstring (5 " ",70,230); g.drawstring (6 " ",70,250); g.setcolor( Color.blue );g.drawstring(""+d11,125,150); g.setcolor( Color.black );g.drawstring(""+d12,149,150); g.drawstring (""+d21,125,170);g.drawstring(""+d22,149,170); g.setcolor( Color.blue );g.drawstring(""+d31,125,190); g.setcolor( Color.black );g.drawstring(""+d32,149,190); g.drawstring (""+d41,125,210);g.drawstring(""+d42,149,210); g.setcolor( Color.blue );g.drawstring(""+d51,125,230); g.setcolor( Color.black );g.drawstring(""+d52,149,230); g.drawstring (""+d61,125,250);g.drawstring(""+d62,149,250); g.setcolor( Color.blue );g.drawstring(""+d13,173,150); g.setcolor( Color.black );g.drawstring(""+d14,197,150); g.drawstring (""+d23,173,170);g.drawstring(""+d24,197,170); g.setcolor( Color.blue );g.drawstring(""+d33,173,190); g.setcolor( Color.black );g.drawstring(""+d34,197,190); g.drawstring (""+d43,173,210);g.drawstring(""+d44,197,210); g.setcolor( Color.blue );g.drawstring(""+d53,173,230); g.setcolor( Color.black );g.drawstring(""+d54,197,230); g.drawstring (""+d63,173,250);g.drawstring(""+d64,197,250); g.setcolor( Color.blue );g.drawstring(""+d15,221,150); g.setcolor( Color.black );g.drawstring(""+d16,245,150); g.drawstring (""+d25,221,170);g.drawstring(""+d26,245,170); g.setcolor( Color.blue );g.drawstring(""+d35,221,190); g.setcolor( Color.black );g.drawstring(""+d36,245,190); g.drawstring (""+d45,221,210);g.drawstring(""+d46,245,210); g.setcolor( Color.blue );g.drawstring(""+d55,221,230); g.setcolor( Color.black );g.drawstring(""+d56,245,230); g.drawstring (""+d65,221,250);g.drawstring(""+d66,245,250); // 枠の線 g.drawline( 30+10,95,255+10,95 ); g.drawline( 30+10,115,105,115 ); g.drawline( 105,115,121,135 ); for ( yy=135;yy < =255;yy=yy+20){ g.drawline( 30+10,yy,255+10,yy ); -31-

for ( xx=255+10;xx> 110+10;xx=xx-24){ g.drawline( xx,95,xx,255 ); g.drawline( 30+10,95,30+10,255 ); // 積が奇数の度数 d=d11+d13+d15+d31+d33+d35+d51+d53+d55; g.drawstring (" 積が奇数の回数 = "+d,40,280); // 積が奇数の割合 if ( ct1!=0){ ritu= ( float) d/ ( float) ct1; g.drawstring (" 積が奇数の割合 = "+ritu,40,300); // 実験回数の表示 g.drawstring (" 実験回数 = "+ct1,110+10,20); // 作者表示 g.drawstring ("Copyright( C) K.Niwa 2001.12",80,325 ); //else if ( flag==1 flag==2) // 停止ボタンを押したとき else if ( flag==3){ switch ( r1){ case 1:g.drawImage( img[ 0 ],100,30,this);break; case 2:g.drawImage( img[ 1 ],100,30,this);break; case 3:g.drawImage( img[ 2 ],100,30,this);break; case 4:g.drawImage( img[ 3 ],100,30,this);break; case 5:g.drawImage( img[ 4 ],100,30,this);break; case 6:g.drawImage( img[ 5 ],100,30,this);break; g.drawstring (" さいころⅠ ",90,75); switch ( r2){ case 1:g.drawImage( img[ 0 ],190,30,this);break; case 2:g.drawImage( img[ 1 ],190,30,this);break; case 3:g.drawImage( img[ 2 ],190,30,this);break; case 4:g.drawImage( img[ 3 ],190,30,this);break; case 5:g.drawImage( img[ 4 ],190,30,this);break; case 6:g.drawImage( img[ 5 ],190,30,this);break; g.drawstring (" さいころⅡ ",180,75); // 枠の項目 g.drawstring (" さいころⅡ 1 2 3 4 g.drawstring (" さいころⅠ ",50,130); g.drawstring (1 " ",70,150); g.drawstring (2 " ",70,170); g.drawstring (3 " ",70,190); g.drawstring (4 " ",70,210); g.drawstring (5 " ",70,230); g.drawstring (6 " ",70,250); 5 6 ",60,110); g.setcolor( Color.blue );g.drawstring(""+d11,125,150); g.setcolor( Color.black );g.drawstring(""+d12,149,150); g.drawstring (""+d21,125,170);g.drawstring(""+d22,149,170); g.setcolor( Color.blue );g.drawstring(""+d31,125,190); g.setcolor( Color.black );g.drawstring(""+d32,149,190); g.drawstring (""+d41,125,210);g.drawstring(""+d42,149,210); g.setcolor( Color.blue );g.drawstring(""+d51,125,230); -32-

g.setcolor( Color.black );g.drawstring(""+d52,149,230); g.drawstring (""+d61,125,250);g.drawstring(""+d62,149,250); g.setcolor( Color.blue );g.drawstring(""+d13,173,150); g.setcolor( Color.black );g.drawstring(""+d14,197,150); g.drawstring (""+d23,173,170);g.drawstring(""+d24,197,170); g.setcolor( Color.blue );g.drawstring(""+d33,173,190); g.setcolor( Color.black );g.drawstring(""+d34,197,190); g.drawstring (""+d43,173,210);g.drawstring(""+d44,197,210); g.setcolor( Color.blue );g.drawstring(""+d53,173,230); g.setcolor( Color.black );g.drawstring(""+d54,197,230); g.drawstring (""+d63,173,250);g.drawstring(""+d64,197,250); g.setcolor( Color.blue );g.drawstring(""+d15,221,150); g.setcolor( Color.black );g.drawstring(""+d16,245,150); g.drawstring (""+d25,221,170);g.drawstring(""+d26,245,170); g.setcolor( Color.blue );g.drawstring(""+d35,221,190); g.setcolor( Color.black );g.drawstring(""+d36,245,190); g.drawstring (""+d45,221,210);g.drawstring(""+d46,245,210); g.setcolor( Color.blue );g.drawstring(""+d55,221,230); g.setcolor( Color.black );g.drawstring(""+d56,245,230); g.drawstring (""+d65,221,250);g.drawstring(""+d66,245,250); // 枠の線 g.drawline( 30+10,95,255+10,95 ); g.drawline( 30+10,115,105,115 ); g.drawline( 105,115,121,135 ); for ( yy=135;yy < =255;yy=yy+20){ g.drawline( 30+10,yy,255+10,yy ); for ( xx=255+10;xx> 110+10;xx=xx-24){ g.drawline( xx,95,xx,255 ); g.drawline( 30+10,95,30+10,255 ); // 積が奇数の度数 d=d11+d13+d15+d31+d33+d35+d51+d53+d55; g.drawstring (" 積が奇数の回数 = "+d,40,280); // 積が奇数の割合 if ( ct1!=0){ ritu= ( float) d/ ( float) ct1; g.drawstring (" 積が奇数の割合 = "+ritu,40,300); // 実験回数の表示 g.drawstring (" 実験回数 = "+ct1,110+10,20); //else if ( flag==3) //if ( mymt.checkid( 0)) //public void paint( Graphics g) //public class Coins extends Applet // 作者表示 g.drawstring ("Copyright( C) K.Niwa 2001.12",80,325 ); -33-

(2) HTML リスト < HTML> < HEAD> <!------------------------------------------------------------------------------------------------------------------------------------- 積が奇数の2 個のさいころ Copyright ( C) K.Niwa 2001.12.20 --------------------------------------------------------------------------------------------------------------------------------------> < /HEAD> < BODY > < CENTER< > B > 積が奇数の2 個のさいころ < /B> < BR>< BR> < APPLET CODE="Saikoro2.class" WIDTH="300" HEIGHT="350" >< /APPLET> < BR>< BR> < /CENTER> < /BODY> < /HTML> 3.Java アプリケーション プログラムリスト //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // 2 個のさいころ // // // Copyright ( C) K.Niwa 2002.08.21 (Javaアプリケーション) // // // // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /****** クラスの読み込み ******************************************************************/ import java.awt.*; //java.awt パッケージから全てのクラスを読み込む import java.awt.event.*; //java.awt.event パッケージから全てのクラスを読み込む import java.lang.math; //java.lang パッケージから.Math クラスを読み込む /****** public class FSaikoro2 extends Frame implements Runnable ********************************/ public class FSaikoro2 extends Frame implements Runnable { // スレット を使えるようにする Thread myth; // スレッド型として宣言する Button[] mybtn; Panel mypanel; // ボタン型として宣言する // パネル型として宣言する int imgno; // 整数型として宣言する Image[] img; MediaTracker mymt; // イメージ型として宣言する // メディアトラッカー型として宣言する int flag=0; int r1=1,r2=1; // 整数型として宣言し初期化する // 乱数 int ct1; // 実験回数 long t; // 時間かせぎ int d11=0,d21=0,d31=0,d41=0,d51=0,d61=0; int d12=0,d22=0,d32=0,d42=0,d52=0,d62=0; int d13=0,d23=0,d33=0,d43=0,d53=0,d63=0; int d14=0,d24=0,d34=0,d44=0,d54=0,d64=0; int d15=0,d25=0,d35=0,d45=0,d55=0,d65=0; int d16=0,d26=0,d36=0,d46=0,d56=0,d66=0; int d=0; // 積が奇数の度数 float ritu; int ct; / 積が奇数の割合 // ループカウンター int N=1000; // 速度 int yy,xx; int count; // 枠の作成 // ループカウンター -34-

/****** フレームとイベントの定義 *********************************************************/ public FSaikoro2(){ setbackground( Color.lightGray ); // 背景色の設定 setsize( 300,360 ); // フレームの大きさ addwindowlistener( new WindowAdapter (){ // フレームの定義 public void windowclosing( WindowEvent e){ System.exit( 0 ); ); myth=null; // スレッドの初期化 if ( myth==null ){ // スレッドの実体化 myth=new Thread( this ); // スレットを開始する myth.start (); imgno=0; r1=1;r2=1; // さいころの目はどちらも1 img=new Image[ 6 ]; // イメージの実体化 img[ 0 ] =Toolkit.getDefaultToolkit ().getimage("sai1.jpg");// さいころ1 画像読み込み img[ 1 ] =Toolkit.getDefaultToolkit ().getimage("sai2.jpg");// さいころ2 画像読み込み img[ 2 ] =Toolkit.getDefaultToolkit ().getimage("sai3.jpg");// さいころ3 画像読み込み img[ 3 ] =Toolkit.getDefaultToolkit ().getimage("sai4.jpg");// さいころ4 画像読み込み img[ 4 ] =Toolkit.getDefaultToolkit ().getimage("sai5.jpg");// さいころ5 画像読み込み img[ 5 ] =Toolkit.getDefaultToolkit ().getimage("sai6.jpg");// さいころ6 画像読み込み mymt=new MediaTracker( this ); // メディアトラッカーの実体化 for ( count=0;count < =5;count++ ){ mymt.addimage( img[ count ],0); // メテ ィアトラッカーへのイメーシ の貼り付け try{ mymt.waitforid( 0 ); // 例外処理 catch( InterruptedException e){ mybtn=new Button[ 4 ]; // ボタンの実体化 mybtn[ 0 ] =new Button (" 初期化 "); mybtn[ 1 ] =new Button (" 高 mybtn[ 2 ] =new Button (" 低 速 "); 速 "); mybtn[ 3 ] =new Button (" 停 止 "); mypanel=new Panel (); // パネルの実態化 mypanel.setlayout( new GridLayout( 1,4 )); for ( count=0;count < =3;count++ ){ // パネルをグリッドレイアウトにする mypanel.add( mybtn[ count ]); // バネルにボタンを貼り付ける setlayout( new BorderLayout ()); // 全体をボーダーレイアウトにする add ("South",myPanel); // パネルを南に貼り付ける mybtn[ 0 ].addactionlistener( new ActionListener (){ // 初期化ボタン public void actionperformed( ActionEvent e){ flag=0; r1=1;r2=1; // さいころの目はどちらも1 repaint (); //paint() メソッドを呼び出す ); -35-

mybtn[ 1 ].addactionlistener( new ActionListener (){ // 高速ボタン public void actionperformed( ActionEvent e){ flag=1; N=100; repaint (); ); mybtn[ 2 ].addactionlistener( new ActionListener (){ // 低速ボタン public void actionperformed( ActionEvent e){ flag=2; N=1000; repaint (); ); mybtn[ 3 ].addactionlistener( new ActionListener (){ // 停止ボタン public void actionperformed( ActionEvent e){ flag=3; repaint (); ); //public FSaikoro2() /****** public void run () メソット **************************************************************/ public void run (){ while ( true ){ try { myth.sleep( N ); // 休む catch ( InterruptedException e){ if ( flag==1 flag==2){ repaint (); /****** public void paint( Graphics g ) メソット ****************************************************/ public void paint( Graphics g){ if ( mymt.checkid( 0)){ // 初期状態と初期化ボタンを押したとき if ( flag==0){ g.clearrect( 0,0,300,350 ); // 全体のクリア d11=0;d21=0;d31=0;d41=0;d51=0;d61=0; の初期化 d12=0;d22=0;d32=0;d42=0;d52=0;d62=0; d13=0;d23=0;d33=0;d43=0;d53=0;d63=0; の初期化 の初期化 d14=0;d24=0;d34=0;d44=0;d54=0;d64=0; の初期化 d15=0;d25=0;d35=0;d45=0;d55=0;d65=0; の初期化 d16=0;d26=0;d36=0;d46=0;d56=0;d66=0; の初期化 ct1=0; // 実験回数の初期化 // さいころ1の画像の表示 g.drawimage( img[ 0 ],100,30,this); g.drawstring (" さいころⅠ ",90,75); // さいころ2の画像の表示 g.drawimage( img[ 0 ],190,30,this); g.drawstring (" さいころⅡ ",180,75); -36-

// 枠の項目 g.drawstring (" さいころⅡ 1 2 3 4 5 6 ",60-15,110); g.drawstring (" さいころⅠ ",50,130); g.drawstring (1 " ",70,150); g.drawstring (2 " ",70,170); g.drawstring (3 " ",70,190); g.drawstring (4 " ",70,210); g.drawstring (5 " ",70,230); g.drawstring (6 " ",70,250); g.setcolor( Color.blue );g.drawstring(""+d11,125,150); g.setcolor( Color.black );g.drawstring(""+d12,149,150); g.drawstring (""+d21,125,170);g.drawstring(""+d22,149,170); g.setcolor( Color.blue );g.drawstring(""+d31,125,190); g.setcolor( Color.black );g.drawstring(""+d32,149,190); g.drawstring (""+d41,125,210);g.drawstring(""+d42,149,210); g.setcolor( Color.blue );g.drawstring(""+d51,125,230); g.setcolor( Color.black );g.drawstring(""+d52,149,230); g.drawstring (""+d61,125,250);g.drawstring(""+d62,149,250); g.setcolor( Color.blue );g.drawstring(""+d13,173,150); g.setcolor( Color.black );g.drawstring(""+d14,197,150); g.drawstring (""+d23,173,170);g.drawstring(""+d24,197,170); g.setcolor( Color.blue );g.drawstring(""+d33,173,190); g.setcolor( Color.black );g.drawstring(""+d34,197,190); g.drawstring (""+d43,173,210);g.drawstring(""+d44,197,210); g.setcolor( Color.blue );g.drawstring(""+d53,173,230); g.setcolor( Color.black );g.drawstring(""+d54,197,230); g.drawstring (""+d63,173,250);g.drawstring(""+d64,197,250); g.setcolor( Color.blue );g.drawstring(""+d15,221,150); g.setcolor( Color.black );g.drawstring(""+d16,245,150); g.drawstring (""+d25,221,170);g.drawstring(""+d26,245,170); g.setcolor( Color.blue );g.drawstring(""+d35,221,190); g.setcolor( Color.black );g.drawstring(""+d36,245,190); g.drawstring (""+d45,221,210);g.drawstring(""+d46,245,210); g.setcolor( Color.blue );g.drawstring(""+d55,221,230); g.setcolor( Color.black );g.drawstring(""+d56,245,230); g.drawstring (""+d65,221,250);g.drawstring(""+d66,245,250); // 枠の線 g.drawline( 30+10,95,255+10,95 ); g.drawline( 30+10,115,105,115 ); g.drawline( 105,115,121,135 ); for ( yy=135;yy < =255;yy=yy+20){ g.drawline( 30+10,yy,255+10,yy ); for ( xx=255+10;xx> 110+10;xx=xx-24){ g.drawline( xx,95,xx,255 ); g.drawline( 30+10,95,30+10,255 ); // 積が奇数の度数 d=d11+d13+d15+d31+d33+d35+d51+d53+d55; g.drawstring (" 積が奇数の回数 = "+d,40,280); // 積が奇数の割合 if ( ct1!=0){ ritu= ( float) d/ ( float) ct1; g.drawstring (" 積が奇数の割合 = "+ritu,40,300); // 実験回数の表示 g.drawstring (" 実験回数 = "+ct1,110+10,20); -37-

// 作者表示 g.drawstring ("Copyright( C) K.Niwa 2002.08",80,325 ); //if ( flag==0) // 高速ボタンまたは低速ボタンを押したとき else if ( flag==1 flag==2){ ct1++; // 実験回数 // さいころ1の画像の表示 g.drawimage( img[ 0 ],100,30,this); g.drawstring (" さいころⅠ ",90,75); // さいころ2の画像の表示 g.drawimage( img[ 0 ],190,30,this); g.drawstring (" さいころⅡ ",180,75); // 枠の項目 g.drawstring (" さいころⅡ 1 2 3 4 5 6 ",60-15,110); //g.drawstring(" さいころⅡ 1 2 3 4 5 6 ",60,110); g.drawstring (" さいころⅠ ",50,130); g.drawstring (1 " ",70,150); g.drawstring (2 " ",70,170); g.drawstring (3 " ",70,190); g.drawstring (4 " ",70,210); g.drawstring (5 " ",70,230); g.drawstring (6 " ",70,250); g.setcolor( Color.blue );g.drawstring(""+d11,125,150); g.setcolor( Color.black );g.drawstring(""+d12,149,150); g.drawstring (""+d21,125,170);g.drawstring(""+d22,149,170); g.setcolor( Color.blue );g.drawstring(""+d31,125,190); g.setcolor( Color.black );g.drawstring(""+d32,149,190); g.drawstring (""+d41,125,210);g.drawstring(""+d42,149,210); g.setcolor( Color.blue );g.drawstring(""+d51,125,230); g.setcolor( Color.black );g.drawstring(""+d52,149,230); g.drawstring (""+d61,125,250);g.drawstring(""+d62,149,250); g.setcolor( Color.blue );g.drawstring(""+d13,173,150); g.setcolor( Color.black );g.drawstring(""+d14,197,150); g.drawstring (""+d23,173,170);g.drawstring(""+d24,197,170); g.setcolor( Color.blue );g.drawstring(""+d33,173,190); g.setcolor( Color.black );g.drawstring(""+d34,197,190); g.drawstring (""+d43,173,210);g.drawstring(""+d44,197,210); g.setcolor( Color.blue );g.drawstring(""+d53,173,230); g.setcolor( Color.black );g.drawstring(""+d54,197,230); g.drawstring (""+d63,173,250);g.drawstring(""+d64,197,250); g.setcolor( Color.blue );g.drawstring(""+d15,221,150); g.setcolor( Color.black );g.drawstring(""+d16,245,150); g.drawstring (""+d25,221,170);g.drawstring(""+d26,245,170); g.setcolor( Color.blue );g.drawstring(""+d35,221,190); g.setcolor( Color.black );g.drawstring(""+d36,245,190); g.drawstring (""+d45,221,210);g.drawstring(""+d46,245,210); g.setcolor( Color.blue );g.drawstring(""+d55,221,230); g.setcolor( Color.black );g.drawstring(""+d56,245,230); g.drawstring (""+d65,221,250);g.drawstring(""+d66,245,250); // 枠の線 g.drawline( 30+10,95,255+10,95 ); g.drawline( 30+10,115,105,115 ); g.drawline( 105,115,121,135 ); -38-

for ( yy=135;yy < =255;yy=yy+20){ g.drawline( 30+10,yy,255+10,yy ); for ( xx=255+10;xx> 110+10;xx=xx-24){ g.drawline( xx,95,xx,255 ); g.drawline( 30+10,95,30+10,255 ); // 積が奇数の度数 d=d11+d13+d15+d31+d33+d35+d51+d53+d55; g.drawstring (" 積が奇数の回数 = "+d,40,280); // 積が奇数の割合 if ( ct1!=0){ ritu= ( float) d/ ( float) ct1; g.drawstring (" 積が奇数の割合 = "+ritu,40,300); // 実験回数の表示 g.drawstring (" 実験回数 = "+ct1,110+10,20); // 作者表示 g.drawstring ("Copyright( C) K.Niwa 2002.08",80,325 ); // 判断前のさいころⅠとさいころⅡの点滅 for ( ct=1;ct < =6;ct++ ){ r1= ( int)( 1+6*Math.random ()); switch ( r1){ case 1:g.drawImage( img[ 0 ],100,30,this);break; case 2:g.drawImage( img[ 1 ],100,30,this);break; case 3:g.drawImage( img[ 2 ],100,30,this);break; case 4:g.drawImage( img[ 3 ],100,30,this);break; case 5:g.drawImage( img[ 4 ],100,30,this);break; case 6:g.drawImage( img[ 5 ],100,30,this);break; g.drawstring (" さいころⅠ ",90,75); r2= ( int)( 1+6*Math.random ()); switch ( r2){ case 1:g.drawImage( img[ 0 ],190,30,this);break; case 2:g.drawImage( img[ 1 ],190,30,this);break; case 3:g.drawImage( img[ 2 ],190,30,this);break; case 4:g.drawImage( img[ 3 ],190,30,this);break; case 5:g.drawImage( img[ 4 ],190,30,this);break; case 6:g.drawImage( img[ 5 ],190,30,this);break; g.drawstring (" さいころⅡ ",180,75); for ( t=1;t < =1000000;t++ ){ のカウント if ( r1==1 && r2==1){ d11=d11+1; else if ( r1==2 && r2==1){ d21=d21+1; else if ( r1==3 && r2==1){ d31=d31+1; else if ( r1==4 && r2==1){ d41=d41+1; -39-

else if ( r1==5 && r2==1){ d51=d51+1; else if ( r1==6 && r2==1){ d61=d61+1; //----------------------- else if ( r1==1 && r2==2){ d12=d12+1; else if ( r1==2 && r2==2){ d22=d22+1; else if ( r1==3 && r2==2){ d32=d32+1; else if ( r1==4 && r2==2){ d42=d42+1; else if ( r1==5 && r2==2){ d52=d52+1; else if ( r1==6 && r2==2){ d62=d62+1; //----------------------- else if ( r1==1 && r2==3){ d13=d13+1; else if ( r1==2 && r2==3){ d23=d23+1; else if ( r1==3 && r2==3){ d33=d33+1; else if ( r1==4 && r2==3){ d43=d43+1; else if ( r1==5 && r2==3){ d53=d53+1; else if ( r1==6 && r2==3){ d63=d63+1; //----------------------- else if ( r1==1 && r2==4){ d14=d14+1; else if ( r1==2 && r2==4){ d24=d24+1; else if ( r1==3 && r2==4){ d34=d34+1; else if ( r1==4 && r2==4){ d44=d44+1; else if ( r1==5 && r2==4){ d54=d54+1; else if ( r1==6 && r2==4){ d64=d64+1; //----------------------- -40-

else if ( r1==1 && r2==5){ d15=d15+1; else if ( r1==2 && r2==5){ d25=d25+1; else if ( r1==3 && r2==5){ d35=d35+1; else if ( r1==4 && r2==5){ d45=d45+1; else if ( r1==5 && r2==5){ d55=d55+1; else if ( r1==6 && r2==5){ d65=d65+1; //----------------------- else if ( r1==1 && r2==6){ d16=d16+1; else if ( r1==2 && r2==6){ d26=d26+1; else if ( r1==3 && r2==6){ d36=d36+1; else if ( r1==4 && r2==6){ d46=d46+1; else if ( r1==5 && r2==6){ d56=d56+1; else if ( r1==6 && r2==6){ d66=d66+1; g.clearrect( 0,0,300,300 ); // 枠の消去 switch ( r1){ case 1:g.drawImage( img[ 0 ],100,30,this);break; case 2:g.drawImage( img[ 1 ],100,30,this);break; case 3:g.drawImage( img[ 2 ],100,30,this);break; case 4:g.drawImage( img[ 3 ],100,30,this);break; case 5:g.drawImage( img[ 4 ],100,30,this);break; case 6:g.drawImage( img[ 5 ],100,30,this);break; g.drawstring (" さいころⅠ ",90,75); switch ( r2){ case 1:g.drawImage( img[ 0 ],190,30,this);break; case 2:g.drawImage( img[ 1 ],190,30,this);break; case 3:g.drawImage( img[ 2 ],190,30,this);break; case 4:g.drawImage( img[ 3 ],190,30,this);break; case 5:g.drawImage( img[ 4 ],190,30,this);break; case 6:g.drawImage( img[ 5 ],190,30,this);break; g.drawstring (" さいころⅡ ",180,75); // 枠の項目 g.drawstring (" さいころⅡ 1 2 3 4 5 6 //g.drawstring(" さいころⅡ 1 2 ",60-15,110); 3 4-41-

g.drawstring (" さいころⅠ ",50,130); g.drawstring (1 " ",70,150); g.drawstring (2 " ",70,170); g.drawstring (3 " ",70,190); g.drawstring (4 " ",70,210); g.drawstring (5 " ",70,230); g.drawstring (6 " ",70,250); 5 6 ",60,110); g.setcolor( Color.blue );g.drawstring(""+d11,125,150); g.setcolor( Color.black );g.drawstring(""+d12,149,150); g.drawstring (""+d21,125,170);g.drawstring(""+d22,149,170); g.setcolor( Color.blue );g.drawstring(""+d31,125,190); g.setcolor( Color.black );g.drawstring(""+d32,149,190); g.drawstring (""+d41,125,210);g.drawstring(""+d42,149,210); g.setcolor( Color.blue );g.drawstring(""+d51,125,230); g.setcolor( Color.black );g.drawstring(""+d52,149,230); g.drawstring (""+d61,125,250);g.drawstring(""+d62,149,250); g.setcolor( Color.blue );g.drawstring(""+d13,173,150); g.setcolor( Color.black );g.drawstring(""+d14,197,150); g.drawstring (""+d23,173,170);g.drawstring(""+d24,197,170); g.setcolor( Color.blue );g.drawstring(""+d33,173,190); g.setcolor( Color.black );g.drawstring(""+d34,197,190); g.drawstring (""+d43,173,210);g.drawstring(""+d44,197,210); g.setcolor( Color.blue );g.drawstring(""+d53,173,230); g.setcolor( Color.black );g.drawstring(""+d54,197,230); g.drawstring (""+d63,173,250);g.drawstring(""+d64,197,250); g.setcolor( Color.blue );g.drawstring(""+d15,221,150); g.setcolor( Color.black );g.drawstring(""+d16,245,150); g.drawstring (""+d25,221,170);g.drawstring(""+d26,245,170); g.setcolor( Color.blue );g.drawstring(""+d35,221,190); g.setcolor( Color.black );g.drawstring(""+d36,245,190); g.drawstring (""+d45,221,210);g.drawstring(""+d46,245,210); g.setcolor( Color.blue );g.drawstring(""+d55,221,230); g.setcolor( Color.black );g.drawstring(""+d56,245,230); g.drawstring (""+d65,221,250);g.drawstring(""+d66,245,250); // 枠の線 g.drawline( 30+10,95,255+10,95 ); g.drawline( 30+10,115,105,115 ); g.drawline( 105,115,121,135 ); for ( yy=135;yy < =255;yy=yy+20){ g.drawline( 30+10,yy,255+10,yy ); for ( xx=255+10;xx> 110+10;xx=xx-24){ g.drawline( xx,95,xx,255 ); g.drawline( 30+10,95,30+10,255 ); // 積が奇数の度数 d=d11+d13+d15+d31+d33+d35+d51+d53+d55; g.drawstring (" 積が奇数の回数 = "+d,40,280); // 積が奇数の割合 if ( ct1!=0){ ritu= ( float) d/ ( float) ct1; g.drawstring (" 積が奇数の割合 = "+ritu,40,300); // 実験回数の表示 g.drawstring (" 実験回数 = "+ct1,110+10,20); -42-

// 作者表示 g.drawstring ("Copyright( C) K.Niwa 2002.08",80,325 ); //else if ( flag==1 flag==2) // 停止ボタンを押したとき else if ( flag==3){ switch ( r1){ case 1:g.drawImage( img[ 0 ],100,30,this);break; case 2:g.drawImage( img[ 1 ],100,30,this);break; case 3:g.drawImage( img[ 2 ],100,30,this);break; case 4:g.drawImage( img[ 3 ],100,30,this);break; case 5:g.drawImage( img[ 4 ],100,30,this);break; case 6:g.drawImage( img[ 5 ],100,30,this);break; g.drawstring (" さいころⅠ ",90,75); switch ( r2){ case 1:g.drawImage( img[ 0 ],190,30,this);break; case 2:g.drawImage( img[ 1 ],190,30,this);break; case 3:g.drawImage( img[ 2 ],190,30,this);break; case 4:g.drawImage( img[ 3 ],190,30,this);break; case 5:g.drawImage( img[ 4 ],190,30,this);break; case 6:g.drawImage( img[ 5 ],190,30,this);break; g.drawstring (" さいころⅡ ",180,75); // 枠の項目 g.drawstring (" さいころⅡ 1 2 3 4 5 6 ",60-15,110); //g.drawstring(" さいころⅡ 1 2 3 4 5 6 ",60,110); g.drawstring (" さいころⅠ ",50,130); g.drawstring (1 " ",70,150); g.drawstring (2 " ",70,170); g.drawstring (3 " ",70,190); g.drawstring (4 " ",70,210); g.drawstring (5 " ",70,230); g.drawstring (6 " ",70,250); g.setcolor( Color.blue );g.drawstring(""+d11,125,150); g.setcolor( Color.black );g.drawstring(""+d12,149,150); g.drawstring (""+d21,125,170);g.drawstring(""+d22,149,170); g.setcolor( Color.blue );g.drawstring(""+d31,125,190); g.setcolor( Color.black );g.drawstring(""+d32,149,190); g.drawstring (""+d41,125,210);g.drawstring(""+d42,149,210); g.setcolor( Color.blue );g.drawstring(""+d51,125,230); g.setcolor( Color.black );g.drawstring(""+d52,149,230); g.drawstring (""+d61,125,250);g.drawstring(""+d62,149,250); g.setcolor( Color.blue );g.drawstring(""+d13,173,150); g.setcolor( Color.black );g.drawstring(""+d14,197,150); g.drawstring (""+d23,173,170);g.drawstring(""+d24,197,170); g.setcolor( Color.blue );g.drawstring(""+d33,173,190); g.setcolor( Color.black );g.drawstring(""+d34,197,190); g.drawstring (""+d43,173,210);g.drawstring(""+d44,197,210); g.setcolor( Color.blue );g.drawstring(""+d53,173,230); g.setcolor( Color.black );g.drawstring(""+d54,197,230); g.drawstring (""+d63,173,250);g.drawstring(""+d64,197,250); g.setcolor( Color.blue );g.drawstring(""+d15,221,150); g.setcolor( Color.black );g.drawstring(""+d16,245,150); g.drawstring (""+d25,221,170);g.drawstring(""+d26,245,170); g.setcolor( Color.blue );g.drawstring(""+d35,221,190); g.setcolor( Color.black );g.drawstring(""+d36,245,190); -43-

g.drawstring (""+d45,221,210);g.drawstring(""+d46,245,210); g.setcolor( Color.blue );g.drawstring(""+d55,221,230); g.setcolor( Color.black );g.drawstring(""+d56,245,230); g.drawstring (""+d65,221,250);g.drawstring(""+d66,245,250); // 枠の線 g.drawline( 30+10,95,255+10,95 ); g.drawline( 30+10,115,105,115 ); g.drawline( 105,115,121,135 ); for ( yy=135;yy < =255;yy=yy+20) { g.drawline( 30+10,yy,255+10,yy ); for ( xx=255+10;xx> 110+10;xx=xx-24) { g.drawline( xx,95,xx,255 ); g.drawline( 30+10,95,30+10,255 ); // 積が奇数の度数 d=d11+d13+d15+d31+d33+d35+d51+d53+d55; g.drawstring (" 積が奇数の回数 = "+d,40,280); // 積が奇数の割合 if ( ct1!=0){ ritu= float d/ float ct1; ( ) ( ) g.drawstring (" 積が奇数の割合 = "+ritu,40,300); // 実験回数の表示 g.drawstring (" 実験回数 = "+ct1,110+10,20); //else if ( flag==3) //if ( mymt.checkid( 0)) //public void paint( Graphics g) // 作者表示 g.drawstring ("Copyright( C) K.Niwa 2002.08",80,325 ); /****** public static void main メソット **********************************************************/ public static void main( String[] args){ Frame w=new FSaikoro2 (); w.show (); //public static void main( String[] args) //public class FSaikoro2 extends Frame implements Runnable -44-