import java.applet.*;
import java.awt.*;
import java.util.*;
import java.net.*;

public class JavaVoci extends Applet{

Button theAskButton, theSolveButton, theResetButton, theNewButton, theHelpButton;
TextField theLWord, theGenitiv, theGenus, thePVP, theDWord;
Choice theModusMenu;
Checkbox theRightCheckBox, theFalseCheckBox;
CheckboxGroup theCheckBoxGroup;
Vector 	theWords;

Label theModeText, theLLabel, theDLabel, theDWordLabel,
	  theSolutionLabel, theSolutionLText, theSolutionDText, theExerciceNum,
	  theRightText, theRightLabel, theFalseText, theFalseLabel,
	  theGenitivLabel, theGenusLabel, thePVPLabel,
	  theNumOfSolutionsText,
	  theAdditionalInfoLabel, theAdditionalInfoText,
	  theExerciceLabel, theExerciceText,
	  theHelpLabel, theHelpText;

boolean[] theUsedWords = new boolean[256];

boolean onlyShortAsk = false,
		withGenitiv = false, withPerfect = false, withPVP = false, withPraesens = false,
		withGenus = false, withAdjectivs = false, withKasus = false,
		withStammformen = false, withGenusGenitiv = false;

int theMode = 0, theExercice = 1, theWordNum = 0;

int theRightNum = 1, theFalseNum = 1, theAskNum = -2, theNumOfAskWords;

String theLSolution, theDSolution, theCurrentHelp, theLanguage;
int theAskWords[] = new int[256];

