[JAVA] Outil d'étude des langues 2.0

//add function that if you double click then search the word by google package jp.co.learn.dict;

import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.Font; import java.awt.Point; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.lang.reflect.Method; import java.nio.charset.StandardCharsets; import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Enumeration; import java.util.List; import java.util.Properties;

import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.UIManager; import javax.swing.plaf.FontUIResource;

public class LearnWords extends JFrame implements ActionListener, KeyListener, Runnable {

static final long serialVersionUID = 1L;
static LearnWords frame;
JLabel label;
int sec;
JPopupMenu menubar = new JPopupMenu();
static List<String> wordList = new ArrayList<String>();
String filename = "";
MouseEvent start;
int intTime = 1000;
int intRight = 40;
int intDown = 20;
int CONTENT_LABEL_HEIGHT = 25;
String MODE_AUTO = "AUTO";
Properties properties;

public static void main(String[] args) throws Exception {

	System.setProperty("awt.useSystemAAFontSettings", "on");
	System.setProperty("swing.aatext", "true");
	try {

// Systématique UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } // Toutes les polices locales utilisées en bas initGlobalFontSetting (nouvelle police ("Meirio", 0, 12));

	frame = new LearnWords();
	

}

public LearnWords() {
	addKeyListener(this);
	sec = 0;

JMenu menu1 = nouveau JMenu ("texte"); JMenu menu2 = nouveau JMenu ("accidentel"); JMenu menu3 = nouveau JMenu ("time"); JMenu menu4 = nouveau JMenu ("langue japonaise"); JMenu menu5 = nouveau JMenu ("Kanshu"); JMenu menu6 = new JMenu("help");

	menubar.add(menu1);
	menubar.add(menu2);
	menubar.add(menu3);
	menubar.add(menu4);
	menubar.add(menu5);
	menubar.add(menu6);

JMenuItem menuitem1_2 = nouveau JMenuItem ("Ouvrir");

JMenuItem menuitem2_1 = new JMenuItem ("Démarrer à tout moment"); JMenuItem menuitem2_2 = new JMenuItem ("Fin des temps");

JMenuItem menuitem3_1 = nouveau JMenuItem ("time +"); JMenuItem menuitem3_2 = nouveau JMenuItem ("time-");

JMenuItem menuitem4_1 = new JMenuItem ("Dictionnaire des critères de question du test de compétence japonais-N1"); JMenuItem menuitem4_2 = new JMenuItem ("Dictionnaire des critères de question du test de compétence japonais-N2"); JMenuItem menuitem4_3 = new JMenuItem ("Dictionnaire des critères de question du test de compétence japonais-N3"); JMenuItem menuitem4_4 = new JMenuItem ("Dictionnaire des critères de question du test de compétence japonais-N4"); JMenuItem menuitem4_5 = nouveau JMenuItem ("Minna no Japanese Words"); JMenuItem menuitem4_6 = new JMenuItem ("Tableau de vocabulaire Katakana de critères de test de compétence en japonais");

	JMenuItem menuitem5_1 = new JMenuItem("exit");

JMenuItem menuitem6_1 = nouveau JMenuItem ("+ clé: fréquence 1 seconde ajoutée"); JMenuItem menuitem6_2 = new JMenuItem ("-key: fréquence réduite de 1 seconde"); JMenuItem menuitem6_3 = new JMenuItem ("Touche d'espace: démarrer à tout moment"); JMenuItem menuitem6_4 = new JMenuItem ("Touche CTRL: fin à tout moment"); JMenuItem menuitem6_5 = nouveau JMenuItem ("Touche ESC: sortie");

	menu1.add(menuitem1_2);
	menu2.add(menuitem2_1);
	menu2.add(menuitem2_2);
	menu3.add(menuitem3_1);
	menu3.add(menuitem3_2);
	menu4.add(menuitem4_1);
	menu4.add(menuitem4_2);
	menu4.add(menuitem4_3);
	menu4.add(menuitem4_4);
	menu4.add(menuitem4_5);
	menu4.add(menuitem4_6);
	menu5.add(menuitem5_1);
	menu6.add(menuitem6_1);
	menu6.add(menuitem6_2);
	menu6.add(menuitem6_3);
	menu6.add(menuitem6_4);
	menu6.add(menuitem6_5);

	menuitem1_2.addActionListener(this);
	menuitem1_2.setActionCommand("Open");

	menuitem2_1.addActionListener(this);

menuitem2_1.setActionCommand ("démarrage aléatoire"); menuitem2_2.addActionListener(this); menuitem2_2.setActionCommand ("fin aléatoire");

	menuitem3_1.addActionListener(this);
	menuitem3_1.setActionCommand("addTime");
	menuitem3_2.addActionListener(this);
	menuitem3_2.setActionCommand("decreaseTime");

	menuitem4_1.addActionListener(this);
	menuitem4_1.setActionCommand("readJapaneseN1");
	menuitem4_2.addActionListener(this);
	menuitem4_2.setActionCommand("readJapaneseN2");
	menuitem4_3.addActionListener(this);
	menuitem4_3.setActionCommand("readJapaneseN3");
	menuitem4_4.addActionListener(this);
	menuitem4_4.setActionCommand("readJapaneseN4");
	menuitem4_5.addActionListener(this);
	menuitem4_5.setActionCommand("readJapaneseMinnna");
	menuitem4_6.addActionListener(this);
	menuitem4_6.setActionCommand("readJapaneseKana");

	menuitem5_1.addActionListener(this);
	menuitem5_1.setActionCommand("exit");

	JPanel p = new JPanel();
	label = new JLabel();
	label.setBackground(Color.gray);
	label.setVerticalAlignment(JLabel.CENTER);
	label.setText("Loading......");
	p.add(label);

	Container contentPane = getContentPane();
	contentPane.add(p, BorderLayout.LINE_START);

	WindowDrugMove mouseListener = new WindowDrugMove();

// Lorsque vous prenez la souris pour la première fois label.addMouseListener(mouseListener); // En faisant glisser la souris label.addMouseMotionListener(mouseListener);

	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	setBounds(intRight, intDown, 400, CONTENT_LABEL_HEIGHT);
	setAlwaysOnTop(true);
	setUndecorated(true);
	setBackground(new Color(0x0, true));
	setVisible(true);

// Lire le fichier de propriétés. properties = new Properties(); try { String currentPath = new File(".").getAbsoluteFile().getParent(); File settingFile = new File(currentPath + "\LearnWords.ini"); if (!settingFile.exists()) { properties.setProperty("MODE", MODE_AUTO); properties.setProperty("DICT", "jp.co.learn.dict.JapaneseN1"); properties.store(new FileOutputStream(settingFile), "Comments"); } else { properties.load(new FileInputStream(settingFile)); } } catch (Exception e) { }

	filename = "C:\\en.txt";
	readFile(filename);

	
	Thread thread = new Thread(this);
	thread.start();
}




/**

// String jisUni = new String(wordList.get(sec).getBytes("Shift_JIS"),"Shift_JIS"); // // Unicode comme EUC // String eucjpUni = new String(jisUni.getBytes("UTF-8"),"UTF-8"); // Process p =Runtime.getRuntime().exec("H:\iexplore.exe http://www.google.com/search?q="+wordList.get(sec)+"&ie=euc-jp" + "&hl=ja");

	        	 Process p =Runtime.getRuntime().exec("H:\\Chrome\\Application\\chrome.exe http://www.google.com/search?q="+wordList.get(sec-1)+"&ie=euc-jp" + "&hl=ja");
				
				 try {
					p.waitFor();
				} catch (InterruptedException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			        InputStream input = p.getInputStream();
			        try (BufferedReader reader = new BufferedReader(new InputStreamReader(input))) {
			            String lines = "";
			            for (String line = reader.readLine(); line != null; line = reader.readLine()) {
			                lines += line + "\n";
			            }
			            System.out.println(lines);
			        }
			        
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
            }
	}

	public void mouseEntered(MouseEvent e) {
	}

	public void mouseExited(MouseEvent e) {
	}

	public void mousePressed(MouseEvent e) {
		start = e;
		showPopup(e);
	}

	public void mouseReleased(MouseEvent e) {

// Bon sushi showPopup(e); } }

public void actionPerformed(ActionEvent e) {

	if (e.getActionCommand() == "Open") {
		JFileChooser jfc1 = new JFileChooser();

// Réglage du nom jfc1.setDialogTitle ("Veuillez sélectionner un fichier."); // Méthode par défaut jfc1.showOpenDialog(null); jfc1.setVisible(true); // Récupère tous les chemins filename = jfc1.getSelectedFile().getAbsolutePath(); readFile(filename); } else if (e.getActionCommand () == "démarrage aléatoire") { label.setText (" <font face = 'MS Mincho, SimSun, Song" size =' + 1'color = 'green'> Random start ... </ font> </ html> "); Collections.shuffle(wordList); return; } else if (e.getActionCommand () == "fin aléatoire") { label.setText (" <font face = 'MS Mincho, SimSun, Song body' size = '+ 1'color =' green '> random end ... </ font> </ html>"); reRadom(); return; } else if (e.getActionCommand() == "addTime") { if (intTime >= 1000) { intTime = intTime + 1000; } else if (250 <= intTime && intTime < 1000) { intTime = intTime * 2; } } else if (e.getActionCommand() == "decreaseTime") { if (intTime > 1000) { intTime = intTime - 1000; } else if (intTime >= 500) { intTime = intTime / 2; } } else if (e.getActionCommand() == "readJapaneseN1") { loadDict("jp.co.learn.dict.JapaneseN1"); sec = 0; } else if (e.getActionCommand() == "readJapaneseN2") { loadDict("jp.co.learn.dict.JapaneseN2"); sec = 0; }

	outPutMsgOfchangTime();
	//
	// else if (e.getActionCommand() == "readJapaneseN3") {
	// readJapaneseN3();
	// sec = 0;
	// } else if (e.getActionCommand() == "readJapaneseN4") {
	// readJapaneseN4();
	// sec = 0;
	// } else if (e.getActionCommand() == "readJapaneseMinnna") {
	// readJapaneseMinnna();
	// sec = 0;
	// } else if (e.getActionCommand() == "readJapaneseKana") {
	// readJapaneseKana();
	// sec = 0;
	// }

	if ("exit".equals(e.getActionCommand())) {
		int dialogButton = JOptionPane.YES_NO_OPTION;
		if (dialogButton == JOptionPane.YES_OPTION) {
			writeFile();
			System.exit(NORMAL);
		}
	}

	menubar.setVisible(false);
	frame.setBounds(frame.getX(), frame.getY(), frame.getWidth(), CONTENT_LABEL_HEIGHT);
}

public void run() {
	do {
		if (sec + 1 > wordList.size()) {
			sec = 0;
		} else {

label.setText (" " + wordList.get (sec) .trim () + "</ font> </ html> "); sec++; if (sec == wordList.size()) { sec = 0; } } try { Thread.sleep(intTime); } catch (InterruptedException e) { } } while (true); }

/**
  • lire le fichier Lire le fichier TXT spécifié

  • @return Aucun */ public void readFile(String fileName) {

     wordList = new ArrayList<String>();
     sec = 0;
     try {
     	Files.lines(Paths.get(fileName)).forEachOrdered(s -> {
     		if (null != s && s.trim().length() > 1 && !s.contains("OK")) {
     			wordList.add(s);
     		}
     	});
     	menubar.setVisible(false);
     	if (wordList.size() == 0) {
     		loadDict("jp.co.learn.dict.JapaneseN1");
     	}
     } catch (IOException e1) {
     	if (wordList.size() == 0) {
     		loadDict("jp.co.learn.dict.JapaneseN1");
     		sec = 0;
     	}
     	e1.printStackTrace();
     }
    

    }

    /**

  • 键盘 监听 */ @Override public void keyPressed(KeyEvent e) {

// + KEY Ajouter du temps pour répéter if (e.getKeyCode() == 107) { if (intTime >= 1000) { intTime = intTime + 1000; } else if (250 <= intTime && intTime < 1000) { intTime = intTime * 2; } } // --KEY Réduction du temps de répétition else if (e.getKeyCode() == 109) { if (intTime > 1000) { intTime = intTime - 1000; } else if (intTime >= 500) {

			intTime = intTime / 2;
		}

	}

// Fin de la touche ESC else if (e.getKeyCode() == 27) { writeFile(); System.exit(NORMAL); } // SPACE Début aléatoire else if (e.getKeyCode() == 32) { Collections.shuffle(wordList); } // Fin aléatoire CTRL else if (e.getKeyCode() == 17) { label.setText ("fin aléatoire"); reRadom(); } // ENTRÉE Écrivez les mots que vous comprenez. Ne pas afficher la prochaine fois else if (e.getKeyCode() == 10) { if (wordList.get(sec - 1) == label.getText()) { wordList.remove(sec - 1); wordList.add(sec - 1, "OK " + label.getText()); System.out.println("OK"); } else { System.out.println("NG"); } } // En bas à droite else if (e.getKeyCode() == 39) { sec++; if (sec == wordList.size()) { sec = 0; } label.setText( " <font face = 'MS Mincho, SimSun, Song'size =' + 1 '>" + wordList.get (sec) .trim () + "</ font> </ html>"); } // Mouvement vers le bas else if (e.getKeyCode() == 40) { intDown = intDown + 50; frame.setBounds(frame.getX(), intDown, frame.getWidth(), CONTENT_LABEL_HEIGHT); } // Meilleur mouvement d'amélioration else if (e.getKeyCode() == 38) { intDown = intDown - 50; if (intDown > 0) { frame.setBounds(frame.getX(), intDown, frame.getWidth(), CONTENT_LABEL_HEIGHT); } } // En haut à gauche else if (e.getKeyCode() == 37) { sec--; if (sec < 0) { sec = 0; } label.setText( " <font face = 'MS Mincho, SimSun, Song'size =' + 1 '>" + wordList.get (sec) .trim () + "</ font> </ html>"); }

