Tugas Pertemuan 2 PBKK
Nama : Achmad Khosyi' Assajjad Ramandanta
NRP : 5025211007
Kelas : PBKK (A)
TUGAS MEMBUAT APLIKASI KALKULATOR SEDERHANA C#
using Microsoft.Win32; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace KalkulSederhana { public partial class Form1 : Form { decimal bil1; decimal bil2; int opr; Boolean opr_selesai = false; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void textBox1_TextChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { if (txtDisplay1.Text == "0") { txtDisplay1.Text = "1"; } else { txtDisplay1.Text += "1"; } } private void button2_Click(object sender, EventArgs e) { if (txtDisplay1.Text == "0") { txtDisplay1.Text = "2"; } else { txtDisplay1.Text += "2"; } } private void b3_Click(object sender, EventArgs e) { if (txtDisplay1.Text == "0") { txtDisplay1.Text = "3"; } else { txtDisplay1.Text += "3"; } } private void b4_Click(object sender, EventArgs e) { if (txtDisplay1.Text == "0") { txtDisplay1.Text = "4"; } else { txtDisplay1.Text += "4"; } } private void b5_Click(object sender, EventArgs e) { if (txtDisplay1.Text == "0") { txtDisplay1.Text = "5"; } else { txtDisplay1.Text += "5"; } } private void b6_Click(object sender, EventArgs e) { if (txtDisplay1.Text == "0") { txtDisplay1.Text = "6"; } else { txtDisplay1.Text += "6"; } } private void b7_Click(object sender, EventArgs e) { if (txtDisplay1.Text == "0") { txtDisplay1.Text = "7"; } else { txtDisplay1.Text += "7"; } } private void b8_Click(object sender, EventArgs e) { if (txtDisplay1.Text == "0") { txtDisplay1.Text = "8"; } else { txtDisplay1.Text += "8"; } } private void b9_Click(object sender, EventArgs e) { if (txtDisplay1.Text == "0") { txtDisplay1.Text = "9"; } else { txtDisplay1.Text += "9"; } } private void b0_Click(object sender, EventArgs e) { if (txtDisplay1.Text != "0") { txtDisplay1.Text += "0"; } } private void bClear_Click(object sender, EventArgs e) { txtDisplay1.Text = "0"; bil1 = 0; bil2 = 0; txtDisplay2.Text = " "; } private void bKali_Click(object sender, EventArgs e) { bil1 = Convert.ToDecimal(txtDisplay1.Text); txtDisplay2.Text = "x"; txtDisplay1.Text = " "; opr = 1; opr_selesai = true; } private void bBagi_Click(object sender, EventArgs e) { bil1 = Convert.ToDecimal(txtDisplay1.Text); txtDisplay2.Text = "/"; txtDisplay1.Text = " "; opr = 2; opr_selesai = true; } private void bKurang_Click(object sender, EventArgs e) { bil1 = Convert.ToDecimal(txtDisplay1.Text); txtDisplay2.Text = "-"; txtDisplay1.Text = " "; opr = 3; opr_selesai = true; } private void bTambah_Click(object sender, EventArgs e) { bil1 = Convert.ToDecimal(txtDisplay1.Text); txtDisplay2.Text = "+"; txtDisplay1.Text = " "; opr = 4; opr_selesai = true; } private void bHasil_Click(object sender, EventArgs e) { if(opr_selesai = true) bil2 = Convert.ToDecimal(txtDisplay1.Text); { switch(opr) { case 1: txtDisplay1.Text = Convert.ToString(bil1 * bil2); break; case 2: txtDisplay1.Text = Convert.ToString(bil1 / bil2); break; case 3: txtDisplay1.Text = Convert.ToString(bil1 - bil2); break; case 4: txtDisplay1.Text = Convert.ToString(bil1 + bil2); break; } opr_selesai = false; } } private void bKoma_Click(object sender, EventArgs e) { txtDisplay1.Text = txtDisplay1.Text + "."; } } } |
Kalkulator sederhana diatas memiliki fitur penjumlahan, pengurangan, perkalian, pembagian, serta dapat melakukan perhitungan bilangan desimal (koma). Ketika kalkulator baru saja terbuka, angka 0 akan menjadi default dari layarnya dan akan berubah ketika kita memasukkan angka dan melakukan perhitungan. Kotak kecil di pojok kiri atas menandakan perhitungan apa yang kita lakukan apakah itu penjumlahan, pengurangan, perkalian atau pembagian.
TUGAS MEMBUAT APLIKASI WEBCAM SEDERHANA C#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using AForge; using AForge.Video; using AForge.Video.DirectShow; using System.Drawing; using System.Drawing.Imaging; namespace webcamm { public partial class Form1 : Form { private FilterInfoCollection captureDevice; private VideoCaptureDevice videoSource; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { captureDevice = new FilterInfoCollection(FilterCategory.VideoInputDevice); foreach(FilterInfo deviceList in captureDevice) { boxWebcamList.Items.Add(deviceList.Name); } boxWebcamList.SelectedIndex = 0; videoSource = new VideoCaptureDevice(); } private void bStart_Click(object sender, EventArgs e) { if (videoSource.IsRunning) { videoSource.SignalToStop(); videoSource.WaitForStop(); pictureBox1.Image = null; pictureBox1.Invalidate(); } videoSource = new VideoCaptureDevice(captureDevice[boxWebcamList.SelectedIndex].MonikerString); videoSource.NewFrame += new NewFrameEventHandler(VideoSource_NewFrame); videoSource.Start(); } private void VideoSource_NewFrame(object sender, NewFrameEventArgs eventArgs) { pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone(); } private void bCapture_Click(object sender, EventArgs e) { pictureBox2.Image = (Bitmap)pictureBox1.Image.Clone(); } private void bSave_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "Save Image As"; saveFileDialog.Filter = "Image Files (*.jpg, *.png) | *.jpg, *.png"; ImageFormat imageFormat = ImageFormat.Png; if(saveFileDialog.ShowDialog() == DialogResult.OK) { string ext = System.IO.Path.GetExtension(saveFileDialog.FileName); switch (ext) { case ".jpg": imageFormat = ImageFormat.Jpeg; break; case ".png": imageFormat = ImageFormat.Png; break; } pictureBox2.Image.Save(saveFileDialog.FileName, imageFormat); } } private void bExit_Click(object sender, EventArgs e) { if (videoSource.IsRunning) { videoSource.SignalToStop(); videoSource.WaitForStop(); pictureBox1.Image = null; pictureBox1.Invalidate(); pictureBox2.Image = null; pictureBox2.Invalidate(); } Application.Exit(null); } } } |
Webcam sederhana diatas dapat melakukan capture kamera melalui kamera apa saja yang tersambung ke device ini. Kamera akan menyala ketika tombol Start ditekan dan tampilan akan muncul di kotak sebelah kiri. Ketika tombol Capture ditekan maka gambar akan tercapture dan hasilnya akan tampil di sebelah kanan. Hasil dari capture juga dapat disimpan dengan format jpg atau png. Ada juga tombol Exit untuk menutup kamera dan aplikasi.
Comments
Post a Comment