	public void init()
	{
		Word theNewWord;
		int i;
		
		this.showStatus("Das Java-Programm wird geladen, haben Sie etwas Geduld...");
		
		this.setBackground(Color.white);
		
		this.setLayout(null);

		InitParams();
		
		theAskButton = new Button("Abfrage");		// Buttons
		theAskButton.reshape(416,360,94,24);
		this.add(theAskButton);

		theSolveButton = new Button("L\u00f6sung");
		theSolveButton.reshape(309,360,94,24);
		this.add(theSolveButton);
		theSolveButton.enable(false);
		
		theNewButton = new Button("Neu");
		theNewButton.reshape(229,360,67,24);
		this.add(theNewButton);

		theResetButton = new Button("Statistik l\u00f6schen");
		theResetButton.reshape(50,360,166,24);
		this.add(theResetButton);

		theHelpButton = new Button("?");
		theHelpButton.reshape(17,360,20,24);
		this.add(theHelpButton);
		theHelpButton.enable(false);
		
		theLLabel = new Label(theLanguage.equals("Latein")?"Latein":"Griech.");			// Sprache
		theLLabel.reshape(23,42,60,18);
		this.add(theLLabel);
		
		theLWord = new TextField("");
		theLWord.reshape(93,42,287,28);
		this.add(theLWord);
		
		theGenitivLabel = new Label("");			// Genitiv
		theGenitivLabel.reshape(93,72,80,18);
		this.add(theGenitivLabel);
		
		theGenitiv = new TextField("");
		theGenitiv.reshape(183,72,197,28);
		this.add(theGenitiv);

		theGenusLabel = new Label("");				// Genus
		theGenusLabel.reshape(93,102,80,18);
		this.add(theGenusLabel);
		
		theGenus = new TextField("");
		theGenus.reshape(183,102,197,28);
		this.add(theGenus);

		thePVPLabel = new Label("");				// PVP
		thePVPLabel.reshape(93,132,80,18);
		this.add(thePVPLabel);
		
		thePVP = new TextField("");
		thePVP.reshape(183,132,197,28);
		this.add(thePVP);		

		theAdditionalInfoLabel = new Label("Zus\u00e4tze");	// Additional Info
		theAdditionalInfoLabel.reshape(93,162,80,18);
		this.add(theAdditionalInfoLabel);

		theAdditionalInfoText = new Label("");
		theAdditionalInfoText.reshape(183,162,197,18);
		this.add(theAdditionalInfoText);
		
		theHelpLabel = new Label("Hilfen");			// Hilfen
		theHelpLabel.reshape(93,182,80,18);
		this.add(theHelpLabel);

		theHelpText = new Label("");
		theHelpText.reshape(183,182,197,18);
		this.add(theHelpText);
				
		theDWordLabel = new Label("Deutsch");		// Deutsch
		theDWordLabel.reshape(23,212,60,18);
		this.add(theDWordLabel);
		
		theDWord = new TextField("");
		theDWord.reshape(93,212,287,28);
		this.add(theDWord);

		
		theNumOfSolutionsText = new Label("Anzahl Bedeutungen: ");				
		theNumOfSolutionsText.reshape(93,242,287,18);
		this.add(theNumOfSolutionsText);


		theSolutionLabel = new Label("L\u00f6sung");	// Loesung
		theSolutionLabel.reshape(23,282,60,18);
		this.add(theSolutionLabel);

		theSolutionLText = new Label("");
		theSolutionLText.reshape(93,282,287,18);
		this.add(theSolutionLText);
		theSolutionDText = new Label("");
		theSolutionDText.reshape(93,302,287,18);
		this.add(theSolutionDText);
		
		theCheckBoxGroup = new CheckboxGroup();		// Richtig oder falsch
		
		theRightCheckBox = new Checkbox("Richtig",theCheckBoxGroup, true);
		theRightCheckBox.reshape(93,327,100,18);
		this.add(theRightCheckBox);
		
		theFalseCheckBox = new Checkbox("Falsch",theCheckBoxGroup,false);
		theFalseCheckBox.reshape(203,327,100,18);
		this.add(theFalseCheckBox);
		

		theExerciceNum = new Label(String.valueOf(theExercice)+". Durchgang");		// Durchgang
		theExerciceNum.reshape(404,42,100,18);
		this.add(theExerciceNum);
		
		theRightLabel = new Label("Richtig",Label.CENTER);		// Statistik
		theRightLabel.reshape(404,82,100,18);
		theRightLabel.setForeground(Color.green);
		this.add(theRightLabel);

		theRightText = new Label("0");
		theRightText.reshape(404,102,30,18);
		theRightText.setForeground(Color.green);
		this.add(theRightText);
		
		theExerciceLabel = new Label("Verbleibend",Label.CENTER);
		theExerciceLabel.reshape(404,142,100,18);
		theExerciceLabel.setForeground(Color.orange);
		this.add(theExerciceLabel);

		theExerciceText = new Label("0");
		theExerciceText.reshape(404,162,30,18);
		theExerciceText.setForeground(Color.orange);
		this.add(theExerciceText);
		
		theFalseLabel = new Label("Falsch",Label.CENTER);
		theFalseLabel.reshape(404,202,100,18);
		theFalseLabel.setForeground(Color.red);
		this.add(theFalseLabel);

		theFalseText = new Label("0");
		theFalseText.reshape(404,222,30,18);
		theFalseText.setForeground(Color.red);
		this.add(theFalseText);
						
		theModusMenu = new Choice();					// Modus
		theModusMenu.addItem(theLanguage.substring(0,1)+" -> D");
		theModusMenu.addItem("D -> "+theLanguage.substring(0,1));
		theModusMenu.addItem(theLanguage.substring(0,1)+" <-> D");
		theModusMenu.reshape(404,276,100,28);
		this.add(theModusMenu);
								
		theWords = new Vector();
		for (i=0;((theNewWord = InitWords("wort"+i)) != null)&&(i<256); i++)
			theWords.addElement(theNewWord);
			
		
		if (theWords.size()	< 1)
		{
			this.showStatus("Keine W\u00f6rter definiert! - Abfrage nicht m\u00f6glich");
			theModeText = new Label("Keine W\u00f6rter definiert! - Abfrage nicht m\u00f6glich");
			theAskButton.enable(false);
		}	// if
		else
		{
			theModeText = new Label("W\u00e4hle 'Abfrage'!");
			this.showStatus("© by L. Hartmann");
		}	// else	

		theWordNum = theWords.size();
		theExerciceText.setText(String.valueOf(theWordNum));
		
		theModusMenu.select(theMode);
		
		theModeText.reshape(17,9,495,18);
		this.add(theModeText);
	}	// Init
	
