0% found this document useful (0 votes)
39 views10 pages

Program Kalkulator Java

The document provides instructions for creating a calculator application in Java Script. It describes opening a new project in NetBeans, creating a user interface with buttons for numbers 0-9, operators like + - * /, and an equals button. It includes code for assigning actions to each button, such as appending numbers to a display or performing calculation operations. The code defines variables to store number values, operations, and results.

Uploaded by

Muhamad Rasya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views10 pages

Program Kalkulator Java

The document provides instructions for creating a calculator application in Java Script. It describes opening a new project in NetBeans, creating a user interface with buttons for numbers 0-9, operators like + - * /, and an equals button. It includes code for assigning actions to each button, such as appending numbers to a display or performing calculation operations. The code defines variables to store number values, operations, and results.

Uploaded by

Muhamad Rasya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

CARA MEMBUAT PROGRAM

KALKULATOR DI JAVA SCRIPT


1. Buka Aplikasi NetBeans

2. Kemudian Klik File – New Project kemudian pilih di bagian kategori JAVA WITH ANT di bagian
project pilih JAVA APPLICATION lalu klik NEXT.

3. Setelah itu di bagian kotak dialog NEW JAVA APPLICATION isi bagian PROJECT NAME dan
UNCHECK CREATE MAIN CLASS . kemudian klik FINISH.
4. Lanjut membuat Form Baru
5. Buatlah Form Kalkulator seperti gamabar di atas menggunakan TOOLBOX DAN PROPERTIES

SOURCE CODE
Mendefinisikan Variabel dan tipe data .

public class TampilanKalkulator extends javax.swing.JFrame {


String angka;
double jumlah,angka1,angka2;
int pilih;
Source Code Button(Tombol) 0 s.d 9

private void btnangka0ActionPerformed(java.awt.event.ActionEvent evt) {

angka += "0";

display.setText(angka);

// TODO add your handling code here:

private void btnangka1ActionPerformed(java.awt.event.ActionEvent evt) {

angka += "1";

display.setText(angka);

// TODO add your handling code here:

private void btnangka2ActionPerformed(java.awt.event.ActionEvent evt) {

angka += "2";

display.setText(angka);

// TODO add your handling code here:

private void btnangka3ActionPerformed(java.awt.event.ActionEvent evt) {

angka += "3";

display.setText(angka);

// TODO add your handling code here:

private void btnangka4ActionPerformed(java.awt.event.ActionEvent evt) {

angka += "0";

display.setText(angka);

// TODO add your handling code here:

}
private void btnangka5ActionPerformed(java.awt.event.ActionEvent evt) {

angka += "5";

display.setText(angka);

// TODO add your handling code here:

private void btnangka6ActionPerformed(java.awt.event.ActionEvent evt) {

angka += "6";

display.setText(angka);

// TODO add your handling code here:

private void btnangka7ActionPerformed(java.awt.event.ActionEvent evt) {

angka += "7";

display.setText(angka);

// TODO add your handling code here:

private void btnangka8ActionPerformed(java.awt.event.ActionEvent evt) {

angka += "8";

display.setText(angka);

// TODO add your handling code here:

private void btnangka9ActionPerformed(java.awt.event.ActionEvent evt) {

angka += "9";

display.setText(angka);

// TODO add your handling code here:

}
Source Code Button Koma

private void btnkomaActionPerformed(java.awt.event.ActionEvent evt) {

angka += ".";

display.setText(angka);

// TODO add your handling code here:

Source Code Button Clear(Hapus)

private void btnhapusActionPerformed(java.awt.event.ActionEvent evt) {

display.setText("");

angka1=0.0;

angka2=0.0;

jumlah=0.0;

angka="";

// TODO add your handling code here:

Source Code Button +,-,*,/ ( Perhitungan Aritmatika)

private void btntambahActionPerformed(java.awt.event.ActionEvent evt) {

angka1=Double.parseDouble(angka);

display.setText("+");

angka="";

pilih=1;

// TODO add your handling code here:


private void btnkurangActionPerformed(java.awt.event.ActionEvent evt) {

angka1=Double.parseDouble(angka);

display.setText("-");

angka="";

pilih=2;

// TODO add your handling code here:

private void btnkaliActionPerformed(java.awt.event.ActionEvent evt) {

angka1=Double.parseDouble(angka);

display.setText("*");

angka="";

pilih=3;

// TODO add your handling code here:

private void btnbagiActionPerformed(java.awt.event.ActionEvent evt) {

angka1=Double.parseDouble(angka);

display.setText("/");

angka="";

pilih=4;

// TODO add your handling code here:

Source Code Button sama dengan (=)

private void btnsamadenganActionPerformed(java.awt.event.ActionEvent evt) {

switch(pilih){

case 1:

angka2= Double.parseDouble(angka);

jumlah= angka1 + angka2;

angka = Double.toString(jumlah);

display.setText(angka);

break;
case 2:

angka2 = Double.parseDouble(angka);

jumlah = angka1 - angka2;

angka = Double.toString(jumlah);

display.setText(angka);

break;

case 3:

angka2 = Double.parseDouble(angka);

jumlah = angka1 * angka2;

angka = Double.toString(jumlah);

display.setText(angka);

break;

case 4:

angka2 = Double.parseDouble(angka);

jumlah = angka1 / angka2;

angka = Double.toString(jumlah);

display.setText(angka);

break;

default:

break;

}
Cara Mengganti Nama Komponen Kalkulator

Beri nama tiap tombol sesuai dengan daftar gambar di bawah ini.

You might also like