	outPutMsgOfchangTime();
}

private void outPutMsgOfchangTime() {
	if (intTime<1000) {

String text = String.valueOf (intTime) + "Changé en milliseconde."; label.setText (" <font face = 'MS Mincho, SimSun, Song" size =' + 1'color = 'green'> "+ text +" </ font> </ html> "); }else{ String text = String.valueOf (intTime / 1000) + "Changé en secondes."; label.setText (" <font face = 'MS Mincho, SimSun, Song" size =' + 1'color = 'green'> "+ text +" </ font> </ html> "); } }

/**
  • Relâchez une sortie aléatoire au hasard. */ private void reRadom() { Collections.sort(wordList, new Comparator() { @Override public int compare(String o1, String o2) { return o1.compareTo(o2); } }); }

    /**

  • Mise à jour du fichier. Mots à comprendre Ajouter OK avant cette ligne. */ public void writeFile() {

     FileSystem fs = FileSystems.getDefault();
    

/ * Ecrire un fichier * / Path outputPath = fs.getPath(filename); try (BufferedWriter bw = Files.newBufferedWriter(outputPath, StandardCharsets.UTF_8, StandardOpenOption.CREATE)) { wordList.forEach(s -> { try { bw.write(s + "\r\n"); } catch (Exception e) { e.printStackTrace(); } }); } catch (IOException e) { e.printStackTrace(); } }

@SuppressWarnings("unchecked")
private void loadDict(String param) {
	try {
		wordList.clear();
		Class<?> clazz = Class.forName(param);
		Object obj = clazz.newInstance();
		Method method = clazz.getMethod("read");
		wordList = (List<String>) method.invoke(obj);
	} catch (Exception e) {
	}
}

private void showPopup(MouseEvent e) {
	if (e.isPopupTrigger()) {
		menubar.show(e.getComponent(), e.getX(), e.getY());
	}
}

public static void initGlobalFontSetting(Font fnt) {
	FontUIResource fontRes = new FontUIResource(fnt);
	for (Enumeration keys = UIManager.getDefaults().keys(); keys.hasMoreElements();) {
		Object key = keys.nextElement();
		Object value = UIManager.get(key);
		if (value instanceof FontUIResource)
			UIManager.put(key, fontRes);
	}
}

@Override
public void keyReleased(KeyEvent arg0) {
}

@Override
public void keyTyped(KeyEvent arg0) {
}



public static boolean isUTF8(byte[] src)
{
    try {
        byte[] tmp = new String(src, "UTF8").getBytes("UTF8");
        return Arrays.equals(tmp, src);
    }
    catch(UnsupportedEncodingException e) {
        return false;
    }
}

public static boolean isSJIS(byte[] src)
{
    try {
        byte[] tmp = new String(src, "Shift_JIS").getBytes("Shift_JIS");
        return Arrays.equals(tmp, src);
    }
    catch(UnsupportedEncodingException e) {
        return false;
    }
}

}

Recommended Posts

Outil d'étude des langues 2.0
Dernière version de l'outil d'étude des langues
Politique d'étude