NET Framework - Kalkulator dan Currency Converter Sederhana

- Winform - Kalkulator
Jadi, aplikasi pertama adalah kalkulator sederhana.
Aplikasi ini akan menerima input dari pengguna dengan 2 buah angka yang akan dilakukan perhitungan
kemudian pengguna akan memilih operasi yang akan dilakukan dengan mengklik button yang akan disediakan.
Untuk kode sumber yang digunakan cukup sederhana sebagai berikut.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 KalkulatorSederhana
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
LBLHasil.Text = "";
}
private void button1_Click(object sender, EventArgs e)
{
if(String.IsNullOrEmpty(textBox1.Text) || String.IsNullOrEmpty(textBox2.Text))
{
MessageBox.Show("Angka 1 dan 2 harus diisi");
}
int a, b, c;
a = int.Parse(this.textBox1.Text);
b = int.Parse(this.textBox2.Text);
c = a + b;
this.LBLHasil.Text = c.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(textBox1.Text) || String.IsNullOrEmpty(textBox2.Text))
{
MessageBox.Show("Angka 1 dan 2 harus diisi");
}
int a, b, c;
a = int.Parse(this.textBox1.Text);
b = int.Parse(this.textBox2.Text);
c = a + b;
this.LBLHasil.Text = c.ToString();
}
private void button5_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
LBLHasil.Text = "";
}
private void button3_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(textBox1.Text) || String.IsNullOrEmpty(textBox2.Text))
{
MessageBox.Show("Angka 1 dan 2 harus diisi");
}
int a, b, c;
a = int.Parse(this.textBox1.Text);
b = int.Parse(this.textBox2.Text);
c = a * b;
this.LBLHasil.Text = c.ToString();
}
private void button4_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(textBox1.Text) || String.IsNullOrEmpty(textBox2.Text))
{
MessageBox.Show("Angka 1 dan 2 harus diisi");
}
double a, b, c;
a = double.Parse(this.textBox1.Text);
b = double.Parse(this.textBox2.Text);
c = a / b;
this.LBLHasil.Text = c.ToString();
}
}
}
Untuk desain formnya sebagai berikut.
Untuk hasil akhirnya sebagai berikut.
- WPF - Currency Converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 KalkulatorSederhana | |
{ | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void label1_Click(object sender, EventArgs e) | |
{ | |
} | |
private void label2_Click(object sender, EventArgs e) | |
{ | |
} | |
private void Form1_Load(object sender, EventArgs e) | |
{ | |
textBox1.Clear(); | |
textBox2.Clear(); | |
LBLHasil.Text = ""; | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
if(String.IsNullOrEmpty(textBox1.Text) || String.IsNullOrEmpty(textBox2.Text)) | |
{ | |
MessageBox.Show("Angka 1 dan 2 harus diisi"); | |
} | |
int a, b, c; | |
a = int.Parse(this.textBox1.Text); | |
b = int.Parse(this.textBox2.Text); | |
c = a + b; | |
this.LBLHasil.Text = c.ToString(); | |
} | |
private void button2_Click(object sender, EventArgs e) | |
{ | |
if (String.IsNullOrEmpty(textBox1.Text) || String.IsNullOrEmpty(textBox2.Text)) | |
{ | |
MessageBox.Show("Angka 1 dan 2 harus diisi"); | |
} | |
int a, b, c; | |
a = int.Parse(this.textBox1.Text); | |
b = int.Parse(this.textBox2.Text); | |
c = a + b; | |
this.LBLHasil.Text = c.ToString(); | |
} | |
private void button5_Click(object sender, EventArgs e) | |
{ | |
textBox1.Clear(); | |
textBox2.Clear(); | |
LBLHasil.Text = ""; | |
} | |
private void button3_Click(object sender, EventArgs e) | |
{ | |
if (String.IsNullOrEmpty(textBox1.Text) || String.IsNullOrEmpty(textBox2.Text)) | |
{ | |
MessageBox.Show("Angka 1 dan 2 harus diisi"); | |
} | |
int a, b, c; | |
a = int.Parse(this.textBox1.Text); | |
b = int.Parse(this.textBox2.Text); | |
c = a * b; | |
this.LBLHasil.Text = c.ToString(); | |
} | |
private void button4_Click(object sender, EventArgs e) | |
{ | |
if (String.IsNullOrEmpty(textBox1.Text) || String.IsNullOrEmpty(textBox2.Text)) | |
{ | |
MessageBox.Show("Angka 1 dan 2 harus diisi"); | |
} | |
double a, b, c; | |
a = double.Parse(this.textBox1.Text); | |
b = double.Parse(this.textBox2.Text); | |
c = a / b; | |
this.LBLHasil.Text = c.ToString(); | |
} | |
} | |
} |
Aplikasi kedua adalah aplikasi untuk melakukan konversi mata uang. Pada aplikasi ini pengguna dapat menuliskan mata
uang yang ingin dikonversi pada text box dan juga memilih mata uang pada combo box yang
telah disediakan. Setiap pengguna melakukan perubahan baik jumlah maupun mata uang yang digunakan, maka secara
otomatis hasil akan diperbarui sesuai dengan input terakhir pengguna. Untuk data kurs-nya, saya menggunakan API dari
fixer.io dengan versi yang gratis. Untuk kode sumbernya bisa dilihat di link GitHub ini.
Untuk desain dari WPFnya sebagai berikut.
Untuk hasil akhirnya sebagai berikut.
Komentar
Posting Komentar