示例#1
0
 private void setTextBoxes(KanjiWord word)
 {
     kanjiBox.Text    = word.getKanji();
     furiganaBox.Text = word.getFurigana();
     romajiBox.Text   = word.getRomaji();
     englishBox.Text  = word.getEnglish();
 }
示例#2
0
        // Reading kanji words form a text file. The text file has a specific format
        private void readWords()
        {
            string kanjiPath = @"data\kanji.txt";

            StreamReader reader;
            string       line;

            // Hiragana reading
            reader = new StreamReader(kanjiPath);
            while ((line = reader.ReadLine()) != null)
            {
                // Author Ahmad Mageed
                // From here ***
                var delimiters = new List <string> {
                    "#k#", "#f#", "#r#", "#m#", "#e#"
                };
                string pattern = "(" + String.Join("|", delimiters.Select(d => Regex.Escape(d))
                                                   .ToArray())
                                 + ")";

                string[] result = Regex.Split(line, pattern);
                // To here ***

                KanjiWord kanjiWord    = new KanjiWord();
                int       stringLength = result.Length;

                for (int index = 0; index < stringLength; index++)
                {
                    switch (result[index])
                    {
                    case "#k#":
                        kanjiWord.setKanji(result[index + 1]);
                        index++;
                        break;

                    case "#f#":
                        kanjiWord.setFurigana(result[index + 1]);
                        index++;
                        break;

                    case "#r#":
                        kanjiWord.setRomaji(result[index + 1]);
                        index++;
                        break;

                    case "#m#":
                        kanjiWord.setEnglish(result[index + 1]);
                        index++;
                        break;

                    case "#e#":
                        break;
                    }
                }
                kanji.Add(kanjiWord);
            }
            reader.Close();
        }
示例#3
0
        private void saveWord_Click_1(object sender, EventArgs e)
        {
            KanjiWord newWord = new KanjiWord();

            newWord.setKanji(kanjiBox.Text);
            newWord.setFurigana(furiganaBox.Text);
            newWord.setRomaji(romajiBox.Text);
            newWord.setEnglish(englishBox.Text);

            kanji.addWord(newWord);
        }
示例#4
0
        public void writeWords()
        {
            StreamWriter writer = new StreamWriter(@"data\kanji.txt", false);

            for (int i = 0; i < kanji.Count; i++)
            {
                KanjiWord     word = kanji.ElementAt <KanjiWord>(i);
                StringBuilder line = new StringBuilder();
                line.Append("#k#");
                line.Append(word.getKanji());
                line.Append("#f#");
                line.Append(word.getFurigana());
                line.Append("#r#");
                line.Append(word.getRomaji());
                line.Append("#m#");
                line.Append(word.getEnglish());
                line.Append("#e#");
                writer.WriteLine(line.ToString());
            }
            writer.Close();
        }
示例#5
0
        private void wordListUI_SelectedIndexChanged(object sender, EventArgs e)
        {
            KanjiWord word = kanji.getWord(wordListUI.SelectedIndex);

            setTextBoxes(word);
        }
示例#6
0
 // Add new Kanji word to the list
 public void addWord(KanjiWord newWord)
 {
     kanji.Add(newWord);
 }