-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLanguageTester.java
More file actions
181 lines (141 loc) · 4.78 KB
/
LanguageTester.java
File metadata and controls
181 lines (141 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.text.Font;
import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import javafx.scene.control.Label;
import javafx.geometry.Insets;
import javafx.scene.control.TextField;
import java.util.ArrayList;
import java.io.*;
import javafx.application.Platform;
import javafx.geometry.HPos;
import java.util.Random;
public class French extends Application
{
Button button;
public static void main( String[] args )
{
launch( args );
Platform.setImplicitExit(true);
Platform.exit();
}
public void start( Stage primaryStage ) throws Exception
{
ArrayList< String > english = new ArrayList< String >();
ArrayList< String > french = new ArrayList< String >();
ArrayList< Integer > hash = new ArrayList< Integer >();
try
{
FileReader fr = new FileReader( "words.txt" );
BufferedReader br = new BufferedReader( fr );
String line = br.readLine();
while( line != null )
{
english.add( line );
line = br.readLine();
french.add( line );
line = br.readLine();
}
br.close();
fr.close();
}
catch( Exception e ){};
Random ran = new Random();
for( int i = 0; i < english.size(); i++ )
{
int x = ran.nextInt( english.size() );
while( Inside( x,hash ) )
{
x = ran.nextInt( english.size() );
}
hash.add( x );
}
Stage window = primaryStage;
window.setOnCloseRequest( new EventHandler< WindowEvent>()
{
public void handle( WindowEvent e )
{
Platform.exit();
System.exit( 0 );
Platform.setImplicitExit(true);
}
});
window.setTitle( "Language test" );
Label label = new Label( english.get( hash.get( 0 ) ) );
TextField field = new TextField();
label.setFont( new Font( "Times New Roman",55 ) );
Button button = new Button( "Check" );
Label counter = new Label( 1 + "/" + english.size() );
counter.setFont( new Font( "Times New Roman",20 ) );
Label mistakes = new Label( "Wrong: " + 0 );
mistakes.setFont( new Font( "Times New Roman",20 ) );
button.setStyle("-fx-font-size: 25pt;");
field.setPrefWidth( 500 );
button.setOnAction( new EventHandler<ActionEvent>()
{
int mistakesI = 0;
public void handle( ActionEvent e )
{
String answer = field.getText();
if( !hash.isEmpty() )
{
if( !answer.toLowerCase().equals( french.get( hash.get( 0 ) ) ) )
{
answer = field.getText();
mistakes.setText( "Wrong: " + ++mistakesI );
}
else
{
hash.remove( 0 );
field.clear();
if( !hash.isEmpty() )
{
label.setText( english.get( hash.get( 0 ) ) );
counter.setText( ( english.size() - hash.size() + 1 ) + "/" + english.size() );
}
else
{
label.setText( "FIN" );
return;
}
}
}
}
});
GridPane grid = new GridPane();
grid.setVgap( 40 );
grid.setHgap( 50 );
GridPane.setHalignment( label, HPos.CENTER );
GridPane.setHalignment( field, HPos.CENTER );
GridPane.setHalignment( button, HPos.CENTER );
GridPane.setHalignment( counter, HPos.LEFT );
GridPane.setHalignment( mistakes, HPos.LEFT );
GridPane.setConstraints( label,2,2 );
GridPane.setConstraints( field,2,4 );
GridPane.setConstraints( button,2,6 );
GridPane.setConstraints( counter,1,8 );
GridPane.setConstraints( mistakes,1,9 );
grid.getChildren().addAll( label,field,button,counter,mistakes );
Scene scene = new Scene( grid,860,600 );
window.setScene( scene );
window.show();
}
public static boolean Inside( int x,ArrayList hash )
{
boolean result = false;
for( int j = 0; j < hash.size(); j++ )
{
if( x == (int)hash.get( j ) )
{
result = true;
break;
}
}
return result;
}
}