rendered paste bodyusing System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Collections.Specialized;
class App
{
public static void Main()
{
Application.Run( new FlashCards () );
}
}
/**
*
*
*
*
**/
class FlashCards : Form
{
private const int FRANCAIS = 0;
private const int ENGLISH = 1;
Button frenchButton, englishButton;
ToolStripMenuItem toolStripMenuItem1,openToolStripMenuItem,answerDelayToolStripMenuItem,
secondsToolStripMenuItem, secondsToolStripMenuItem1, secondsToolStripMenuItem2,
exitToolStripMenuItem;
Random rand;
MenuStrip menuStrip1;
int wordIndex, wordListLength, currentLanguage, timePeriod;
Label promptLabel, answerLabel;
string[,] pairList;
string[] frList, enList;
OrderedDictionary lexicon;
Timer clock;
public FlashCards()
{
InitializeComponent();
string fileName = "mots.txt";
lexicon = new OrderedDictionary();
if (File.Exists(fileName))
{
FileStream lesMots = new FileStream(fileName, FileMode.Open, FileAccess.Read);
StreamReader fileReader = new StreamReader(lesMots);
// pairList = fillArray(fileReader);
fillLexicon(fileReader);
}
// this.KeyDown += new KeyEventHandler(OnKeyPress);
clock = new Timer();
timePeriod = 4000;
clock.Interval = timePeriod;
clock.Start();
clock.Tick += new EventHandler(clockTick);
wordIndex = 0;
currentLanguage = -1;
rand = new Random();
}
private string[,] fillArray(StreamReader reader)
{
List<string> wordList = new List<string>();
string newLine = reader.ReadLine();
do
{
wordList.Add(newLine);
newLine = reader.ReadLine();
}
while (newLine != null);
wordListLength = wordList.Count;
string[,] output = new string[2, wordListLength];
for (int i = 0, split = 0; i < wordListLength; ++i)
{
newLine = wordList[i];
split = newLine.IndexOf(" - ");
output[FRANCAIS,i] = newLine.Substring(0, split).Trim();
output[ENGLISH,i] = newLine.Substring(split+3).Trim();
}
return output;
}
private void fillLexicon( StreamReader reader )
{
lexicon.Clear();
string temp = reader.ReadLine();
string part1, part2 = null;
int split = 0;
int i = 1;
while( temp != null )
{
split = temp.IndexOf(" - ");
if(split > -1)
{
part1 = temp.Substring(0,split).Trim();
part2 = temp.Substring(split+3).Trim();
lexicon.Add( part1, part2 );
}
else
MessageBox.Show( "File Error at line " + i );
temp = reader.ReadLine();
++i;
}
wordListLength = lexicon.Count;
populateArrays();
}
// fills arrays with the dictionary data
private void populateArrays()
{
frList = new string[wordListLength];
lexicon.Keys.CopyTo(frList,0);
enList = new string[wordListLength];
lexicon.Values.CopyTo(enList,0);
}
//keyPress events--file deletion, program exit, etc;
private void OnKeyPress( object sender, KeyEventArgs e )
{
promptLabel.Text = "Key Pressed: " + e.KeyCode;
}
// button clicks: clear labels and display a random word
private void frenchClick( object sender, EventArgs e )
{
wordIndex = rand.Next(wordListLength);
currentLanguage = FRANCAIS;
promptLabel.Text = frList[wordIndex];
answerLabel.Text = null;
clock.Stop();
clock.Start();
}
private void englishClick( object sender, EventArgs e )
{
wordIndex = rand.Next(wordListLength);
currentLanguage = ENGLISH;
promptLabel.Text = enList[wordIndex];
answerLabel.Text = null;
clock.Stop();
clock.Start();
}
// on time delay, display the translation in answerLabel
private void clockTick( object sender, EventArgs e )
{
if(currentLanguage == FRANCAIS)
answerLabel.Text = enList[wordIndex];
if(currentLanguage == ENGLISH)
answerLabel.Text = frList[wordIndex];
}
protected void openFileClick(object sender, System.EventArgs e)
{
Stream myStream;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "." ;
openFileDialog1.Filter = "txt files (*.txt)|*.txt" ;
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
if((myStream = openFileDialog1.OpenFile())!= null)
{
StreamReader fileReader = new StreamReader(myStream);
fillLexicon(fileReader);
myStream.Close();
}
}
}
private void delayClick(object sender, System.EventArgs e)
{
if(sender == secondsToolStripMenuItem)
{
timePeriod = 4000;
this.secondsToolStripMenuItem1.Checked = false;
this.secondsToolStripMenuItem2.Checked = false;
}
if(sender == secondsToolStripMenuItem1)
{
timePeriod = 6000;
this.secondsToolStripMenuItem.Checked = false;
this.secondsToolStripMenuItem2.Checked = false;
}
if(sender == secondsToolStripMenuItem2)
{
timePeriod = 8000;
this.secondsToolStripMenuItem.Checked = false;
this.secondsToolStripMenuItem1.Checked = false;
}
clock.Interval = timePeriod;
}
private void exitClick(object sender, System.EventArgs e)
{
Application.Exit();
}
private void InitializeComponent()
{
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.answerDelayToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.secondsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.secondsToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.secondsToolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem();
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.promptLabel = new System.Windows.Forms.Label();
this.englishButton = new System.Windows.Forms.Button();
this.frenchButton = new System.Windows.Forms.Button();
this.answerLabel = new System.Windows.Forms.Label();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItem1});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(392, 24);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
// toolStripMenuItem1
//
this.toolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.openToolStripMenuItem,
this.answerDelayToolStripMenuItem,
this.exitToolStripMenuItem});
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(35, 20);
this.toolStripMenuItem1.Text = "&File";
//
// openToolStripMenuItem
//
this.openToolStripMenuItem.Name = "openToolStripMenuItem";
this.openToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.openToolStripMenuItem.Text = "&Open";
this.openToolStripMenuItem.Click += new EventHandler(openFileClick);
//
// answerDelayToolStripMenuItem
//
this.answerDelayToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.secondsToolStripMenuItem,
this.secondsToolStripMenuItem1,
this.secondsToolStripMenuItem2});
this.answerDelayToolStripMenuItem.Name = "answerDelayToolStripMenuItem";
this.answerDelayToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.answerDelayToolStripMenuItem.Text = "&Answer Delay";
//
// secondsToolStripMenuItem
//
this.secondsToolStripMenuItem.Name = "secondsToolStripMenuItem";
this.secondsToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.secondsToolStripMenuItem.Text = "4 seconds";
this.secondsToolStripMenuItem.Click += new EventHandler(delayClick);
this.secondsToolStripMenuItem.CheckOnClick = true;
this.secondsToolStripMenuItem.Checked = true;
//
// secondsToolStripMenuItem1
//
this.secondsToolStripMenuItem1.Name = "secondsToolStripMenuItem1";
this.secondsToolStripMenuItem1.Size = new System.Drawing.Size(152, 22);
this.secondsToolStripMenuItem1.Text = "6 seconds";
this.secondsToolStripMenuItem1.Click += new EventHandler(delayClick);
this.secondsToolStripMenuItem1.CheckOnClick = true;
//
// secondsToolStripMenuItem2
//
this.secondsToolStripMenuItem2.Name = "secondsToolStripMenuItem2";
this.secondsToolStripMenuItem2.Size = new System.Drawing.Size(152, 22);
this.secondsToolStripMenuItem2.Text = "8 seconds";
this.secondsToolStripMenuItem2.Click += new EventHandler(delayClick);
this.secondsToolStripMenuItem2.CheckOnClick = true;
//
// exitToolStripMenuItem
//
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
this.exitToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.exitToolStripMenuItem.Text = "E&xit";
this.exitToolStripMenuItem.Click += new EventHandler(exitClick);
//
// promptLabel
//
this.promptLabel.AutoSize = true;
this.promptLabel.Font = new System.Drawing.Font("Eras Light ITC", 11.25F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.promptLabel.Location = new System.Drawing.Point(50, 75);
this.promptLabel.Name = "promptLabel";
this.promptLabel.Size = new System.Drawing.Size(200, 20);
this.promptLabel.TabIndex = 1;
this.promptLabel.Text = "promptLabel";
//
// answerLabel
//
this.answerLabel.AutoSize = true;
this.answerLabel.Font = new System.Drawing.Font("Eras Light ITC",11.25F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.answerLabel.Location = new System.Drawing.Point(50,150);
this.answerLabel.Name = "answerLabel";
this.answerLabel.Size = new System.Drawing.Size(200,20);
this.answerLabel.Text = null;
this.answerLabel.ForeColor = System.Drawing.Color.Maroon;
this.answerLabel.TabIndex = 2;
//
// frenchButton
//
this.frenchButton.Location = new System.Drawing.Point(40, 380);
this.frenchButton.Name = "frenchButton";
this.frenchButton.Size = new System.Drawing.Size(150, 40);
this.frenchButton.TabIndex = 3;
this.frenchButton.Text = "&Français";
this.frenchButton.UseVisualStyleBackColor = true;
this.frenchButton.Click += new EventHandler(frenchClick);
this.frenchButton.KeyUp += new KeyEventHandler(OnKeyPress);
//
// englishButton
//
this.englishButton.Location = new System.Drawing.Point(200, 380);
this.englishButton.Name = "englishButton";
this.englishButton.Size = new System.Drawing.Size(150, 40);
this.englishButton.TabIndex = 4;
this.englishButton.Text = "&English";
this.englishButton.UseVisualStyleBackColor = true;
this.englishButton.Click += new EventHandler(englishClick);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(392, 466);
this.Controls.Add(this.englishButton);
this.Controls.Add(this.frenchButton);
this.Controls.Add(this.promptLabel);
this.Controls.Add(this.answerLabel);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "FlashCards";
this.Text = "FlashCards";
this.KeyUp += new KeyEventHandler(OnKeyPress);
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
}