Syafi'i Blog's'

Senin, 16 Maret 2009

Pembagian

/**
* @(#)pembagian.java
*
*
* @author syafii jauhari
* @version 1.00 2009/3/11
*/

import javax.swing.*;
import java.awt.event.*;
public class pembagian extends JFrame
{
JLabel ljudul=new JLabel("..:: PEMBAGIAN ::..");
JLabel lbil1 =new JLabel("Bilangan Pertama");
JLabel lbil2 =new JLabel("Bilangan Kedua");
JLabel lhsl =new JLabel("Hasil Pembagian");
JTextField tbil1=new JTextField(20);
JTextField tbil2=new JTextField(20);
JTextField tbil3=new JTextField(20);
JButton pro=new JButton("Proses Pembagian");
JButton ulng=new JButton("Ulangi");
JButton klu=new JButton("Keluar");
pembagian()
{
setTitle("..:: PEMBAGIAN ::..");
setLocation(300,100);
setSize(250,230);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void komponen_visual()
{
getContentPane().setLayout(null);
getContentPane().add(ljudul);
ljudul.setBounds(60,7,200,20);
getContentPane().add(lbil1);
lbil1.setBounds(10,30,110,20);
getContentPane().add(lbil2);
lbil2.setBounds(10,50,100,20);
getContentPane().add(lhsl);
lhsl.setBounds(10,110,100,20);
getContentPane().add(tbil1);
tbil1.setBounds(125,30,100,20);
getContentPane().add(tbil2);
tbil2.setBounds(125,50,100,20);
getContentPane().add(tbil3);
tbil3.setBounds(125,110,100,20);
getContentPane().add(pro);
pro.setBounds(10,80,216,20);
getContentPane().add(ulng);
ulng.setBounds(10,140,216,20);
getContentPane().add(klu);
klu.setBounds(10,168,216,20);
setVisible(true);
}
void aksi_reaksi()
{
pro.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
double A=Double.parseDouble(tbil1.getText());
double B=Double.parseDouble(tbil2.getText());
if (B == 0)
{

String bilbru = JOptionPane.showInputDialog(null,
"Masukkan Bilangan Lain,Tidak boleh bilangan '0'",
"Penggantian Bilangan",JOptionPane.INFORMATION_MESSAGE);
int C= Integer.parseInt(bilbru);
tbil2.setText(bilbru);
String H=String.valueOf(A/C);
tbil3.setText(H);
}
else
{
String H=String.valueOf(A/B);
tbil3.setText(H);
}

}
});
pro.addKeyListener(new KeyAdapter()
{
public void keyPressed(KeyEvent e)
{
if (e.getKeyCode()==e.VK_F1)// untuk keyboard F1
{
double A=Double.parseDouble(tbil1.getText());
double B=Double.parseDouble(tbil2.getText());
if (B == 0)
{

String bilbru = JOptionPane.showInputDialog(null,
"Masukkan Bilangan Lain,Tidak boleh bilangan '0'",
"Penggantian Bilangan",JOptionPane.INFORMATION_MESSAGE);
int C= Integer.parseInt(bilbru);
tbil2.setText(bilbru);
String H=String.valueOf(A/C);
tbil3.setText(H);
}
else
{
String H=String.valueOf(A/B);
tbil3.setText(H);
}
ulng.requestFocus();
}
}
});
tbil1.addKeyListener(new KeyAdapter()
{
public void keyPressed(KeyEvent e)
{
if (e.getKeyCode()==e.VK_ENTER)// untuk keyboard enter
{
tbil2.requestFocus();
}
}
});
tbil2.addKeyListener(new KeyAdapter()
{
public void keyPressed(KeyEvent e)
{
if (e.getKeyCode()==e.VK_ENTER)// untuk keyboard enter
{
pro.requestFocus();
}
}
});
/** ulng.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
tbil1.setText("");
tbil2.setText("");
tbil3.setText("");
}
});*/
ulng.addKeyListener(new KeyAdapter()
{
public void keyPressed(KeyEvent e)
{
if (e.getKeyCode()==e.VK_ENTER)// untuk keyboard enter
{
tbil1.setText("");
tbil2.setText("");
tbil3.setText("");
tbil1.requestFocus();
}
}
});
klu.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int kluar = JOptionPane.showConfirmDialog(null,"Yakin Keluar",
"Konfirmasi",JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if ( kluar ==0)
{
System.exit(0);
}
}
});
}
public static void main (String[] args)
{
pembagian PB=new pembagian();
PB.komponen_visual();
PB.aksi_reaksi();
}


}

0 komentar:

Template by : auraipank x-template.blogspot.com