report#8
ProgII/e045732
Report#1
Report#2
Report#3
Report#4
Report#5
Report#6
Report#7
Report#8
Belonging-----Information Engineering Section
Student ID---045732K
Name----------Shingo Tamaki
Date------------2006/01/30(MON)
1.課題の紹介
---Java Appletプログラミング---
- Java Applet/AWTについて学び、Java Appletのオリジナルプログラムを作
成し解説せよ。
2.ソースプログラム
- Count.java
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Count extends Applet {
int i = 0;
int k = 0;
int n = 0;
int t = 0;
String s = "";
Button b0 = new Button("Reset");
Button b1 = new Button("1");
Button b2 = new Button("2");
Button b3 = new Button("3");
Label l1 = new Label("Your First");
public void init() {
add(b0);
add(b1);
add(b2);
add(b3);
add(l1);
b0.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
n = 0;
l1.setText("Your First");
}
});
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
i = n;
n = n + 1;
Random r = new Random();
k = ((int)(r.nextDouble() * 10) % 3) + 1;
t = n + k;
if(i >= 50){
l1.setText("The End");
}
else if(n == 21){
l1.setText("You Lose");
n = n + 100;
}
else if(t <= 20){
String v = Integer.toString(t);
l1.setText(v);
n = t;
}
else if(t > 20){
l1.setText("You Win");
n = n + 100;
}
}
});
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
i = n;
n = n + 2;
Random r = new Random();
k = ((int)(r.nextDouble() * 10) % 3) + 1;
t = n + k;
if(i >= 21){
l1.setText("The End");
}
else if(n >= 21){
l1.setText("You Lose");
n = n + 100;
}
else if(t <= 20){
String v = Integer.toString(t);
l1.setText(v);
n = t;
}
else if(t > 20){
l1.setText("You Win");
n = n + 100;
}
}
});
b3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
i = n;
n = n + 3;
Random r = new Random();
k = ((int)(r.nextDouble() * 10) % 3) + 1;
t = n + k;
if(i >= 22){
l1.setText("The End");
}
else if(n >= 21){
l1.setText("You Lose");
n = n + 100;
}
else if(t <= 20){
String v = Integer.toString(t);
l1.setText(v);
n = t;
}
else if(t > 20){
l1.setText("You Win");
n = n + 100;
}
}
});
}
}
3.実行結果
4.考察及び解説
- これは21を取らないように数を取っていくゲームです。
最初、横の方に『Your First』と表示され、こちらが先攻で、
数字のボタンを押すと順に数字を取り、さらにプログラムがラ
ンダムに1から3取った数が表示されます。
もし、21以上の数を取ると『You Lose』が表示され、逆に取
らせると『You Win』が表示されます。『You Lose』や『You W
in』が表示されている時に数字のボタンを押すと『The End』と
表示されます。
Resetボタンを押すと、いつでも最初からやり直せます。
5.感想
ProgII/e045732
Report#1
Report#2
Report#3
Report#4
Report#5
Report#6
Report#7
Report#8