	public void paint(Graphics g)
	{
		g.drawRect(17,36,369,230);		
		g.drawRect(17,276,369,75);
		
		g.setColor(Color.green);
		g.drawRect(398,76,112,52);

		g.setColor(Color.orange);
		g.drawRect(398,136,112,52);

		g.setColor(Color.red);
		g.drawRect(398,196,112,52);

		g.setColor(Color.black);
		g.drawRect(398,36,112,30);
			
	}	// paint
	
	public void HandleResetButton()
	{
		theRightNum = 1;
		theFalseNum = 1;
		theRightText.setText(String.valueOf(0));
		theFalseText.setText(String.valueOf(0));
	}	// HandleResetButton
	
	public void HandleNewButton()
	{
		int i;
					
		theAskNum = -2;
				
		theLWord.setText("");
		theGenitiv.setText("");
		theGenus.setText("");
		thePVP.setText("");
		theDWord.setText("");
		theHelpText.setText("");
		theNumOfSolutionsText.setText("Anzahl Bedeutungen: ");
		theWordNum = theWords.size();
		theExerciceText.setText(String.valueOf(theWordNum));
		theExerciceNum.setText("1. Durchgang");
		
		theGenitivLabel.setText("");
		theGenusLabel.setText("");
		thePVPLabel.setText("");

		theModeText.setBackground(Color.white);
		theModeText.setText("W\u00e4hle 'Abfrage'!");
		theSolutionLText.setText("");
		theSolutionDText.setText("");
		
		theSolveButton.enable(false);		
		theHelpButton.enable(false);		
		theAskButton.enable(true);	
	}	// HandleNewButton

	public void HandleAskButton()
	{
		if (!theAskButton.isEnabled())
			return;
		
		if (theAskNum == -2)
			InitAsk(true);
		else
		{
			if (theRightCheckBox.getState())
			{
				theRightText.setText(String.valueOf(theRightNum++));
				theUsedWords[theAskWords[theAskNum-1]] = true;
			}	// if
			else
			{
				theFalseText.setText(String.valueOf(theFalseNum++));
				theUsedWords[theAskWords[theAskNum-1]] = false;
				theWordNum++;
			}	// else

			if (theAskNum >= theNumOfAskWords)
				theAskNum = -1;
							
			if (theAskNum == -1)
			{
				int i, theNumOfUsedWords = 0;
				
				for (i=0;i<256;i++)
				{
					if (theUsedWords[i])
						theNumOfUsedWords++;
				}	// for
								
				if (theNumOfUsedWords >= theWords.size())
				{
					theModeText.setBackground(Color.yellow);
					theModeText.setText("Gratuliere! Du hast die \u00dcbung erf\u00fcllt!");
					theSolveButton.enable(false);		
					theHelpButton.enable(false);
					theAskButton.enable(false);			
					return;
				}	// else
				else
					InitAsk((theNumOfUsedWords >= theWords.size()));
			}	// if
		
		}	// else

		theWordNum--;
		theExerciceText.setText(String.valueOf(theWordNum));			
		DisplayAsk();
		
		theSolveButton.enable(true);		
		theHelpButton.enable(!theCurrentHelp.equals(""));
		theAskButton.enable(false);			
	}	// HandleAskButton
	
	public void HandleSolveButton()
	{
		if (!theSolveButton.isEnabled())
			return;

		DisplaySolution();
		
		if (theAskNum >= theNumOfAskWords)
			theModeText.setText("Der " + String.valueOf(theExercice) + ". Durchgang ist beendet, w\u00e4hle 'Abfrage'!");
		else
			theModeText.setText("W\u00e4hle 'Abfrage'!");
			
		theSolveButton.enable(false);
		theHelpButton.enable(false);		
		theAskButton.enable(true);
	}	// HandleSolveButton
		
