/**
* 漢字テスト「その他」
*
**/
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.lang.Math;
public class s extends Applet implements ActionListener{
TextField tf1, tf2, tf3, tf4, tf5, name, cw1, cw2, cw3, cw4, cw5; //ユーザの入力するTextfield
TextArea ta1; // 採点後コメントのでるTextArea
Button b1; //採点するときにユーザがおすボタン
String Q1, Q2, Q3, Q4, Q5; //ユーザが入力した答えを代入する
String answer1 = "はかどる"; //1問目の答えA
String answer1b= "はかど"; //1問目の答えB
String answer2 = "うな"; //2問目の答えA
String answer2b= "うなされる";//2問目の答えB
String answer3 = "えくぼ"; //3問目の答え
String answer4 = "たてがみ"; //4問目の答え
String answer5 = "ひょうきん"; //5問目の答え
String secans = "ひょうけい"; //秘密の間違いの答え
String msg = new String ("Correct!"); //「正解」の表示
String msg2= new String ("wrong!");//「はずれ」の表示
int s; //得点を代入する変数
// initメソッド:アプレットの初期化を行う
public void init(){
setLayout(null);
setBackground(Color.white);
//ユーザが名前を入力するtextfield
name = new TextField("",30);
add(name);
name.addActionListener(this);
name.setBounds(285,15,100,30);
tf1 = new TextField("",10); //一問目に使う解答用のtextfieldのコンストラクタ
add(tf1);
tf1.addActionListener(this);
tf1.setBounds(220,70,125,30);
tf2 = new TextField("",10); //2問目に使う解答用のtextfieldのコンストラクタ
add(tf2);
tf2.addActionListener(this);
tf2.setBounds(220, 140, 125, 30);
tf3 = new TextField("",10); //3問目に使う解答用のtextfieldのコンストラクタ
add(tf3);
tf3.addActionListener(this);
tf3.setBounds(220, 200, 125, 30);
tf4 = new TextField("",10); //4問目に使う解答用のtextfieldのコンストラクタ
add(tf4);
tf4.addActionListener(this);
tf4.setBounds(220, 250, 125, 30);
tf5 = new TextField("",10); //5問目に使う解答用のtextfieldのコンストラクタ
add(tf5);
tf5.addActionListener(this);
tf5.setBounds(220, 310, 125, 30);
Button b1= new Button("採点!"); //採点するときにユーザが押すボタンのコンストラクタ
b1.setActionCommand("score"); //採点するときにボタンをおすと”score”commandが発動される
b1.addActionListener(this);
add(b1);
b1.setBounds(200,340,50,30);
ta1 = new TextArea("",120,20,TextArea.SCROLLBARS_HORIZONTAL_ONLY); //得点に対するコメントがかかれるtextarea。スクロールバーが下につく。
add(ta1);
ta1.setBounds(125,400,200,40);
/**回答の正誤の判定(correct!/wrong!)が現れるテキストフィールドのコンストラクター **/
cw1 = new TextField(null,10);
add(cw1);
cw2 = new TextField(null,10);
add(cw2);
cw3 = new TextField(null,10);
add(cw3);
cw4 = new TextField(null,10);
add(cw4);
cw5 = new TextField(null,10);
add(cw5);
int s =0; //得点を代入する変数。初期設定は0点。
}
/**採点ボタンがおされたあとのActionEvent **/
public void actionPerformed(ActionEvent e){
System.out.println("actionP");
setLayout(null);
String command = e.getActionCommand(); //コマンドをとる
String msg4= new String(""+name.getText()+"みたいに中途半端に1問だけあってんのってサイテー。");
String msg3= new String("故人"+name.getText()+"は漢字は読めなくても、とてもやさしい子でした・・(泣)");
String msg5= new String("秘密暴露コーナー:私、"+name.getText()+"の趣味は連続コマネチ100回を寝起き直後にすることです。");
String msg6= new String(""+name.getText()+"〜、あんたってほんっっと相変わらず月並な人間よね");
String msg7= new String(""+name.getText()+"くん、本当にカンニングしてない?");
String msg8= new String(""+name.getText()+"殿、あなたの無駄に博識振りをここに賞します。");
String msg9= new String("ちょっと"+name.getText()+"、「ひょうけい」はないんじゃないの?「ひょうけい」は・・。");
/**採点ボタンが押されたら**/
if(command.equals("score")){
System.out.println("button pushed");
Q1 = tf1.getText(); //各テキストフィールドにユーザが入力した文字を取る
Q2 = tf2.getText();
Q3 = tf3.getText();
Q4 = tf4.getText();
Q5 = tf5.getText();
//得点の初期設定。最初は0点。ユーザが解答を修正後に、前に採点してえた得点にさらに加算しない役割も果たす。
s = 0;
/**第1問目**/
if(Q1.equals(answer1)){ //「はかどる」と答えたばあい。
System.out.println("1correct asw a");
cw1.setText(msg);
cw1.setBounds(350,70,55,20);
s = s + 20; //20点加算される
}
else if(Q1.equals(answer1b)){ //「はかど」と答えたばあい
System.out.println("1correct asw b");
cw1.setText(msg);
cw1.setBounds(350,70,55,20);
s = s + 20; //20点加算される
}
else { //その他違う答えの場合。
System.out.println("1wrong asw");
cw1.setText(msg2);
cw1.setBounds(350,70,55,20);
}
//以下も同型
/** 第2問目 **/
if(Q2.equals(answer2)){ //「うな」
System.out.println("2correct asw a");
cw2.setText(msg);
cw2.setBounds(350,140,55,20);
s = s + 20;
}
else if(Q2.equals(answer2b)){ //「うなされる」と答えたばあい
System.out.println("2correct asw b");
cw2.setText(msg);
cw2.setBounds(350,140,55,20);
s = s + 20; //20点加算される
}
else{
System.out.println("2wrong asw");
cw2.setText(msg2);
cw2.setBounds(350,140,55,20);
}
/**第三問目**/
if(Q3.equals(answer3)){ //「えくぼ」
System.out.println("3correct asw");
cw3.setText(msg);
cw3.setBounds(350,200,55,20);
s = s + 20;
}
else{
System.out.println("3wrong asw");
cw3.setText(msg2);
cw3.setBounds(350,200,55,20);
}
/**第4問目**/
if(Q4.equals(answer4)){ //「たてがみ」
System.out.println("4correct asw");
cw4.setText(msg);
cw4.setBounds(350,260,55,20);
s = s + 20;
}
else{
System.out.println("4wrong asw");
cw4.setText(msg2);
cw4.setBounds(350,260,55,20);
}
/**第5問目**/
if(Q5.equals(answer5)){ //「ひょうきん」
System.out.println("5correct asw");
cw5.setText(msg);
cw5.setBounds(350,320,55,20);
s = s + 20;
}
else if(Q5.equals(secans)){ //「秘密の間違い」
System.out.println("secret answer");
cw5.setText(msg2);
cw5.setBounds(350,320,55,20);
s = s -100000;
}
else{
System.out.println("5wrong asw");
cw5.setText(msg2);
cw5.setBounds(350,320,55,20);
}
/** 点数別のリアクション**/
if(s == 0){ //0点の場合
System.out.println("msg0");
ta1.setText(msg3); //メッセージを書く
setBackground(Color.gray); //背景色を変える。グレイ
}
if(s == 20){
System.out.println("msg20"); //20点の場合
ta1.setText(msg4);
setBackground(Color.pink);
}
if(s == 40){ //40点の場合
System.out.println("msg40");
ta1.setText(msg5);
setBackground(Color.white);
}
if(s == 60){ //60点の場合
System.out.println("msg60");
ta1.setText(msg6);
setBackground(Color.orange);
}
if(s == 80){ //80点の場合
System.out.println("msg80");
ta1.setText(msg7);
setBackground(Color.blue);
}
if(s == 100){ //100点の場合
System.out.println("msg100");
ta1.setText(msg8);
setBackground(Color.red);
}
if(s <= -100000){ //裏技を使ったとき
System.out.println("msg100000");
ta1.setText(msg9);
setBackground(Color.black);
}
repaint();
}
}
public void paint(Graphics g){
Font font;
setLayout(new FlowLayout(FlowLayout.LEFT));
g.setFont(new Font("impact",Font.ITALIC,20));
g.drawString("あなたの下の名前",100,30);
g.setFont(new Font("impact",Font.BOLD,30)); //質問をコンストラクト
g.drawString("捗る",100,85);
g.drawString("魘される",100,160);
g.drawString("靨",100,215);
g.drawString("鬣",100,270);
g.drawString("剽軽",100,325);
g.setColor(Color.green);
g.drawString("Your score is "+s+" !",100,390); //点を表示
}
}