♥ Kalkulator Ku ♥

kalku

public class KALKULATOR extends javax.swing.JFrame {

double operator, hasil, bil1;
/**
* Creates new form KALKULATOR
*/
public KALKULATOR() {
super(“typocalcjava”);
initComponents();
setTitle(“K A L K U L A T O R K U by : Nurul C.”);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

  •    script tuk button no 1

private void no1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(output.getText()+1);

  •    script tuk button no 2

private void no2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(output.getText()+2);
}

  •    script tuk button no 3

private void no3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(output.getText()+3);
}

  •    script tuk button no 4

private void no4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(output.getText()+4);
}

  •    script tuk button no 5

private void no5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(output.getText()+5);
}

  •    script tuk button no 6

private void no6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(output.getText()+6);
}

  •    script tuk button no 7

private void no7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(output.getText()+7);
}

  •    script tuk button no 8

private void no8ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(output.getText()+8);
}

  •    script tuk button no 9

private void no9ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(output.getText()+9);
}

  •    script tuk button no 0

private void no0ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(output.getText()+0);
}

  •    script tuk button koma (,)

private void komaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(output.getText()+”,”);
}

  •    script tuk button CE

private void ceActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(“0”);
output.setText(“”);
}

  •    script tuk button no samadengan (=)

private void JsamaDenganActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(operator==1){
hasil = bil1+Double.parseDouble(output.getText());
output.setText((String.valueOf(hasil)));
}else if(operator==2){
hasil = bil1-Double.parseDouble(output.getText());
output.setText((String.valueOf(hasil)));
}else if(operator==3){
hasil = bil1*Double.parseDouble(output.getText());
output.setText((String.valueOf(hasil)));
}else if(operator==4){
hasil = bil1/Double.parseDouble(output.getText());
output.setText((String.valueOf(hasil)));
}else if(operator==5){
if(hasil<0){
output.setText(“Syntax Error”);
}else{
hasil = Math.pow(bil1, Double.parseDouble(output.getText()));
output.setText(String.valueOf(hasil));
}
}
}

  •    script tuk button operator tambah (+)

private void JtambahActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
operator = 1;
bil1 = Double.parseDouble(output.getText());
output.setText(“”);
}

  •    script tuk button operator kurang (-)

private void JkurangActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
operator = 2;
bil1 = Double.parseDouble(output.getText());
output.setText(“”);
}

  •    script tuk button operator kali (x)

private void JkaliActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
operator = 3;
bil1 = Double.parseDouble(output.getText());
output.setText(“”);
}

  •    script tuk button operator bagi (:)

private void JbagiActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
operator = 4;
bil1 = Double.parseDouble(output.getText());
output.setText(“”);
}

  •    script tuk button backspace / hapus

private void backspaceActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
output.setText(“”);
}

  •    script tuk button factorial

private void JfactActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
double n, c;
c = 1;
hasil = Double.parseDouble(output.getText());
for(n=1;n<=hasil;n++){
c = c * n;
}
output.setText(String.valueOf(c));
}

  •    script tuk button persen (%)

private void JpersentActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
hasil = Double.parseDouble(output.getText())/100;
output.setText(String.valueOf(hasil));
}

  •    script tuk button SIN

private void JsinActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(Double.parseDouble(output.getText())==30){
output.setText(“0.5”);
}else if(Double.parseDouble(output.getText())==0){
output.setText(“0.0”);
}else if(Double.parseDouble(output.getText())==90){
output.setText(“1.0”);
}else{
hasil = Math.sin(Double.parseDouble(output.getText())/180*22/7);
output.setText(String.valueOf(hasil));
}
}

  •   script tuk button COS

private void JcosActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(Double.parseDouble(output.getText())==60){
output.setText(“0.5”);
}else if(Double.parseDouble(output.getText())==90){
output.setText(“0.0”);
}else if(Double.parseDouble(output.getText())==0){
output.setText(“1.0”);
}else{
hasil = Math.cos(Double.parseDouble(output.getText())/180*22/7);
output.setText(String.valueOf(hasil));
}
}

  •    script tuk button TAN

private void JtanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(Double.parseDouble(output.getText())==45){
output.setText(“1.0”);
}else if(Double.parseDouble(output.getText())==0){
output.setText(“0.0”);
}else if(Double.parseDouble(output.getText())==90){
output.setText(“tak terhingga”);
}else{
hasil = Math.tan(Double.parseDouble(output.getText())/180*22/7);
output.setText(String.valueOf(hasil));
}
}

  •   script tuk button 1/1 (per)

 

private void JuntittleActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
hasil = 1/Double.parseDouble(output.getText());
output.setText(String.valueOf(hasil));
}

 

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s