// ====================================================================== // // Conjugation2.java: Applet framework to do conjugation drills // ----------------- // Modification of "Conjugation.java" // // Note: This version is setup with data for Spanish verbs but by changing // the data, the Applet could be adapted to similar exercices. // // Author: Jean VAUCHER, Prof. informatique & RO, Univ. de Montreal // (retired 2008) // Email : vaucher@iro.umontreal.ca // WWW : http://www.iro.umontreal.ca/~vaucher/ // // ------------------------------------------------------------------------ // Version 1.0: march 2002 // // Tested on: MacOS X - "appletviewer" & Explorer // Mac Os9 : Explorer & Netscape 4.79 + Plug-in & MRJ // Linux: appletviewer and Netscape // // At present, we appear to have bugs under Windows. // // - In order to run on as many browsers as possible, we tried to limit // Java features to those in Java 1.1. Thus, we don't use Swing, // limit ourselves to Vector data structures and do our own sorting. // // - One problem that proved difficult is handling of accents. We decided // to allow the "/" character to denote an accent. We check KeyEvents, // "consume" the "/" characters and replace following vowels by the // Unicode accented equivalent. // - But, the program has been patched to accomodate bugs/peculiarities // of various environments. In particular, under Netscape/Linux it appears // difficult to "consume" KeyEvents and "/" characters appear. This is // why we look for and replace slashes in the answer field before // checking the answers. // ---------------------------------------------------------------------- // Jan 2009: // - generalised the code to simplify adding more tenses or verb groups // - Also replaced UNICODE for accentd letters in tables (‡ versus ‡) // - added the "x" as place holder for verb form to be ignored // a) for imperative (YO) and to reduce boredom for simple repetitive forms // // - Spawned two versions: // Conjugation2 for standard tenses and // Conjugation3 for subjunctive and stuff // ============================================================================= import java.awt.*; import java.awt.event.*; import java.util.* ; import java.applet.Applet; public class Conjugation2 extends Applet // Implements Actionlistener { ProgressBar left = new ProgressBar(); CheckboxGroup tense = new CheckboxGroup(); Checkbox ckb_a1 = new Checkbox("Present", true); Checkbox ckb_a2 = new Checkbox("Imperfect", false); Checkbox ckb_a3 = new Checkbox("Preterito", false); Checkbox ckb_a4 = new Checkbox("Future", false); Checkbox ckb_a5 = new Checkbox("Conditional", false); Checkbox ckb_b1 = new Checkbox("Ser, Estar", true); Checkbox ckb_b2 = new Checkbox("Regular -AR"); Checkbox ckb_b3 = new Checkbox("Regular -ER"); Checkbox ckb_b4 = new Checkbox("Regular -IR"); Checkbox ckb_c1 = new Checkbox("Haber,Hacer,Tener", false); Checkbox ckb_c2 = new Checkbox("Irreg. -AR"); Checkbox ckb_c3 = new Checkbox("Irreg. -ER"); Checkbox ckb_c4 = new Checkbox("Irreg. -IR"); Checkbox ckb_c5 = new Checkbox("Just to practice errors"); Label tenseHeader = new Label("Presente de Subjunctivo", Label.CENTER); Label model = new Label(" to begin !", Label.CENTER); Label person = new Label(" yo", Label.RIGHT ); TextField answer = new TextField(" ", 22 ); Button start = null; // Flasher display=null; Checkbox [] catBoxes = { ckb_b1, ckb_b2, ckb_b3, ckb_b4, ckb_c1, ckb_c2, ckb_c3, ckb_c4, ckb_c5 }; Checkbox [] tenseBoxes = { ckb_a1, ckb_a2, ckb_a3, ckb_a4, ckb_a5 }; Hashtable tenseTable = new Hashtable(10); Hashtable tenseOUT = new Hashtable(10); Hashtable tenseColor = new Hashtable(); static String level; int cat0 = 1; public void init() { level = "1"; String param = getParameter("level"); // System.out.println( param ); if ( param!=null) level = param; // - the following matches the order in "tenseBoxes" and that in COLUMN1 if (level.equals("1")) { tenseTable.put("Present", new Integer(0)); tenseTable.put("Imperfect", new Integer(1)); tenseTable.put("Preterito", new Integer(2)); tenseTable.put("Future", new Integer(3)); tenseTable.put("Conditional",new Integer(4)); tenseColor.put("Preterito", Color.red); tenseColor.put("Imperfect", new Color(0x006600)); tenseColor.put("Future", Color.blue); tenseColor.put("Conditional", new Color(0xFF6600)); } else { tenseTable.put("Present_PERF", new Integer(0)); tenseTable.put("Present_PROG", new Integer(1)); tenseTable.put("Present_SUBJ", new Integer(2)); tenseTable.put("Imperative", new Integer(3)); tenseTable.put("Past_SUBJ", new Integer(4)); tenseOUT.put("Present_PERF", "Presente Perfecto"); tenseOUT.put("Present_PROG", "Pres. Progressivo"); tenseOUT.put("Present_SUBJ", "Present Subjunctive"); tenseOUT.put("Past_SUBJ" , "Past Subjunctive"); tenseColor.put("Imperative", Color.red); tenseColor.put("Present_SUBJ", new Color(0x006600)); tenseColor.put("Past_SUBJ", new Color(0xFF00FF)); tenseColor.put("Present_PROG", Color.blue); ckb_a1.setLabel("+participle"); ckb_a2.setLabel("+gerund"); ckb_a3.setLabel("Present Subjunct."); ckb_a4.setLabel("Imperative"); ckb_a5.setLabel("Past Subjunct."); } // display = new Flasher( this ); display.start(); start = new Button(" Reset "); start.setVisible(false); // Set a default font this.setFont(new Font("SansSerif", Font.PLAIN, 12)); Panel column1 = new Panel(); Panel column2 = new Panel(); Panel column3 = new Panel(); column1.setLayout( new GridLayout(5,1, 5, 5) ); column2.setLayout( new GridLayout(4,1, 5, 5) ); column3.setLayout( new GridLayout(4,1, 5, 5) ); // The following must also correspond column1.add( ckb_a1 ); column1.add( ckb_a2 ); column1.add( ckb_a3 ); column1.add( ckb_a4 ); column1.add( ckb_a5 ); column2.add( ckb_b1 ); column2.add( ckb_b2 ); column2.add( ckb_b3 ); column2.add( ckb_b4 ); column3.add( ckb_c1 ); column3.add( ckb_c2 ); column3.add( ckb_c3 ); column3.add( ckb_c4 ); // column3.add( ckb_c5 ); Panel bottom = new Panel(); // bottom.setLayout( new GridLayout(1,3, 10, 5) ); // bottom.add( column1 ); // bottom.add( column2 ); // bottom.add( column3 ); bottom.setLayout( new GridBagLayout() ); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets( 2,2,2,2 ); c.weightx = 1; c.gridx = 0; c.gridy = 0; c.gridwidth = 2; bottom.add( column1, c ); c.weightx = 0.5; c.gridx = 2; c.gridy = 0; c.gridwidth = 1; bottom.add( column2, c ); c.weightx = 1; c.gridx = 3; c.gridy = 0; c.gridwidth = 2; bottom.add( column3, c ); this.setLayout(new BorderLayout(10, 10)); this.add(bottom, "South"); tenseHeader.setFont(new Font("Monospaced", Font.BOLD, 20)); model.setFont( new Font("Monospaced", Font.BOLD, 18 )); person.setFont( new Font("Monospaced", Font.PLAIN, 12) ); answer.setFont( new Font("Monospaced", Font.BOLD, 14) ); Panel main = new Panel(); main.setLayout( new GridBagLayout() ); c = new GridBagConstraints(); c.insets = new Insets( 2,2,2,2 ); c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.HORIZONTAL; main.add( tenseHeader, c ); c.gridx = 0; c.gridy = 1; main.add( model, c ); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; main.add( person, c ); c.gridx = 1; c.gridy = 2; c.gridwidth = GridBagConstraints.REMAINDER; main.add( answer, c ); this.add( main, "Center"); this.add( left, "West"); Panel right = new Panel(); right.setLayout( new GridLayout(4,1) ); right.add( new Panel() ); right.add( start ); right.add( new Panel() ); right.add( new Panel() ); this.add( right, "East"); // ------------Set-up Listeners -------------------------- start.addActionListener( new StartListener()); answer.addActionListener( new AnswerListener() ); answer.addKeyListener( new KeyModListener() ); CBListener cbl = new CBListener(); int ic; for (ic=0; ic= 0 )) { e.setKeyChar( "/‡Ž’—".charAt(pos)); accent = false; } else accent = false; } } // ===================================================================== // Program Logic // ===================================================================== boolean accent = false ; int fldLen = 0 ; // -------- Accented letters ------------ // 'a : ‡ // 'e : Ž // 'i : ’ // 'o : — // -------------------------------------- static String VERBS [] = { "1 Present Estar estoy est‡s est‡ estamos est‡n", "1 Imperfect Estar estaba estabas estaba est‡bamos estaban", "1 Preterito Estar estuve estuviste estuvo estuvimos estuvieron", "1 Future Estar estarŽ estar‡s estar‡ estaremos estar‡n", "1 Conditional Estar estar’a estar’as estar’a estar’amos estar’an", "1 Imperative Estar x est‡ estŽ estemos estŽn", "1 Present_SUBJ Estar estŽ estŽs estŽ estemos estŽn", "1 Past_SUBJ Estar estuviera estuvieras estuviera estuviŽramos estuvieran", "1 Past_SUBJ Estar2 estuviese estuvieses x x x", "1 Present_PERF Estar he_estado x ha_estado x han_estado", "1 Present_PERF Ser x has_sido x hemos_sido x ", "1 Present_PROG Estar estoy_estando x x x x", "1 Present Ser soy eres es somos son", "1 Imperfect Ser era eras era Žramos eran", "1 Preterito Ser fui fuiste fue fuimos fueron", "1 Future Ser serŽ ser‡s ser‡ seremos ser‡n", "1 Conditional Ser ser’a ser’as ser’a ser’amos ser’an", "1 Imperative Ser x sŽ sea seamos sean", "1 Present_SUBJ Ser sea seas sea seamos sean", "1 Past_SUBJ Ser fuera fueras x fuŽramos fueran", "1 Past_SUBJ Ser2 fuese x x fuŽsemos x", "1 Present_PROG Ser x est‡s_siendo x x x", // ---------------------- "2 Present Cantar canto x canta x cantan", "2 Imperfect Cantar cantaba x cantaba cant‡bamos x", "2 Preterito Cantar cantŽ x cant— x x", // "2 Future Cantar x cantar‡s cantar‡ cantaremos cantar‡n", "2 Conditional Cantar cantar’a x cantar’a x cantar’an", "2 Imperative Cantar x canta cante cantemos canten", "2 Present Hablar x hablas x hablamos x", "2 Imperfect Cambiar x cambiabas x cambi‡bamos cambiaban", "2 Preterito Comprar x compraste x compramos compraron", "2 Future Llamar llamarŽ llamar‡s llamar‡ llamaremos llamar‡n", "2 Conditional Usar x usar’as x usar’amos x", "2 Present_SUBJ Comprar compre compres compre compremos compren", "2 Present_SUBJ Cantar cante x x cantemos x", "2 Present_PERF Cantar he_cantado has_cantado x hemos_cantado x", "2 Present_PERF Hablar x x ha_hablado x han_hablado", "2 Present_PROG Cantar estoy_cantando x x x est‡n_cantando", "2 Present_PROG Hablar x est‡s_hablando x x x", "2 Present_PROG Cambiar x x est‡_cambiando x x", "2 Present_PROG Comprar x x x estamos_comprando x", // ---------------------- "3 Present Comer como comes come comemos comen", "3 Imperfect Beber beb’a x beb’a beb’amos x", "3 Preterito Comer com’ comiste x comimos x", "3 Future Beber beberŽ x beber‡ beberemos x", // "3 Conditional Comer comer’a comer’as comer’a comer’amos comer’an", "3 Imperative Beber x bebe beba bebamos beban", "3 Present_SUBJ Comer coma comas coma x x", "3 Present_SUBJ Beber x bebas x bebamos beban", "3 Past_SUBJ Beber bebiera x bebiera bebiŽramos x", "3 Past_SUBJ Beber2 x x bebiese x bebiesen ", "3 Present_PERF Comer he_comido has_comido x x x", "3 Present_PROG Beber x x est‡_bebiendo x x", "3 Present Leer leo lees lee leemos leen", "3 Imperfect Poder x pod’as x x pod’an", "3 Preterito Conocer x x conoci— x conocieron", "3 Future Perder x perder‡s x x perder‡n", "3 Conditional Vender vender’a vender’as vender’a vender’amos vender’an", // ---------------------- "4 Present Vivir vivo x vive vivimos x", "4 Imperfect Vivir viv’a x viv’a viv’amos x", "4 Preterito Vivir viv’ x vivi— x x", "4 Future Vivir vivirŽ vivir‡s x viviremos vivir‡n", "4 Conditional Vivir vivir’a x vivir’a x vivir’an", "4 Present Escribir x escribes x x escriben", "4 Imperfect Decir x dec’as x dec’amos dec’an", "4 Preterito Subir x subiste x subimos subieron", "4 Future Ir irŽ x ir‡ iremos x", "4 Conditional Abrir x abrir’as x abrir’amos x", "4 Imperative Vivir x vive viva vivamos vivan", "4 Present_SUBJ Vivir viva x x vivamos x", "4 Present_SUBJ Recibir x recibas reciba x reciban", "4 Past_SUBJ Vivir viviera vivieras x x vivieran", "4 Past_SUBJ Vivir2 x x viviese viviŽsemos x", "4 Present_PERF Vivir he_vivido x x hemos_vivido x", "4 Present_PROG Vivir estoy_viviendo x x x est‡n_viviendo", // ---------------------- "5 Present Tener tengo tienes tiene tenemos tienen", "5 Imperfect Tener ten’a x ten’a x ten’an", "5 Preterito Tener tuve tuviste tuvo x x", "5 Future Tener tendrŽ tendr‡s tendr‡ tendremos tendr‡n", "5 Conditional Tener tendr’a x x tendr’amos x", "5 Present Haber he has ha hemos han", "5 Imperfect Haber hab’a x x hab’amos x", "5 Preterito Haber hube hubiste x hubimos hubieron", "5 Future Haber habrŽ habr‡s x x x", "5 Conditional Haber habr’a habr’as habr’a habr’amos habr’an", "5 Present Hacer hago haces hace hacemos hacen", "5 Imperfect Hacer hac’a hac’as x x x", "5 Preterito Hacer hice x hizo hicimos x", "5 Future Hacer harŽ x har‡ haremos x", "5 Conditional Hacer x har’as x har’amos x", "5 Imperative Tener x ten tenga tengamos tengan", "5 Imperative Haber x he haya hayamos hayan", "5 Imperative Hacer x haz haga hagamos hagan", "5 Present_SUBJ Tener tenga tengas x tengamos x", "5 Present_SUBJ Haber haya x x hayamos hayan", "5 Present_SUBJ Hacer x hagas haga x x", "5 Past_SUBJ Tener tuviera tuvieras x tuviŽramos x", "5 Past_SUBJ Tener2 tuviese x x x x", "5 Present_PERF Hacer he_hecho has_hecho x x x", "5 Present_PERF Tener x x x x han_tenido", "5 Present_PERF Haber x x x hemos_habido x", "5 Present_PROG Tener x est‡s_teniendo x x x", // ---------------------- "6 Present Pensar pienso piensas piensa pensamos piensan ", "6 Present Empezar empiezo empiezas empieza empezamos empiezan", "6 Present Contar cuento cuentas cuenta contamos cuentan", "6 Present Dar doy das da damos dan", "6 Preterito Empezar empecŽ empezaste empez— empezamos empezaron", "6 Preterito Andar anduve anduviste anduvo anduvimos anduvieron", "6 Preterito Pagar paguŽ pagaste pag— pagamos pagaron", "6 Preterito Dar di diste dio dimos dieron", "6 Preterito Buscar busquŽ x x x buscaron", "6 Preterito Jugar juguŽ jugaste x x x", "6 Preterito Llegar lleguŽ x lleg— x x", "6 Preterito Lanzar lancŽ x x lanzamos x", "6 Imperfect Andar andaba andabas andaba and‡bamos andaban", "6 Future Pagar pagarŽ pagar‡s pagar‡ pagaremos pagar‡n", "6 Conditional Pensar pensar’a pensar’as pensar’a pensar’amos pensar’an", "6 Present_SUBJ Pensar piense pienses piense pensemos piensen", "6 Present_SUBJ Empezar empiece empieces x empecemos x", "6 Present_SUBJ Contar cuente x x contemos cuenten", "6 Present_SUBJ Jugar juegue juegues x juguemos jueguen", "6 Present_SUBJ Lanzar lance x x x lancen", "6 Present_SUBJ Buscar busque busques x busquemos x", "6 Imperative Pagar x paga pague paguemos paguen", "6 Imperative Dar x da dŽ demos den ", "6 Imperative Dar_neg x des x x x", "6 Imperative Buscar x busca busque x x", "6 Past_SUBJ Pensar pensara pensaras x x x", "6 Past_SUBJ Pensar2 x x x pens‡semos pensasen", "6 Past_SUBJ Dar diera x x diŽramos dieran", "6 Imperative Vivir x vive viva vivamos vivan", "6 Present_SUBJ Vivir viva x x vivamos x", "6 Past_SUBJ Vivir viviera vivieras x x vivieran", "6 Past_SUBJ Vivir2 x x viviese viviŽsemos x", "6 Present_PERF Pensar he_pensado x x x x", "6 Present_PERF Empezar x has_empezado x x x", "6 Present_PERF Dar x x ha_dado x x", "6 Present_PROG Dar estoy_dando x x x x", "6 Present_PROG Vivir estoy_viviendo x x x est‡n_viviendo", // ---------------------- "7 Present Poder puedo puedes puede podemos pueden", "7 Imperfect Poder pod’a pod’as pod’a pod’amos pod’an", "7 Preterito Poder pude pudiste pudo pudimos pudieron", "7 Future Poder podrŽ podr‡s podr‡ podremos podr‡n", "7 Conditional Poder podr’a x x podr’amos x", "7 Preterito Poner puse pusiste puso pusimos pusieron", "7 Future Poner pondrŽ pondr‡s pondr‡ pondremos pondr‡n", "7 Present Querer quiero quieres quiere queremos quieren", "7 Preterito Querer quise quisiste quiso quisimos quisieron", "7 Future Querer querrŽ querr‡s querr‡ querremos querr‡n", "7 Present Saber sŽ sabes sabe sabemos x", "7 Preterito Saber supe supiste supo supimos supieron", "7 Future Saber sabrŽ sabr‡s sabremos x", "7 Conditional Saber sabr’a x x x sabr’an", "7 Present Valer valgo x vale x x", "7 Future Valer valdrŽ x x valdremos x", "7 Present Nacer nazco naces x x x", "7 Present_SUBJ Nacer nazca nazcas x x x", "7 Imperative Nacer x nace nazca x x", "7 Preterito Leer x le’ste ley— le’mos x", "7 Preterito Caer ca’ x cay— x cayeron", "7 Preterito Traer traje x trajo x x ", "7 Preterito Caber cupe x x x cupieron", "7 Present_SUBJ Poder pueda puedas pueda podamos puedan", "7 Imperative Poder x puede pueda podamos puedan", "7 Present_SUBJ Poner ponga x x pongamos pongan", "7 Present_SUBJ Querer quiera quieras x querarmos quieran", "7 Present_SUBJ Saber x sepas sepa sepamos x", "7 Present_SUBJ Valer x valgas x valgamos x", "7 Past_SUBJ Poner pusiera x x x x", "7 Past_SUBJ Poder x x pudiera pudiŽramos x", "7 Past_SUBJ Querer quisiera x x quisiŽramos x", "7 Past_SUBJ Saber supiera x x supiŽramos x", "7 Past_SUBJ Leer leyera leyeras x leyŽramos leyeran", "7 Present_PERF Poner he_puesto x ha_puesto x x", "7 Present_PERF Poder he_podido x x x x", "7 Present_PERF Querer x has_querido x x x", "7 Present_PERF Valer x x x hemos_valido x", "7 Present_PERF Leer he_le’do x x x x", "7 Present_PERF Caer x has_ca’do x x x", "7 Present_PROG Poder estoy_pudiendo x x x x", "7 Present_PROG Poner x est‡s_poniendo x x x", "7 Present_PROG Saber x x est‡_sabiendo x x", "7 Present_PROG Leer x x x x est‡n_leyendo", "7 Present_PROG Caer x x x estamos_cayendo x", // ---------------------- "8 Present Decir digo dices dice decimos dicen", "8 Preterito Decir dije dijiste dijo dijimos dijeron", "8 Future Decir dirŽ dir‡s dir‡ diremos dir‡n", "8 Conditional Decir dir’a x dir’a x dir’an", "8 Imperative Decir x di diga digamos digan", "8 Present Venir vengo vienes viene venimos vienen", "8 Preterito Venir vine viniste vino vinimos vinieron", "8 Future Venir vendrŽ vendr‡s vendr‡ vendremos vendr‡n", "8 Conditional Venir x vendr’as x vendr’amos x", "8 Present_SUBJ Venir x vengas x x x", "8 Past_SUBJ Venir x x viniera x x", "8 Present Pedir pido pides pide pedimos piden", "8 Preterito Pedir ped’ pediste pidi— pedimos pidieron", "8 Preterito Servir x x sirvi— x sirvieron", "8 Present Ir voy vas va vamos van", "8 Imperfect Ir iba ibas iba ’bamos iban", "8 Preterito Ir fui fuiste fue fuimos fueron", "8 Imperative Ir x ve vaya vayamos vayan", "8 Past_SUBJ Ir x x fuera fuŽramos x", "8 Present Oir o’go oyes oye o’mos oyen", "8 Preterito Oir o’ o’ste oy— o’mos oyeron", "8 Present_SUBJ Oir x oigas x oigamos x", "8 Imperative Oir x oye x x oigan", "8 Present Salir salgo x sale salimos x", "8 Future Salir saldrŽ saldr‡s x x x", "8 Conditional Salir saldr’a x x saldr’amos x", "8 Present_SUBJ Salir x x salga salgamos x", "8 Imperative Salir x sal x salgamos x", "8 Present Dormir duermo duermes duerme dormimos duermen", "8 Preterito Dormir dorm’ dormiste durmi— x durmieron", "8 Preterito Morir x x muri— x murieron", "8 Present_SUBJ Dormir duerma x x durmamos x", "8 Past_SUBJ Dormir durmiera x x x x", "8 Present Seguir sigo sigues sigue seguimos siguen", "8 Preterito Seguir segu’ seguiste sigui— seguimos siguieron", "8 Present_PERF Dormir he_dormido x x x x", "8 Present_PERF Ir x x x x han_ido", "8 Present_PROG Dormir estoy_durmiendo x x x x", "8 Present_PROG Venir x est‡s_viniendo x x x", "8 Present_PROG Ir x x est‡_yendo x x", // ---------------------- "9 Imperative Hacer x haz haga hagamos hagan", "10 Imperative Haber x he haya hayamos hayan" }; Entry [] Verblist; static String[] prompt = {"", " yo", " tś", " ella", "nosotros", " ellos" }; static String[] sing3 = { " Žl", " ella", " Usted" }; static String[] plur3 = { " ellos", " ellas", " Ustedes" }; int listMax = 100; Link [] list = new Link[listMax]; Link [] list2= new Link[listMax]; Link p; // the verb form being displayed String sp; int J = 0, rr = 0, n = 0, nv = 0, nv2= 0; static int maxtrials=50; // ---------------------------------------------------------------------------- void SetUp_VerbTable( ) { String s; int i; Vector l = new Vector(); for (i = 0; i< VERBS.length; i++) { Entry e = new Entry( VERBS[i], tenseTable) ; if (e.tense<9) l.addElement( e ); } Verblist = new Entry[ l.size() ] ; Enumeration e = l.elements() ; for (i = 0; i< l.size(); i++) Verblist[i] = (Entry) e.nextElement(); } // ---------------------------------------------------------------------------- void reset() { gatherErrors(); nv = n = 0; int i, j, k; Vector v = new Vector(); for (i = 0 ; i< Verblist.length; i++ ) { if ( pertinent (Verblist[i]) ) v.addElement( Verblist[i] ); } Entry [] Ea = new Entry[ v.size() ] ; i = 0; for (Enumeration e = v.elements() ; e.hasMoreElements() ; ) Ea[i++] = (Entry) e.nextElement(); for( i=0; i 30 ) { int ii = nextInt( nv-- ); n -= list[ii].cnt; System.arraycopy(list, ii+1, list, ii, nv-ii); } // for (i = 0; i< nv; i++) // System.out.println( list[i]); J = nextInt( nv ); rr = 2*J; maxtrials = n; left.repaint(); nextTurn(); accent = false; } boolean pertinent (Entry e) { int tense = e.tense, cat = e.category - cat0; if (tense >= tenseBoxes.length || cat < 0 || cat >=catBoxes.length) return false; return tenseBoxes[tense].getState() && catBoxes[cat].getState(); } void init1( String [] verb) { for (int i=1; i<6; i++) { int dn=1; if ((i==3 || i==5 ) && chance( 0.5)) dn=2; if ( ! verb[i+1].equals("x")) { if (nv>=list.length) { Link [] templ = new Link[15*list.length/10]; System.arraycopy( list, 0, templ, 0, list.length ); list = templ; templ = new Link[list.length]; System.arraycopy( list2, 0, templ, 0, list2.length ); list2 = templ; } list[nv++] = new Link(dn, i, verb); n += dn; } } } void gatherErrors() // retain entries with errors { int err; nv2=0; for (int i =0; i 0) { // System.out.println("ERR:" + list[i].form + ", " + list[i].errs); list2[ nv2++ ] = list[i]; err = list[i].errs; list[i].errs = 0; list[i].cnt = (err>2 ? 2 : err); list[i].flag=true; } } void addErrors() // retain entries with errors { for (int i =0; i0) { String s = answer.getText().trim(); if (s.indexOf("/") >= 0){ s = cleanUp(s); show(s,0.6); } if ( s.equals( p.form ) ) { p.cnt-- ; n--; if (n>0) { r = rr = (rr + 1+ nextInt( 4 )) % n; J = 0; while ( list[J].cnt==0 || r > list[J].cnt ) { r -= list[J].cnt; J++; } } answer.setText(""); left.hint = list[J].flag; nextTurn(); } else { int delta = (p.cnt>3 ? 1 : 2); p.errs++; p.cnt+=delta ; n +=delta ; show("!?!... " + p.form , 2.0); // display.show("!?!... " + p.form , 1.0); } left.repaint(); } } void nextTurn() { if (n>0) { answer.setText(""); p = list[J] ; model.setText( p.verb ); String ss = (String) tenseOUT.get(p.tense); if (ss==null) tenseHeader.setText( p.tense ); else tenseHeader.setText( ss ); Color col = (Color)tenseColor.get(p.tense); if (col==null) tenseHeader.setForeground(Color.black); else tenseHeader.setForeground(col); int prsn = p.person; if (prsn == 3) sp = sing3[ nextInt(3) ] ; else if (prsn == 5) sp = plur3[ nextInt(3) ] ; else sp = prompt[ prsn ] ; person.setText( sp ); } else { show( cheers[i_cheer] , 2.0); i_cheer = (i_cheer+1) % cheers.length ; changeLevel(); reset(); repaint(); } answer.requestFocus(); } int i_cheer = 0; String cheers [] = { "** Well done ! **", "** Excellent ! **", "** Good work! **", "** Right on Dude ! **", "** Muy bien ! **" } ; void changeLevel() { int i; int cLen = catBoxes.length, tLen = tenseBoxes.length, cMax = 0, tMax = 0; for (i=0; itLen-1) tMax=0; for (i=0; i= 0 )) { sb.append( "‡Ž’—".charAt(pos)); accent = false; } else { sb.append(c); accent = false; } } return sb.toString(); } // === For testing as an application static String ARGS[]; public static void main(String[] args) { Frame f = new Frame("Espanol") ; ARGS = args; Conjugation2 ex1 = new Conjugation2() { public String getParameter(String name) { if (ARGS.length>0 ) return ARGS[0]; else return null; } }; ex1.init(); f.add("Center", ex1); f.pack(); f.show(); // System.out.println(f.getWidth() + ", " + f.getHeight()); } static void sleep(double sec) { try { Thread.sleep((long) (1000 * sec)); } catch (InterruptedException e) {} } // ----------------------------------------------------------------- class ProgressBar extends Canvas { Dimension size = new Dimension( 40, 125 ); boolean hint = false; public void paint (Graphics page) { int h=100; if (n>maxtrials) maxtrials = n; if (maxtrials>0) h = 100*n/maxtrials; page.setColor( Color.gray ); page.fillRect( 16, 120-h, 19, h ); page.setColor( (hint ? Color.red :Color.black) ); page.drawRect( 15, 20, 20, 100 ); page.setColor( Color.black ); hint=false; } public Dimension getMinimumSize() { return size; } public Dimension getPreferredSize() { return size; } } } // ----------------------------------------------------------------- class Entry { static Random rnd = new Random(); int key ; int category, tense; String infinitive; String [] table = new String[7]; public Entry (String t, Hashtable tenses) { key = nextInt(1000); StringTokenizer st = new StringTokenizer(t); if (st.countTokens() > 8) System.out.println (t); try { category = Integer.parseInt(st.nextToken()); } catch (Exception e) {} String s = st.nextToken() ; Number num = (Number) tenses.get(s); if (num!=null) tense = num.intValue(); else tense = 9; int i=0; table[i++] = s; while (st.hasMoreTokens()) { table[i++] = st.nextToken().replaceAll("_"," "); } } public boolean matches( Checkbox[] c, Checkbox[] t) { if ( category-1 < c.length && tense < t.length && c[ category-1 ].getState() && t[ tense ].getState()) return true; else return false; } public String toString() { return category + ") " + table[1] + ": " + table[0] + " (" + key + ")" ; } static int nextInt( int n ) { return (int)(n * rnd.nextFloat()); } } // ----------------------------------------------------------------- class Link { public int cnt, errs, person; String tense, verb, form; boolean flag = false; public Link(int n, int p, String [] v) { cnt = n; errs=0; person = p; tense = v[0]; verb = v[1]; form = v[p+1]; } public String toString() { return verb + ": " + form; } } // -----------------------------------------------------------------