	public boolean keyDown(Event theEvent, int theKey)
	{
		if ((theEvent.id == Event.KEY_PRESS)&&(theKey == '\n'))
		{
			if (theAskButton.isEnabled())
				HandleAskButton();
			else
				HandleSolveButton();
			return true;
		}	// if

		return false;
	}	// key
	
	public boolean action(Event theEvent, Object arg)
	{
		if (theEvent.target == theAskButton)
		{
			HandleAskButton();
			return true;
		}	// if
		else if (theEvent.target == theSolveButton)
		{
			HandleSolveButton();
			return true;
		}	// else
		else if (theEvent.target == theResetButton)
		{
			HandleResetButton();
			return true;
		}	// else		
		else if (theEvent.target == theNewButton)
		{
			HandleNewButton();
			return true;
		}	// else		
		else if (theEvent.target == theHelpButton)
		{
			theHelpText.setText(theCurrentHelp);
			return true;
		}	// else		
		return false;
	}	// action
	
	public boolean CheckDSolution(Word theWord)
	{
		String theSolution = theDWord.getText();
		String theSolutions[] = new String[4];
		boolean isRight[] = {false, false, false, false, true};
		int i, j, k;
		
		if (withStammformen||withGenusGenitiv)
			isRight[4] = CheckLSolution(theWord);
		
		StringTokenizer theTokenizer = new StringTokenizer(theSolution,",");
		
		for (i=0;i<4;i++)
		{
			try
			{
				theSolutions[i] = theTokenizer.nextToken();
			}	// try
			catch (NoSuchElementException e)	{break;}
		}	// for
		
		for (j=0;j<i;j++)
			theSolutions[j] = theSolutions[j].trim();
		
		for (j=theWord.theNumOfTraductions;j<4;j++)
			isRight[j] = true;
		
		for (j=0;j<i;j++)
		{
			for (k=0;k<theWord.theNumOfTraductions;k++)
			{
				if (theSolutions[j].equalsIgnoreCase(theWord.theTraductions[k]))
					isRight[k] = true;
			}	// for
		}	// for
		
		return isRight[0] && isRight[1] && isRight[2] && isRight[3] && isRight[4];		
	}	// CheckDSolution
	
	public boolean CheckLSolution(Word theWord)
	{
		String theNominativText = theLWord.getText().trim();
		
		if (onlyShortAsk)
			return theNominativText.equals(theWord.theNominativ);
			
		String theGenitivText = (theGenitivLabel.getText().equals("-")?"":theGenitiv.getText().trim());
		String theGenusText = (theGenusLabel.getText().equals("-")?"":theGenus.getText().trim());
		if (!theGenusText.equals(""))
		{
			if (theGenusText.charAt(theGenusText.length()-1) == '.')
				theGenusText = theGenusText.substring(0,theGenusText.length()-1);
		}	// if
		
		String thePVPText = (thePVPLabel.getText().equals("-")?"":thePVP.getText().trim());
		
		// Kurzformen
		// Substantive: us, i; a, ae; us, us; um, i; es, ei
		// Verben: o, io, eo; avi, ivi; atum; itum
		// Adjektive: a, um	
		
		if (theWord.theType.equals("s"))
		{
			if (theGenitivText.equals("i")||theGenitivText.equals("us")||
				theGenitivText.equals("ei"))
				theGenitivText = theNominativText.substring(0,theNominativText.length()-2)+theGenitivText;
			else if (theGenitivText.equals("ae"))
				theGenitivText = theNominativText.substring(0,theNominativText.length()-1)+"ae";
		}	// if
		else if (theWord.theType.equals("v"))
		{
			if (theGenitivText.equals("o")||theGenitivText.equals("io")||
				theGenitivText.equals("eo"))
				theGenitivText = theNominativText.substring(0,theNominativText.length()-3)+theGenitivText;
			if (theGenusText.equals("avi")||theGenusText.equals("ivi"))
				theGenusText = theNominativText.substring(0,theNominativText.length()-3)+theGenusText;
			if (thePVPText.equals("atum")||thePVPText.equals("itum"))
				thePVPText = theNominativText.substring(0,theNominativText.length()-3)+thePVPText;			
		}	// else if
		else if (theWord.theType.equals("a"))
		{
			if (theGenitivText.equals("a"))
				theGenitivText = theNominativText.substring(0,theNominativText.length()-2)+"a";
			if (theGenusText.equals("um"))
				theGenusText = theNominativText.substring(0,theNominativText.length()-2)+"um";		
		}	// else if
		
		return  theNominativText.equals(theWord.theNominativ)&&
				theGenitivText.equals(theWord.theGenitiv)&&
				theGenusText.equals(theWord.theGenus)&&
				thePVPText.equals(theWord.thePVP);
	}	// CheckLSolution
		
	public void DisplaySolution()
	{
		Word theWord;
		
		theSolutionLText.setText(theLSolution);
		theSolutionDText.setText(theDSolution);

		theWord = GetWord(theAskWords[theAskNum]);
		
		if (theMode == 0)
		{
			if (CheckDSolution(theWord))
			{
				theRightCheckBox.setState(true);
				theFalseCheckBox.setState(false);			
			}	// if
			else
			{
				theRightCheckBox.setState(false);
				theFalseCheckBox.setState(true);						
			}	// else
		}	// if
		else
		{
			
			if (CheckLSolution(theWord))
			{
				theRightCheckBox.setState(true);
				theFalseCheckBox.setState(false);						
			}	// if
			else
			{
				theRightCheckBox.setState(false);
				theFalseCheckBox.setState(true);			
			}	// else
		}	// else

		theAskNum++;

		theRightCheckBox.show();
		theFalseCheckBox.show();
		
	}	// DisplaySolution
	
	public void DisplayAsk()
	{
		Word theWord;
		int i;
		boolean displayLabels;
		
		theSolutionLText.setText("");
		theSolutionDText.setText("");
		theHelpText.setText("");
		
		if (theAskNum >= theNumOfAskWords)
			return;
					
		if (theModusMenu.getSelectedIndex() == 0)
			theMode = 0;
		else if (theModusMenu.getSelectedIndex() == 1)
			theMode = 1;
		else
			theMode = GetRandomNumber(new Random(), 2);
		
		theWord = GetWord(theAskWords[theAskNum]);
		if (theWord == null)
			return;

		theCurrentHelp = theWord.theHelp;
		theNumOfSolutionsText.setText("Anzahl Bedeutungen: "+String.valueOf(theWord.theNumOfTraductions));
		theAdditionalInfoText.setText(theWord.theAdditionalInfo);
		
		theDSolution = theWord.theTraductions[0];
		for (i=1;i<theWord.theNumOfTraductions;i++)
			theDSolution += ", " + theWord.theTraductions[i];

		if (onlyShortAsk)
			theLSolution = theWord.theNominativ;
		else if (theWord.theType.equals("v"))
			theLSolution = theWord.theNominativ
							  + ((withPraesens&&!theWord.theGenitiv.equals(""))?", " + theWord.theGenitiv:"")
							  + ((withPerfect&&!theWord.theGenus.equals(""))?", " + theWord.theGenus:"")
							  + ((withPVP&&!theWord.thePVP.equals(""))?", " + theWord.thePVP:"");
		else if (theWord.theType.equals("x"))
			theLSolution = theWord.theNominativ;
		else if (theWord.theType.equals("p"))
			theLSolution = theWord.theNominativ
							  + (withKasus?" + " + theWord.theGenitiv + ".":"");
		else if (theWord.theType.equals("s"))
			theLSolution = theWord.theNominativ
							  + ((withGenitiv&&!theWord.theGenitiv.equals(""))?", " + theWord.theGenitiv:"")
							  + ((withGenus&&!theWord.theGenus.equals(""))?" " + theWord.theGenus + ".":"");
		else if (theWord.theType.equals("d"))
			theLSolution = theWord.theNominativ
						 	  + ((withPraesens&&!theWord.theGenitiv.equals(""))?", " + theWord.theGenitiv:"")
						 	  + ((withPVP&&!theWord.theGenus.equals(""))?", " + theWord.theGenus:"");
		else	// Adjektive
			theLSolution = theWord.theNominativ
							  + ((withAdjectivs&&!theWord.theGenitiv.equals(""))?", " + theWord.theGenitiv + ", " +
					 	  		 theWord.theGenus:"");
					 	  		 
		if (onlyShortAsk&&(theMode == 1))
		{
			theGenitivLabel.setText("-");
			theGenusLabel.setText("-");
			thePVPLabel.setText("-");
		}	// if	
		else if (theWord.theType.equals("v"))
		{
			theGenitivLabel.setText(((withPraesens&&!theWord.theGenitiv.equals(""))?(theLanguage.equals("Latein")?"1.Sg.":"Futur"):"-"));
			theGenusLabel.setText(((withPerfect&&!theWord.theGenus.equals(""))?(theLanguage.equals("Latein")?"Perf.":"Aor."):"-"));
			thePVPLabel.setText(((withPVP&&!theWord.thePVP.equals(""))?(theLanguage.equals("Latein")?"PVP":"Aor. pass."):"-"));		
		}	// if
		else if (theWord.theType.equals("x"))
		{
			theGenitivLabel.setText("-");
			theGenusLabel.setText("-");
			thePVPLabel.setText("-");
		}	// else if
		else if (theWord.theType.equals("p"))
		{
			theGenitivLabel.setText((withKasus?"Kasus":"-"));
			theGenusLabel.setText("-");
			thePVPLabel.setText("-");				
		}	// else if
		else if (theWord.theType.equals("s"))
		{
			theGenitivLabel.setText(((withGenitiv&&!theWord.theGenitiv.equals(""))?"Gen.":"-"));
			theGenusLabel.setText(((withGenus&&!theWord.theGenus.equals(""))?"Genus":"-"));
			thePVPLabel.setText("-");
		}	// else if
		else if (theWord.theType.equals("d"))
		{
			theGenitivLabel.setText(((withPraesens&&!theWord.theGenitiv.equals(""))?(theLanguage.equals("Latein")?"1.Sg.":"Futur"):"-"));
			theGenusLabel.setText(((withPVP&&!theWord.theGenus.equals(""))?(theLanguage.equals("Latein")?"PVP":"Aor."):"-"));
			thePVPLabel.setText("-");								
		}	// else if
		else
		{
			theGenitivLabel.setText(((withAdjectivs&&!theWord.theGenitiv.equals(""))?"f.":"-"));
			theGenusLabel.setText(((withAdjectivs&&!theWord.theGenus.equals(""))?"n.":"-"));
			thePVPLabel.setText("-");		
		}	// else
		
		if (theMode == 0)		// Lt. -> Dt.
		{						
			theLWord.setText(theWord.theNominativ);
			if (((theWord.theType.equals("s"))&&(!withGenitiv||withGenusGenitiv))||
				((theWord.theType.equals("v")&&(!withPraesens||withStammformen)))||
				((theWord.theType.equals("d")&&(!withPraesens||withStammformen)))||
				((theWord.theType.equals("p")&&(!withKasus)))||
				((theWord.theType.equals("a")&&(!withAdjectivs))))
				theGenitiv.setText("");
			else
				theGenitiv.setText(theWord.theGenitiv);

			if ((withPerfect&&!withStammformen&&(theWord.theType.equals("v")))||
				(withPVP&&!withStammformen&&(theWord.theType.equals("d")))||
				(withGenus&&!withGenusGenitiv&&(theWord.theType.equals("s")))||
				(withAdjectivs&&(theWord.theType.equals("a"))))
				theGenus.setText(theWord.theGenus);
			else
				theGenus.setText("");
				
			if (withPVP&&!withStammformen&&(theWord.theType.equals("v")))
				thePVP.setText(theWord.thePVP);
			else
				thePVP.setText("");
				
			theDWord.setText("");
			theDWord.selectAll();
			theModeText.setText("\u00dcbersetze ins Deutsche!");
		}	// if
		else					// Dt. -> Lt.
		{				
			theDWord.setText(theDSolution);
			
			theLWord.setText("");
			theGenitiv.setText("");
			theGenus.setText("");
			thePVP.setText("");
			
			theLWord.selectAll();			
			theModeText.setText("\u00dcbersetze ins "+theLanguage+"!");
		}	// else
		
		theRightCheckBox.hide();
		theFalseCheckBox.hide();
	}	// DisplayAsk
	
	public int GetRandomNumber(Random theRandom, int theRange)
	{
		return (Math.abs(theRandom.nextInt()))%(theRange);
	}	// GetRandomNumber
	
	public void InitAsk(boolean resetAll)
	{
		int i, j, theNumOfWords;
		Random theRandom = new Random();
		int x;

		theNumOfAskWords = 0;
				
		if (resetAll)
		{
			for (i=0;i<256;i++)
				theUsedWords[i] = false;
				
			theExercice = 1;
		}	// if
		else
			theExercice++;
			
		theExerciceNum.setText(String.valueOf(theExercice)+". Durchgang");
		
		theSolutionLText.setText("");
		theSolutionDText.setText("");
		theHelpText.setText("");
		theExerciceText.setText(String.valueOf(theWords.size()));
		
		theNumOfWords = theWords.size();
		
		for (i=0;i<256;i++)
		{
			if (theUsedWords[i])
				theNumOfWords--;
		}	// for
		
		for (i=theNumOfWords;i>0;i--)
		{
			x = GetRandomNumber(theRandom,i);
			
			for (j=0;j<=x;j++)
			{
				if (theUsedWords[j])
					x++;
			}	// for

			theAskWords[theNumOfAskWords++] = x;
			theUsedWords[x] = true;
		}	// for
		
		theAskNum = 0;
	}	// InitAsk
	
