From 37934e0c65cf921e1b822299cdeec9cb5a40584f Mon Sep 17 00:00:00 2001 From: Amrit Panesar Date: Tue, 21 Apr 2015 21:09:55 -0700 Subject: [PATCH] Project 4 Signed-off-by: Amrit Panesar --- COM380/Project4/Project4/Form1.h | 300 +++++++++++++++++++++- COM380/Project4/Project4/LottoBall.h | 10 +- COM380/Project4/Project4/LottoBallcpp.cpp | 50 ++++ 3 files changed, 355 insertions(+), 5 deletions(-) diff --git a/COM380/Project4/Project4/Form1.h b/COM380/Project4/Project4/Form1.h index 08b89cd..81b9131 100644 --- a/COM380/Project4/Project4/Form1.h +++ b/COM380/Project4/Project4/Form1.h @@ -42,6 +42,26 @@ namespace Project4 private: System::Windows::Forms::ToolStripMenuItem^ exitToolStripMenuItem; private: System::Windows::Forms::ToolStripMenuItem^ helpToolStripMenuItem; private: System::Windows::Forms::ToolStripMenuItem^ aboutToolStripMenuItem; + private: System::Windows::Forms::GroupBox^ groupBox1; + private: System::Windows::Forms::TextBox^ textBox6; + private: System::Windows::Forms::TextBox^ textBox5; + private: System::Windows::Forms::TextBox^ textBox4; + private: System::Windows::Forms::TextBox^ textBox3; + private: System::Windows::Forms::TextBox^ textBox2; + private: System::Windows::Forms::TextBox^ textBox1; + private: System::Windows::Forms::Label^ label6; + private: System::Windows::Forms::Label^ label5; + private: System::Windows::Forms::Label^ label4; + private: System::Windows::Forms::Label^ label3; + private: System::Windows::Forms::Label^ label2; + private: System::Windows::Forms::Label^ label1; + private: System::Windows::Forms::RadioButton^ radioButton6; + private: System::Windows::Forms::RadioButton^ radioButton5; + private: System::Windows::Forms::RadioButton^ radioButton4; + private: System::Windows::Forms::RadioButton^ radioButton3; + private: System::Windows::Forms::RadioButton^ radioButton2; + private: System::Windows::Forms::RadioButton^ radioButton1; + private: System::Windows::Forms::Button^ button1; private: /// @@ -61,7 +81,28 @@ namespace Project4 this->exitToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); this->helpToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); this->aboutToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); + this->groupBox1 = (gcnew System::Windows::Forms::GroupBox()); + this->radioButton6 = (gcnew System::Windows::Forms::RadioButton()); + this->radioButton5 = (gcnew System::Windows::Forms::RadioButton()); + this->radioButton4 = (gcnew System::Windows::Forms::RadioButton()); + this->radioButton3 = (gcnew System::Windows::Forms::RadioButton()); + this->radioButton2 = (gcnew System::Windows::Forms::RadioButton()); + this->radioButton1 = (gcnew System::Windows::Forms::RadioButton()); + this->label6 = (gcnew System::Windows::Forms::Label()); + this->label5 = (gcnew System::Windows::Forms::Label()); + this->label4 = (gcnew System::Windows::Forms::Label()); + this->label3 = (gcnew System::Windows::Forms::Label()); + this->label2 = (gcnew System::Windows::Forms::Label()); + this->label1 = (gcnew System::Windows::Forms::Label()); + this->textBox6 = (gcnew System::Windows::Forms::TextBox()); + this->textBox5 = (gcnew System::Windows::Forms::TextBox()); + this->textBox4 = (gcnew System::Windows::Forms::TextBox()); + this->textBox3 = (gcnew System::Windows::Forms::TextBox()); + this->textBox2 = (gcnew System::Windows::Forms::TextBox()); + this->textBox1 = (gcnew System::Windows::Forms::TextBox()); + this->button1 = (gcnew System::Windows::Forms::Button()); this->menuStrip1->SuspendLayout(); + this->groupBox1->SuspendLayout(); this->SuspendLayout(); // // menuStrip1 @@ -86,7 +127,7 @@ namespace Project4 // this->exitToolStripMenuItem->Name = L"exitToolStripMenuItem"; this->exitToolStripMenuItem->ShortcutKeys = static_cast((System::Windows::Forms::Keys::Alt | System::Windows::Forms::Keys::F4)); - this->exitToolStripMenuItem->Size = System::Drawing::Size(152, 22); + this->exitToolStripMenuItem->Size = System::Drawing::Size(134, 22); this->exitToolStripMenuItem->Text = L"E&xit"; this->exitToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::exitToolStripMenuItem_Click); // @@ -105,36 +146,287 @@ namespace Project4 this->aboutToolStripMenuItem->Size = System::Drawing::Size(145, 22); this->aboutToolStripMenuItem->Text = L"&About"; // + // groupBox1 + // + this->groupBox1->Controls->Add(this->radioButton6); + this->groupBox1->Controls->Add(this->radioButton5); + this->groupBox1->Controls->Add(this->radioButton4); + this->groupBox1->Controls->Add(this->radioButton3); + this->groupBox1->Controls->Add(this->radioButton2); + this->groupBox1->Controls->Add(this->radioButton1); + this->groupBox1->Controls->Add(this->label6); + this->groupBox1->Controls->Add(this->label5); + this->groupBox1->Controls->Add(this->label4); + this->groupBox1->Controls->Add(this->label3); + this->groupBox1->Controls->Add(this->label2); + this->groupBox1->Controls->Add(this->label1); + this->groupBox1->Controls->Add(this->textBox6); + this->groupBox1->Controls->Add(this->textBox5); + this->groupBox1->Controls->Add(this->textBox4); + this->groupBox1->Controls->Add(this->textBox3); + this->groupBox1->Controls->Add(this->textBox2); + this->groupBox1->Controls->Add(this->textBox1); + this->groupBox1->Location = System::Drawing::Point(12, 27); + this->groupBox1->Name = L"groupBox1"; + this->groupBox1->Size = System::Drawing::Size(645, 127); + this->groupBox1->TabIndex = 1; + this->groupBox1->TabStop = false; + this->groupBox1->Text = L"Lotto Balls"; + // + // radioButton6 + // + this->radioButton6->AutoSize = true; + this->radioButton6->Location = System::Drawing::Point(581, 86); + this->radioButton6->Name = L"radioButton6"; + this->radioButton6->Size = System::Drawing::Size(14, 13); + this->radioButton6->TabIndex = 13; + this->radioButton6->TabStop = true; + this->radioButton6->UseVisualStyleBackColor = true; + // + // radioButton5 + // + this->radioButton5->AutoSize = true; + this->radioButton5->Location = System::Drawing::Point(475, 86); + this->radioButton5->Name = L"radioButton5"; + this->radioButton5->Size = System::Drawing::Size(14, 13); + this->radioButton5->TabIndex = 12; + this->radioButton5->TabStop = true; + this->radioButton5->UseVisualStyleBackColor = true; + // + // radioButton4 + // + this->radioButton4->AutoSize = true; + this->radioButton4->Location = System::Drawing::Point(369, 86); + this->radioButton4->Name = L"radioButton4"; + this->radioButton4->Size = System::Drawing::Size(14, 13); + this->radioButton4->TabIndex = 11; + this->radioButton4->TabStop = true; + this->radioButton4->UseVisualStyleBackColor = true; + // + // radioButton3 + // + this->radioButton3->AutoSize = true; + this->radioButton3->Location = System::Drawing::Point(263, 86); + this->radioButton3->Name = L"radioButton3"; + this->radioButton3->Size = System::Drawing::Size(14, 13); + this->radioButton3->TabIndex = 10; + this->radioButton3->TabStop = true; + this->radioButton3->UseVisualStyleBackColor = true; + // + // radioButton2 + // + this->radioButton2->AutoSize = true; + this->radioButton2->Location = System::Drawing::Point(157, 86); + this->radioButton2->Name = L"radioButton2"; + this->radioButton2->Size = System::Drawing::Size(14, 13); + this->radioButton2->TabIndex = 9; + this->radioButton2->TabStop = true; + this->radioButton2->UseVisualStyleBackColor = true; + // + // radioButton1 + // + this->radioButton1->AutoSize = true; + this->radioButton1->Location = System::Drawing::Point(51, 86); + this->radioButton1->Name = L"radioButton1"; + this->radioButton1->Size = System::Drawing::Size(14, 13); + this->radioButton1->TabIndex = 8; + this->radioButton1->TabStop = true; + this->radioButton1->UseVisualStyleBackColor = true; + // + // label6 + // + this->label6->AutoSize = true; + this->label6->Location = System::Drawing::Point(567, 28); + this->label6->Name = L"label6"; + this->label6->Size = System::Drawing::Size(37, 13); + this->label6->TabIndex = 7; + this->label6->Text = L"Bonus"; + // + // label5 + // + this->label5->AutoSize = true; + this->label5->Location = System::Drawing::Point(465, 28); + this->label5->Name = L"label5"; + this->label5->Size = System::Drawing::Size(33, 13); + this->label5->TabIndex = 7; + this->label5->Text = L"Ball 5"; + // + // label4 + // + this->label4->AutoSize = true; + this->label4->Location = System::Drawing::Point(359, 28); + this->label4->Name = L"label4"; + this->label4->Size = System::Drawing::Size(33, 13); + this->label4->TabIndex = 7; + this->label4->Text = L"Ball 4"; + // + // label3 + // + this->label3->AutoSize = true; + this->label3->Location = System::Drawing::Point(253, 28); + this->label3->Name = L"label3"; + this->label3->Size = System::Drawing::Size(33, 13); + this->label3->TabIndex = 7; + this->label3->Text = L"Ball 3"; + // + // label2 + // + this->label2->AutoSize = true; + this->label2->Location = System::Drawing::Point(147, 28); + this->label2->Name = L"label2"; + this->label2->Size = System::Drawing::Size(33, 13); + this->label2->TabIndex = 7; + this->label2->Text = L"Ball 2"; + // + // label1 + // + this->label1->AutoSize = true; + this->label1->Location = System::Drawing::Point(41, 28); + this->label1->Name = L"label1"; + this->label1->Size = System::Drawing::Size(33, 13); + this->label1->TabIndex = 6; + this->label1->Text = L"Ball 1"; + // + // textBox6 + // + this->textBox6->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, + static_cast(0))); + this->textBox6->Location = System::Drawing::Point(40, 44); + this->textBox6->Name = L"textBox6"; + this->textBox6->ReadOnly = true; + this->textBox6->Size = System::Drawing::Size(34, 29); + this->textBox6->TabIndex = 5; + this->textBox6->Text = L"00"; + this->textBox6->TextAlign = System::Windows::Forms::HorizontalAlignment::Center; + // + // textBox5 + // + this->textBox5->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, + static_cast(0))); + this->textBox5->Location = System::Drawing::Point(146, 44); + this->textBox5->Name = L"textBox5"; + this->textBox5->ReadOnly = true; + this->textBox5->Size = System::Drawing::Size(34, 29); + this->textBox5->TabIndex = 4; + this->textBox5->Text = L"00"; + this->textBox5->TextAlign = System::Windows::Forms::HorizontalAlignment::Center; + // + // textBox4 + // + this->textBox4->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, + static_cast(0))); + this->textBox4->Location = System::Drawing::Point(252, 44); + this->textBox4->Name = L"textBox4"; + this->textBox4->ReadOnly = true; + this->textBox4->Size = System::Drawing::Size(34, 29); + this->textBox4->TabIndex = 3; + this->textBox4->Text = L"00"; + this->textBox4->TextAlign = System::Windows::Forms::HorizontalAlignment::Center; + // + // textBox3 + // + this->textBox3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, + static_cast(0))); + this->textBox3->Location = System::Drawing::Point(358, 44); + this->textBox3->Name = L"textBox3"; + this->textBox3->ReadOnly = true; + this->textBox3->Size = System::Drawing::Size(34, 29); + this->textBox3->TabIndex = 2; + this->textBox3->Text = L"00"; + this->textBox3->TextAlign = System::Windows::Forms::HorizontalAlignment::Center; + // + // textBox2 + // + this->textBox2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, + static_cast(0))); + this->textBox2->Location = System::Drawing::Point(464, 44); + this->textBox2->Name = L"textBox2"; + this->textBox2->ReadOnly = true; + this->textBox2->Size = System::Drawing::Size(34, 29); + this->textBox2->TabIndex = 1; + this->textBox2->Text = L"00"; + this->textBox2->TextAlign = System::Windows::Forms::HorizontalAlignment::Center; + // + // textBox1 + // + this->textBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, + static_cast(0))); + this->textBox1->Location = System::Drawing::Point(570, 44); + this->textBox1->Name = L"textBox1"; + this->textBox1->ReadOnly = true; + this->textBox1->Size = System::Drawing::Size(34, 29); + this->textBox1->TabIndex = 0; + this->textBox1->Text = L"00"; + this->textBox1->TextAlign = System::Windows::Forms::HorizontalAlignment::Center; + // + // button1 + // + this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, + static_cast(0))); + this->button1->Location = System::Drawing::Point(297, 187); + this->button1->Name = L"button1"; + this->button1->Size = System::Drawing::Size(74, 50); + this->button1->TabIndex = 2; + this->button1->Text = L"Start"; + this->button1->UseVisualStyleBackColor = true; + this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click); + // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; - this->ClientSize = System::Drawing::Size(669, 482); + this->ClientSize = System::Drawing::Size(669, 255); + this->Controls->Add(this->button1); + this->Controls->Add(this->groupBox1); this->Controls->Add(this->menuStrip1); this->MainMenuStrip = this->menuStrip1; this->Name = L"Form1"; - this->Text = L"Form1"; + this->Text = L"Lotto Ball Picker"; this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load); this->menuStrip1->ResumeLayout(false); this->menuStrip1->PerformLayout(); + this->groupBox1->ResumeLayout(false); + this->groupBox1->PerformLayout(); this->ResumeLayout(false); this->PerformLayout(); } #pragma endregion - public: List balls; + public: List^ balls; + public: volatile static array^ numbers; private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { + this->numbers = gcnew array {0, 0, 0, 0, 0, 0}; + balls = gcnew List; + + for (int i = 0; i < 5; i++) + { + balls->Add(gcnew LottoBall(1, 75)); + } + balls->Add(gcnew LottoBall(1, 15)); } private: System::Void exitToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) { + for (int i = 0; i < balls->Count; i++) + { + balls[i]->stop(); + } + Application::Exit(); } + private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) + { + for (int i = 0; i < balls->Count; i++) + { + balls[i]->start(); + } + } }; + } diff --git a/COM380/Project4/Project4/LottoBall.h b/COM380/Project4/Project4/LottoBall.h index c7ecc10..770d40d 100644 --- a/COM380/Project4/Project4/LottoBall.h +++ b/COM380/Project4/Project4/LottoBall.h @@ -13,12 +13,20 @@ namespace Project4 { public: - LottoBall(); + LottoBall(int minval, int maxval); ~LottoBall(); int getCurrentValue(); + int num; + + System::Void start(); + System::Void stop(); private: + int minVal; + int maxVal; + + bool threadStop; Thread^ thread; System::Void run(); diff --git a/COM380/Project4/Project4/LottoBallcpp.cpp b/COM380/Project4/Project4/LottoBallcpp.cpp index 79f48d4..83882e7 100644 --- a/COM380/Project4/Project4/LottoBallcpp.cpp +++ b/COM380/Project4/Project4/LottoBallcpp.cpp @@ -1,4 +1,54 @@ #include "LottoBall.h" +#include "Form1.h" +namespace Project4 +{ + LottoBall::LottoBall(int minval, int maxval) + { + minVal = minval; + maxVal = maxval; + + threadStop = false; + num = 0; + thread = gcnew Thread(gcnew ThreadStart(&run)); + + } + + LottoBall::~LottoBall() + { + thread->Abort(); + } + + System::Void LottoBall::run() + { + Random^ r = gcnew Random(); + String^ threadname = Thread::CurrentThread->Name; + int id = 0; + Int32::TryParse(threadname, id); + + while (!this->threadStop) + { + this->num = r->Next(minVal, maxVal); + Form1::numbers[id] = this->num; + } + } + + int LottoBall::getCurrentValue() + { + return this->num; + } + + System::Void LottoBall::start() + { + this->threadStop = false; + thread->Start(); + } + + System::Void LottoBall::stop() + { + this->threadStop = true; + } + +} \ No newline at end of file