Back to index

wims  3.65+svn20090927
VreemdeEend2.java
Go to the documentation of this file.
00001 // horrible amateur scriblings...no copyrights
00002 
00003 import java.applet.*;
00004 import java.awt.*;
00005 import java.util.*;
00006 import java.awt.event.*;
00007 import java.lang.Math;
00008 import java.net.*;
00009 
00010 //    <param name="max" value="20">                                                                                                  
00011 //    <param name="renew" value="yes">                                                                                               
00012 //    <param name="language" value="nl">                                                                                             
00013 //    <param name="show_result" value="no">
00014 
00015 public class VreemdeEend2 extends Applet implements Runnable{
00016     private static final long serialVersionUID = 1L;
00017     Thread thread = null;Graphics canvas;String replystring="";
00018     public int sy=22;public int xsize=680;public int ysize=7*sy;
00019     int dx;int dy;long start;int foutcounter=1;
00020     double diff;String duration="" ;
00021     int counter;int goedeantwoord;
00022     long stop;public long totaltime=0;
00023     public Image ok;public Image nok;
00024     String[][] Antwoorden;int v1;int v2;int v3;int v4;
00025     String[] Vragen;int records=0;int goedzo=1;int klaar=0;
00026     int volgorde[]={1,2,3,4};long begin;int pressed=1;
00027     int vraagnummers[];
00028     int fnsize=14;Font defaultFont = new Font( "Helvetica", Font.BOLD, fnsize );  
00029     Color blauw=new Color(0,0,255);
00030     Color zwart=new Color(0,0,0);
00031     Color kleur;int max=10;
00032     int m1=0;int m2=0;
00033     
00034     public void init(){
00035         begin=System.currentTimeMillis();klaar=0;
00036        ok=getImage(getCodeBase(), "ok.gif");nok=getImage(getCodeBase(), "nok.gif");
00037        String questions=getParameter("questions");if(questions==null){System.out.println("CAN NOT READ QUESTION PARAM");}
00038        String ss=getParameter("max");if(ss!=null && ss.length()>0){max = Integer.parseInt(ss, 10);}
00039        StringTokenizer vragen = new StringTokenizer(questions, ":");
00040        String vraag="";String antwoord="";int w=0;
00041        Antwoorden=new String[max][4*max];
00042        vraagnummers=new int[max+1];
00043        Vragen=new String[max+1];
00044        int tmp=0;
00045        for(int s=0;s<max-1;s++){
00046            vraag=vragen.nextToken();
00047            StringTokenizer antwoorden = new StringTokenizer(vraag, ";");
00048            w=antwoorden.countTokens();
00049            vraagnummers[s]=s;
00050            for(int r=0;r<w;r++){
00051               antwoord=antwoorden.nextToken();
00052               tmp=fnsize*antwoord.length();if(tmp>xsize){xsize=tmp;}
00053               if(r==0){
00054                   Vragen[s]=antwoord;
00055                   //System.out.println("de vraag = "+antwoord);
00056               }
00057               else
00058               {
00059                   Antwoorden[s][r-1]=antwoord;
00060                   //System.out.println("antwoord  ="+antwoord);
00061               }
00062            }
00063        }
00064        vraagnummers=Shuffle(vraagnummers);
00065        
00066        addMouseMotionListener(new MouseMotionAdapter(){
00067            public void mouseMoved(MouseEvent e){
00068               dy = e.getY();
00069               kleur=zwart;
00070               for(int i=2;i<6;i++){
00071                   m1=i*sy;m2=(i+1)*sy;
00072                   if(dy>m1 && dy<m2){
00073                      pressed=0;
00074                      kleur=blauw;
00075                      i=10;
00076                   }
00077               }
00078               repaint();
00079            }
00080        }
00081        );
00082        
00083        
00084        addMouseListener(
00085            new MouseAdapter(){
00086               public void mousePressed(MouseEvent e){
00087                   dx = e.getX();
00088                   dy = e.getY();
00089                   if(klaar==0){
00090                      kleur=zwart;
00091                      for(int p=2;p<7;p++){
00092                          if(dx>0 && dx<xsize){
00093                             if(dy>(p)*sy+5 && dy<(p+1)*sy+5){
00094                                 if(counter==max){klaar=1;}
00095                                 if(goedeantwoord==p){
00096                                    stop=System.currentTimeMillis();
00097                                    diff=(double)(stop-start)/1000;
00098                                    duration=duration+","+diff;
00099                                    replystring=replystring+"\n"+diff+":"+foutcounter;
00100                                    foutcounter=1;
00101                                    counter++;goedzo=1;
00102                                    start=System.currentTimeMillis();
00103                                    pressed=1;
00104                                 }
00105                                 else
00106                                 {
00107                                    goedzo=0;foutcounter++;
00108                                    pressed=0;
00109                                 }
00110                                 repaint();
00111                             }
00112                          }
00113                      }
00114                   }
00115               }
00116            }
00117        );
00118 
00119     }
00120 
00121        
00122     public static int[] Shuffle(int[] S){
00123            int ll= S.length;
00124            for (int i=0;i<ll;i++){
00125               int r = (int) (Math.random() * (i+1));
00126               int swap = S[r];
00127               S[r] = S[i];
00128               S[i] = swap;
00129            }
00130            for(int i=0;i<ll;i++){
00131             //System.out.println(S[i]);
00132            }
00133         return S;
00134     }
00135     
00136     
00137     public void paint(Graphics canvas){
00138        if(counter==0){start=begin;}
00139        if(klaar==0){
00140            int num=vraagnummers[counter];
00141            canvas.setColor(Color.black);canvas.fillRect(0,0,xsize,ysize);
00142            canvas.setColor(kleur);canvas.fillRect(0,m1+5,xsize,m2+5);
00143            canvas.setColor(Color.black);canvas.fillRect(0,m2+5,xsize,6*sy);
00144            canvas.setFont(defaultFont);canvas.setColor(Color.yellow);
00145            canvas.drawString("Multiplechoice Q "+(counter+1)+") ",10,sy);
00146            canvas.drawString(Vragen[num],10,2*sy);
00147            canvas.setColor(Color.white);
00148            if(pressed!=0){volgorde=Shuffle(volgorde);}
00149            int k;
00150            for(int p=0;p<4;p++){
00151               k=volgorde[p];
00152               if(k==4){goedeantwoord=p+2;}
00153               canvas.setColor(Color.red);canvas.drawLine(0,(p+3)*(sy)+5,xsize,(p+3)*(sy)+5);
00154               canvas.setColor(Color.white);canvas.drawString((p+1)+") "+Antwoorden[num][k-1],10,(p+3)*(sy));
00155            }
00156            canvas.clearRect(0,6*sy+5,xsize,ysize);
00157            canvas.setColor(Color.black);canvas.fillRect(0,6*sy+5,xsize,ysize);
00158            if(goedzo==0){
00159               canvas.drawImage(nok,50,ysize, this);
00160            }
00161            else
00162            {
00163               canvas.drawImage(ok,50,ysize, this);
00164            }
00165        }
00166        
00167        if(klaar==1){
00168            canvas.setColor(Color.black);canvas.fillRect(0,0,xsize,ysize);
00169            canvas.setFont(defaultFont);
00170            StringTokenizer q = new StringTokenizer(replystring, "\n");
00171            int m=q.countTokens(); 
00172            String sub="";int X=10;int Y=10; 
00173            canvas.setColor(Color.white);
00174            canvas.drawString("time :attempts",X,Y);
00175            for(int s=0;s<m;s++){
00176               Y=Y+14;sub=q.nextToken(); canvas.drawString(sub,X,Y);
00177               if(Y>(ysize-14)){ X=X+120; Y=10;canvas.drawString("time :attempts",X,Y);}
00178            }
00179        }
00180                      //System.out.println("goede antwoord="+goedeantwoord);
00181     }
00182  
00183     public void start(){
00184        if(thread == null){
00185            thread = new Thread(this);
00186            thread.start();
00187        }
00188     }
00189 
00190  
00191     public void stop(){
00192        thread =null;
00193     }
00194 
00195     public void run(){
00196        while(thread != null){
00197        try{
00198            Thread.sleep(100);
00199        }
00200        catch (InterruptedException e){
00201        }
00202     }
00203 }
00204 
00205 public void update( Graphics canvas ){
00206     paint( canvas ) ;
00207 }
00208  
00209 public String ReadApplet(){
00210     if(counter<max){
00211        return "error: not finished";
00212     }
00213     else
00214     {
00215        double totaltime=(double) (stop-begin)/1000;
00216        return totaltime+":"+(max-1)+"\n"+replystring;
00217     }
00218 }
00219  
00220  
00221 }
00222 
00223 
00224 
00225 
00226 
00227 
00228 
00229 
00230 
00231 
00232 
00233 
00234 
00235 
00236 
00237 
00238 
00239 
00240 
00241 
00242 
00243 
00244 
00245 
00246 
00247 
00248 
00249 
00250 
00251 
00252 
00253 
00254 
00255 
00256 
00257 
00258 
00259 
00260 
00261 
00262 
00263