Wednesday, April 11, 2012

mengedit atau modifikasi kalkulator menggunakan editplus

hai.... haiii... jumpa lagi kita..
nah pada kesempatan kali ini
kita kan membahas tentang mengedit
sebuah aplikasi menggunakan editplus





malam ini saya lagi belajar membuat kakulator dengan editplus
jadi harap sabar yaa...tunggu satu hari lagi pasti  udah saya posting
scriptnya....harap bersabar ya....
.. ..................

maap menunggu lama ... ini scriptnya .. silahkan di coba :

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class kal extends JFrame implements ActionListener {Label t=new Label("",Label.RIGHT);String s="";
 Button b[]=new Button[80];int op1=0,op2=0;
 boolean fa=false,fs=false,fm=false,fd=false,fr=false,fi=false;
 kal() {for(int i=0;i<10;i++) {b[i]=new Button(""+i);    b[i].addActionListener(this);}
    b[10]=new Button("/");b[11]=new Button("+");b[12]=new Button("-");
    b[13]=new Button("*");b[14]=new Button("C");b[15]=new Button("%");
    b[16]=new Button("+/-");b[17]=new Button("=");
    for(int i=10;i<18;i++) b[i].addActionListener(this);
    Box y1=Box.createVerticalBox();Box y2=Box.createVerticalBox();Box y3=Box.createVerticalBox();
    y1.add(b[1]);y1.add(b[4]);y1.add(b[7]);y1.add(b[0]);y1.add(b[12]);y1.add(b[15]);
    y2.add(b[2]);y2.add(b[5]);y2.add(b[8]);y2.add(b[10]);y2.add(b[13]);y2.add(b[16]);
    y3.add(b[3]);y3.add(b[6]);y3.add(b[9]);y3.add(b[11]);y3.add(b[14]);y3.add(b[17]);
    Box x=Box.createHorizontalBox();x.add(y1);x.add(y2);x.add(y3);
    Box y=Box.createVerticalBox();y.add(t);y.add(x);add(y);pack();
    setBackground(Color.blue);
   
    //setVisible(true);
    //setBounds(10,20,200,200);
    //setDefaultCloseOperation(this.EXIT_ON_CLOSE);
    }
  public void actionPerformed(ActionEvent e) {String c=e.getActionCommand();
    if(c=="C") s="";
    else if(c=="=") {op2=Integer.parseInt(t.getText());
      if(fa) {op1+=op2;fa=false;
      } else if(fs) {op1-=op2;fs=false;
      } else if(fm) {op1*=op2;fm=false;
      } else if(fd) {op1/=op2;fd=false;
      } else if(fr) {op1%=op2;fr=false;} s=""+op1;
    } else if(c=="+") {fa=true;op1=Integer.parseInt(t.getText());s="";
    } else if(c=="-") {fs=true;op1=Integer.parseInt(t.getText());s="";
    } else if(c=="*") {fm=true;op1=Integer.parseInt(t.getText());s="";
    } else if(c=="/") {fd=true;op1=Integer.parseInt(t.getText());s="";
    } else if(c=="%") {fr=true;op1=Integer.parseInt(t.getText());s="";
    } else if(c=="+/-") {fi=true;op1=Integer.parseInt(t.getText());op1*=-1;s=""+op1;
    } else s+=c; t.setText(s);  }
  public static void main(String[] args) {
      kal frame = new kal();
      frame.setTitle("Kalkulator");
       frame.setSize(180,250);
      frame.setVisible(true);
      frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
      frame.setVisible(true);

     }
}


Nb : jangan lupa di save sesuai dengan nama classnya klo disini nama classnya adalah kal.

No comments:

Post a Comment

Udah di baca kan.... kritik dan sarannya saya persilahkan ^_^..jangan lupa isi Buku tamunya juga ya...