Selamat malam sobat kali ini mumpung lagi semangat ngeposting saya akan share program sederhana untuk para sobat2 blogger... cekidooottt....
Source codenya:
import
javax.swing.*;
import java.awt.event.*;
class
calculator extends JFrame
{
JLabel garis=new JLabel
("============================================");
JLabel bawah=new JLabel
("============================================");
JLabel judul=new JLabel ("By Noviyanto
Fadholi | vian.missu@london.com");
JLabel poli=new JLabel ("Teknik
Informatika 2011/2012");
JLabel nama=new JLabel ("Calculator Vr
1.0");
JTextField data1=new JTextField(20);
JTextField data2=new JTextField(20);
JButton tambah=new JButton("+");
JButton kurang=new JButton("-");
JButton kali=new JButton("x");
JButton bagi=new JButton("/");
JButton sin=new JButton("Sin");
JButton cosinus=new
JButton("Cos");
JButton tan=new JButton("Tan");
JButton kuadrat=new
JButton("X2");
JButton log=new JButton("log");
JButton persen=new JButton("%");
JButton akar=new JButton("Akar");
JTextField hasil=new JTextField(20);
JButton exit=new
JButton("EXIT");
calculator(){
setTitle("Calc Vr 1.0 | Power
By VIAN");
setLocation(500,250);
setSize(350,350);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void komponenVisual(){
getContentPane().setLayout(null);
getContentPane().add(akar);
akar.setBounds(165,215,105,20);
getContentPane().add(persen);
persen.setBounds(70,215,90,20);
getContentPane().add(poli);
poli.setBounds(72,270,310,20);
getContentPane().add(bawah);
bawah.setBounds(10,290,310,20);
getContentPane().add(garis);
garis.setBounds(10,50,310,20);
getContentPane().add(judul);
judul.setBounds(30,30,270,20);
getContentPane().add(nama);
nama.setBounds(117,10,120,20);
getContentPane().add(data1);
data1.setBounds(70,115,90,20);
getContentPane().add(data2);
data2.setBounds(165,115,105,20);
getContentPane().add(tambah);
tambah.setBounds(70,140,55,20);
getContentPane().add(kurang);
kurang.setBounds(130,140,55,20);
getContentPane().add(kali);
kali.setBounds(70,165,55,20);
getContentPane().add(bagi);
bagi.setBounds(130,165,55,20);
getContentPane().add(sin);
sin.setBounds(190,140,80,20);
getContentPane().add(cosinus);
cosinus.setBounds(190,165,80,20);
getContentPane().add(tan);
tan.setBounds(190,190,80,20);
getContentPane().add(kuadrat);
kuadrat.setBounds(70,190,55,20);
getContentPane().add(log);
log.setBounds(130,190,55,20);
getContentPane().add(hasil);
hasil.setBounds(70,90,200,20);
getContentPane().add(exit);
exit.setBounds(70,240,200,20);
setVisible(true);
}
void AksiReaksi(){
tambah.addActionListener(new
ActionListener(){
public void
actionPerformed(ActionEvent e){
int
x=Integer.parseInt(data1.getText());
int
y=Integer.parseInt(data2.getText());
String
z=String.valueOf(x+y);
hasil.setText(z);
}});
kurang.addActionListener(new
ActionListener(){
public void actionPerformed(ActionEvent
e){
int
a=Integer.parseInt(data1.getText());
int b=Integer.parseInt(data2.getText());
String c=String.valueOf(a-b);
hasil.setText(c);
}});
kali.addActionListener(new
ActionListener(){
public void
actionPerformed(ActionEvent e){
int
r=Integer.parseInt(data1.getText());
int s=Integer.parseInt(data2.getText());
String t=String.valueOf(r*s);
hasil.setText(t);
}});
bagi.addActionListener(new
ActionListener(){
public void
actionPerformed(ActionEvent e){
int
o=Integer.parseInt(data1.getText());
int p=Integer.parseInt(data2.getText());
String q=String.valueOf(o/p);
hasil.setText(q);
}});
sin.addActionListener(new
ActionListener(){
public void actionPerformed(ActionEvent e){
double
m=Integer.parseInt(data1.getText());
String k=String.valueOf(Math.sin(m));
hasil.setText(k);
}});
cosinus.addActionListener(new
ActionListener(){
public void actionPerformed(ActionEvent e){
double
m=Integer.parseInt(data1.getText());
String k=String.valueOf(Math.cos(m));
hasil.setText(k);
}});
tan.addActionListener(new
ActionListener(){
public void actionPerformed(ActionEvent e){
double
w=Integer.parseInt(data1.getText());
String d=String.valueOf(Math.tan(w));
hasil.setText(d);
}});
kuadrat.addActionListener(new
ActionListener(){
public void actionPerformed(ActionEvent e){
int
l=Integer.parseInt(data1.getText());
int j=Integer.parseInt(data2.getText());
String f=String.valueOf(Math.pow(l,j));
hasil.setText(f);
}});
log.addActionListener(new
ActionListener(){
public void actionPerformed(ActionEvent e){
double v=Integer.parseInt(data1.getText());
String i=String.valueOf(Math.log(v));
hasil.setText(i);
}});
persen.addActionListener(new
ActionListener(){
public void actionPerformed(ActionEvent e){
double
u=Integer.parseInt(data1.getText());
String o=String.valueOf(u/100);
hasil.setText(o);
}});
akar.addActionListener(new
ActionListener(){
public void actionPerformed(ActionEvent e){
double
r=Integer.parseInt(data1.getText());
String x=String.valueOf(Math.sqrt(r));
hasil.setText(x);
}});
exit.addActionListener(new
ActionListener(){
public void
actionPerformed(ActionEvent e){
System.exit(0);
}});}
public static void main(String args[])
{
calculator c=new calculator();
c.komponenVisual();
c.AksiReaksi();
}}
Hasil outputnya: