import javax.swing.*;
import java.awt.Graphics;
import java.awt.event.*;
import java.applet.*;
public class Vokabeltrainerzusammen
extends Applet
implements ActionListener, ItemListener // 2do Erklärung, fehler, warum es anhält
{
public String[] D = new String [1901];
public String [] E = new String [1901];
public String [] Z = new String [1901];
public int [] gesamt = new int [1901];
public int [] richtig = new int [1901];
public int auswahlidex [] = new int [20];
public String [] ausgewaehlt = new String [20];
public String verzweiflung;
public List LektionenListe;
public String [] LektionenName = {"100","200","300","400","500","600","700","800","900","1000","1100","1200","1300","1400","1500","1600","1700","1800","1900","2000"};
public Panel p1,p2,p3,p4;
public TextField tf;
public Label tfalt;
public Label tfvon;
public JTextArea taZ;
private final static String newline = "\n";
public Label balt;
public Button b;
public int n;
public int i;
public int j;
public double prozentsatz;
public boolean Abfrage;
public boolean praep;
public double random;
public String[] izukette = new String [20];
public static int zahl(){
double d;
int m;
d=Math.random();
m=(int)(1+1901*d);
return m;
}
public boolean Tippfehler(String v1, String v2){
int treffer= 0;
for(int i=0; i<v1.length()&& i<v2.length(); i++){
if(v1.charAt(i) == v2.charAt(i)) treffer+= 1;
if(v1.length()== 0) treffer = treffer-1;
}
return (treffer>= 0.5*v2.length());
}
public void init()
{
setBackground(Color.orange);
// ...Vokabeln ...
n = zahl();
gesamt[n] = gesamt[n]+1;
tf = new TextField("??", 110);
b = new Button(" "+D[n]+" ");
balt = new Label(" ");
tfalt = new Label(" ");
tfvon = new Label("Von 0 abgefragten Vokabeln hast du 0 richtig!");
taZ = new JTextArea(10, 30);
taZ.setEditable(false);
taZ.setLineWrap(true);
taZ.setWrapStyleWord(true);
tf.addActionListener(this);
p1 = new Panel();
p1.setLayout(new GridLayout(1,2));
p1.add(balt);
p1.add(tfalt);
add(p1);
p2 = new Panel();
p2.setLayout(new GridLayout(2,1));
p2.add(b);
p2.add(tf);
add(p2);
p3 = new Panel();
p3.setLayout(new GridLayout(1,2));
p3.add(taZ);
p3.add(tfvon);
add(p3);
LektionenListe = new List( 21, true );
LektionenListe.addItemListener(this);
for ( int i = 0; i < LektionenName.length; i++ )
{
LektionenListe.add( LektionenName[ i ] );
}
add( LektionenListe );
}
public void actionPerformed(ActionEvent event)
{
String s1 = E[n];
String s2 = "Eingabe";
String s3 = "RICHTIG";
String s4 = "FALSCH";
String s5 = "Ausgabe";
String s6 = "Tippfehler";
String s7 = "to vergessen";
String s8 = "Groß - und Kleinschreibung";
String s9 = "Präposition bzw. unregelmäßige Verbformen in Klammern vergessen";
String vgl = "";
if (event.getSource() == tf){
s2 = tf.getText();
boolean b1 = E[n].equals(s2);
if (b1 == true) {
richtig[n] = richtig[n]+1;
s5 = s3;
tfalt.setBackground(Color.green);
}
if (b1 == false){
s5 = s4;
if (Tippfehler(s2,E[n])== true) s5 = s6; //TIPPFEHLER
boolean to1;
boolean to2;
to1 = E[n].startsWith("to");
to2 = s2.startsWith("to");
vgl = E[n].substring(3);
if(to1 == true && to2 == false && vgl.equals(s2) == true) s5 = s7; //TO VERGESSEN
if(E[n].equalsIgnoreCase(s2)== true && b1 == false) s5=s8; // GROß - UND KLEINSCHREIBUNG
boolean praep1;
boolean praep2;
praep1 = E[n].endsWith(")");
praep2 = s2.endsWith(")");
if(praep1 == true && praep2 == false )s5 = s9; //PRÄPOSTION BZW. UNREG. VERBFORM VERGESSEN
if(s2.length() == 0)s5=s4; //WENN GAR NICHTS EINGEGEBEN
tfalt.setBackground(Color.red);
}
tfalt.setText(D[n]+" = "+E[n]);
balt.setText(""+s5);
i = i+1;
if (b1 == true){
j = j+1;
}
tfvon.setText("Von "+i+" abgefragten Vokabeln hast du "+j+" richtig!");
taZ.setText("");
taZ.append(""+Z[n]);
tf.selectAll();
n = zahl();
Abfrage = false;
if (gesamt[n] == 0)Abfrage = true;
while (Abfrage == false){
prozentsatz = richtig[n]/gesamt[n];
random = Math.random();
if (prozentsatz <= random)Abfrage = true;
if (Abfrage == false)n = zahl();
}
gesamt[n] = gesamt[n]+1;
b.setLabel(""+D[n]);
}
/*else if (event.getSource() == LektionenListe){
} */
}
public void itemStateChanged( ItemEvent e )
{
//noch keine Ahnung, wie ich das machen soll....
}
}
cu azur