-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJapanese.java
More file actions
315 lines (299 loc) · 9.67 KB
/
Japanese.java
File metadata and controls
315 lines (299 loc) · 9.67 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
package japanese;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Collections;
import java.io.IOException;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.awt.Font;
import java.io.File;
import java.util.NoSuchElementException;
public class Japanese extends JFrame {
static LinkedList<Slova> slovv = new LinkedList<>();
static LinkedList<Slova> slovosh = new LinkedList<>();
public static Font font = new Font("Calibri", 0, 15);
public static Font japFt;
public static void main (String [] args){
Japanese jp = new Japanese();
jp.setVisible(true);
}
public static void reader(String put) throws Exception{
LinkedList<Slova> slova = new LinkedList<>();
slovv.clear();
slovosh.clear();
try{
Reader unicodeFileReader = new InputStreamReader(new FileInputStream(put), "UTF-8");
StringBuilder out = new StringBuilder();
char[] buf = new char[10000];
int rsz = unicodeFileReader.read(buf, 0, buf.length);
out.append(buf, 0, rsz);
String[] opa = out.toString().split("\n");
for(int i = 0; i<opa.length ; i++){
String line = opa[i];
if(line.contains("<Slova ")){
String[] elem = line.split(" ");
String[] elemnew = line.split("\"");
String imi = "abstractt";
String yomi = "abstractt";
String kanji = "abstractt";
imi = elemnew[1];
yomi = elemnew[3];
kanji = elemnew[5];
System.out.println(imi + " " + yomi + " " + kanji);
slova.add(new Slova(imi, yomi, kanji));
}
}
}
catch(IOException e){
System.out.println("не найден файл");
}
Collections.sort(slova);
slovv.addAll(slova);
slovosh.addAll(slova);
numb = slovv.size();
}
static int numb;
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("Уровень");
JMenu standart = new JMenu("standart");
JMenu settings = new JMenu("Настройки");
JMenu exitM = new JMenu("Exit");
JButton button = new JButton("Дальше");
JButton button2 = new JButton("Не верно");
JMenuItem exit = new JMenuItem("Exit");
JMenuItem n5 = new JMenuItem("N5");
JMenuItem n4 = new JMenuItem("N4");
JMenuItem n3 = new JMenuItem("N3");
JMenuItem n2 = new JMenuItem("N2");
JMenuItem pn5 = new JMenuItem("N5");
JMenuItem pn4 = new JMenuItem("N4");
JMenuItem pn3 = new JMenuItem("N3");
JMenuItem pn2 = new JMenuItem("N2");
JMenuItem userrmenu = new JMenuItem("Персональзировать уровни");
JLabel label = new JLabel("<html>Выберите уровень</html>", JLabel.CENTER);
JLabel chtenie = new JLabel("Уровень -> *lvl*");
int kolosh = 0;
int vsego;
static String put;
public Japanese(){
super("Тест иероглифы");
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int locationX = (screenSize.width - 300) / 2;
int locationY = (screenSize.height - 200) / 2;
this.setBounds(locationX, locationY,300,200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setJMenuBar(menuBar);
//UserEditMenu usermenu/* = new UserEditMenu()*/;
try{
japFt = Font.createFont(Font.TRUETYPE_FONT, new File("japanese/yugothil.ttf"));
japFt = japFt.deriveFont(Font.BOLD, 18);
}catch(Exception e){e.printStackTrace();}
//label.setFont(msgothic);
menuBar.add(fileMenu);
menuBar.add(settings);
menuBar.add(exitM);
exitM.add(exit);
fileMenu.add(standart);
standart.add(n5);
standart.add(n4);
standart.add(n3);
standart.add(n2);
fileMenu.add(pn5);
fileMenu.add(pn4);
fileMenu.add(pn3);
fileMenu.add(pn2);
settings.add(userrmenu);
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
userrmenu.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//this.setVisible(false);
UserEditMenu usermenu = new UserEditMenu();
usermenu.setVisible(true);
}
});
n4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
put = "japanese/slova4.xml";
actformenu(put);
}
});
n5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
put = "japanese/slova5.xml";
actformenu(put);
}
});
n3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
put = "japanese/slova3.xml";
actformenu(put);
}
});
n2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
put = "japanese/slova2.xml";
actformenu(put);
}
});
pn4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
put = "japanese/userEditor4.xml";
actformenu(put);
}
});
pn5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
put = "japanese/userEditor5.xml";
actformenu(put);
}
});
pn3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
put = "japanese/userEditor3.xml";
actformenu(put);
}
});
pn2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
put = "japanese/userEditor2.xml";
actformenu(put);
}
});
Container container = this.getContentPane();
container.setLayout(new GridLayout(2,2));
container.add(label);
container.add(chtenie);
label.setFont(font);
chtenie.setFont(font);
button.setFont(font);
button2.setFont(font);
button.addActionListener(new ButtonEventListener());
button2.addActionListener(new ButtonEventListener2());
container.add(button);
container.add(button2);
}
void actformenu(String option){
//put = "japanese/slova2.xml";
//System.out.println(option);
try{
reader(option);
} catch(Exception ex){}
System.out.println(slovv);
try{
label.setText(slovv.getFirst().imi);
chtenie.setText(slovv.getFirst().yomi);
chtenie.setFont(japFt);
slovv.removeFirst();
}catch(NoSuchElementException exex){label.setText("nea");exex.printStackTrace();}
}
class ButtonEventListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (slovv.size() != 0){
label.setText("<html>" + slovv.getFirst().imi + "</html>");
chtenie.setText(slovv.getFirst().yomi);
slovv.removeFirst();
}
else {
String message = "Количество ошибок: " + kolosh + " из " + numb + " ";
for (Slova a : slovosh){
message += a.getKanji() + " ";
}
String[] mess = message.split(" ");
for (int i = 4; i < mess.length; i+=12){
mess[i] = mess[i] + "\n";
}
String[] viviv = String.join(" ",mess).split("\n");
JLabel[] vivods = new JLabel[viviv.length];
JLabel ftfirst = new JLabel(viviv[0]);
vivods[0] = ftfirst;
ftfirst.setFont(font);
for(int i = 1; i<viviv.length; i++){
JLabel ft = new JLabel(viviv[i]);
ft.setFont(japFt);
vivods[i] = ft;
}
chtenie.setFont(font);
slovosh.clear();
kolosh = 0;
label.setText("Выберите уровень");
chtenie.setText("Уровень -> *lvl*");
JOptionPane.showMessageDialog(null,
vivods,
"Результат",
JOptionPane.PLAIN_MESSAGE);
}
}
}
class ButtonEventListener2 implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (slovv.size() != 0){
label.setText("<html>" + slovv.getFirst().imi + "</html>");
chtenie.setText(slovv.getFirst().yomi);
slovv.removeFirst();
kolosh = kolosh + 1;
}
else {
kolosh = kolosh + 1;
String message = "Количество ошибок: " + kolosh + " из " + numb + " ";
for (Slova a : slovosh){
message += a.getKanji() + " ";
}
String[] mess = message.split(" ");
for (int i = 4; i < mess.length; i+=12){
mess[i] = mess[i] + "\n";
}
String[] viviv = String.join(" ",mess).split("\n");
JLabel[] vivods = new JLabel[viviv.length];
for(int i = 0; i<viviv.length; i++){
JLabel ft = new JLabel(viviv[i]);
ft.setFont(japFt);
vivods[i] = ft;
}
slovosh.clear();
kolosh = 0;
label.setText("Выберите уровень");
chtenie.setText("Уровень -> *lvl*");
JOptionPane.showMessageDialog(null,
vivods,
"Результат",
JOptionPane.PLAIN_MESSAGE);
}
}
}
}
class Slova implements Comparable<Slova>{
String imi;
String yomi;
String kanji;
public Slova(String imi, String yomi, String kanji){
this.imi = imi;
this.yomi = yomi;
this.kanji = kanji;
}
public String getKanji(){
return this.kanji;
}
public String getImi(){
return this.imi;
}
public String getYomi(){
return this.yomi;
}
@Override
public int compareTo(Slova odin){
int i = (int)Math.round(Math.random()*50 - 25);
return i;
}
@Override
public String toString(){
return imi;
}
}