	public boolean GetParameter(String theParamName)
	{
		String theParam = this.getParameter(theParamName);

		if (theParam != null)
		{		
			try
			{
				StringTokenizer theString = new StringTokenizer(theParam,",");
				String theValue = theString.nextToken();
			
				return (theValue.equalsIgnoreCase("on"));
			}	// try
			catch (NoSuchElementException e)	{return false;}
		}	// if
		
		return false;
	
	}	// GetParameter
				
	public void InitParams()
	{
		String theParam = this.getParameter("modus");

		if (theParam != null)
		{		
			try
			{
				StringTokenizer theString = new StringTokenizer(theParam,",");
				String theNewMode= theString.nextToken();
			
				if (theNewMode.equalsIgnoreCase("ld"))
					theMode = 0;
				else if (theNewMode.equalsIgnoreCase("dl"))
					theMode = 1;
				else
					theMode = 2;
			}	// try
			catch (NoSuchElementException e)	{theMode = 0;}
		}	// if
		else
			theMode = 0;

		theParam = this.getParameter("sprache");

		if (theParam != null)
		{		
			try
			{
				StringTokenizer theString = new StringTokenizer(theParam,",");
				String theNewLanguage= theString.nextToken();
			
				if (theNewLanguage.equalsIgnoreCase("griechisch"))
					theLanguage = "Griechisch";
				else
					theLanguage = "Latein";
			}	// try
			catch (NoSuchElementException e)	{theLanguage = "Latein";}
		}	// if
		else
			theLanguage = "Latein";

		onlyShortAsk = GetParameter("kurzabfrage");
		withStammformen = GetParameter("stammformen");
		withGenusGenitiv = GetParameter("genus/genitiv");
		
		withGenitiv = GetParameter("genitiv");
		withGenus = GetParameter("genus");
		withAdjectivs = GetParameter("adjektiv");
		withPraesens = GetParameter("praesens");
		withPerfect = GetParameter("perfekt");
		withPVP = GetParameter("PVP");
		withKasus = GetParameter("kasus");
	}	// InitParams
	
	public Word InitWords(String theParamName)
	{
		String theType, theNom, theGenitiv = "", theGenus = "", thePVP = "", theNumString;
		StringTokenizer theParams;
		String the1Traduction = "", the2Traduction = "", the3Traduction = "", the4Traduction = "";
		String theAdditionalInformation = "";
		String theHelp = "";
		int theNumOfTraductions;
				
		String theParam = this.getParameter(theParamName);
		if (theParam == null)	return null;
		
		try
		{
			theParams = new StringTokenizer(theParam,",");
			theType = theParams.nextToken().trim();
			theNom = theParams.nextToken().trim();
			
			if (!(theType.equals("x")))
			{
				theGenitiv = theParams.nextToken().trim();
				if ((theType.equals("p")&&!withKasus)||
					(theType.equals("s")&&!withGenitiv)||
					(theType.equals("a")&&!withAdjectivs)||
					(theType.equals("v")&&!withPraesens)||
					(theType.equals("d")&&!withPraesens))
					theGenitiv = "";

				if (!theType.equals("p"))
				{
					theGenus = theParams.nextToken().trim();
					
					if ((theType.equals("s")&&!withGenus)||
						(theType.equals("a")&&!withAdjectivs)||
						(theType.equals("v")&&!withPerfect)||
						(theType.equals("d")&&!withPVP))
						theGenus = "";
					
					if (theType.equals("v"))
					{
						thePVP = theParams.nextToken().trim();
						if (!withPVP)
							thePVP = "";
					}	// if
				}	// if
			}	// if
			
			theNumString = theParams.nextToken().trim();
		}	// try
		catch (NoSuchElementException e)	{return null;}
		
		try
		{
			theNumOfTraductions = Integer.parseInt(theNumString);
		}	// try
		catch (NumberFormatException e)		{return null;}
		
		try
		{
			the1Traduction = theParams.nextToken().trim();
			if (theNumOfTraductions > 1)
			{
				the2Traduction = theParams.nextToken().trim();
				if (theNumOfTraductions > 2)
				{
					the3Traduction = theParams.nextToken().trim();
					if (theNumOfTraductions > 3)
						the4Traduction = theParams.nextToken().trim();
				}	// if
			}	// if
		}	// try
		catch (NoSuchElementException e)	{return null;}
		
		try
		{
			theAdditionalInformation = theParams.nextToken().trim();
		}	// try
		catch (NoSuchElementException e)	{theAdditionalInformation = "";}

		while (true)
		{
			try
			{
				theHelp = theHelp + (theHelp==""?"":", ") + theParams.nextToken().trim();
			}	// try
			catch (NoSuchElementException e)	{break;}
		}	// while

		
		return new Word(theType,theNom, theGenitiv, theGenus, thePVP, theNumOfTraductions,
						the1Traduction,the2Traduction,the3Traduction,the4Traduction,
						theAdditionalInformation, theHelp);
	}	// InitWords
	
	public Word GetWord(int i)
	{
		if (i > theWords.size())
			return null;
			
		return ((Word)(theWords.elementAt(i)));
	}	// GetWord
		
	static class Word
	{
		String theType, theNominativ, theGenitiv, theGenus, thePVP;
		String theTraductions[] = new String[4];
		String theAdditionalInfo, theHelp;
		int theNumOfTraductions;

		public Word(String theNewType, String theNewNom, String theNewGenitiv, String theNewGenus,
					String theNewPVP, int theNewNumOfTraductions, String the1Traduction,
					String the2Traduction, String the3Traduction, String the4Traduction,
					String theNewAdditionalInfo, String theNewHelp)
		{
			theType = theNewType;
			theNominativ = theNewNom;
			theGenitiv = theNewGenitiv;
			theGenus = theNewGenus;
			thePVP = theNewPVP;
			theNumOfTraductions = theNewNumOfTraductions;
			theTraductions[0] = the1Traduction;
			theTraductions[1] = the2Traduction;
			theTraductions[2] = the3Traduction;
			theTraductions[3] = the4Traduction;
			theAdditionalInfo = theNewAdditionalInfo;
			theHelp = theNewHelp;
		}	// Word - Init
	}	// Word
		
}	// JavaVoci