import java.applet.Applet;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.event.*;
import java.text.DecimalFormat;

public class sifirabolmetesti extends JApplet implements ActionListener
{
JPanel girdi;
protected JLabel L1,L2;
protected JTextField T1,T2;
protected JTextArea TA;
private int sayi1,sayi2;
private double sonuc;
Container c;

public void init()
{
c=getContentPane();
girdi=new JPanel(new FlowLayout());
sayi1=0;
sayi2=1;
L1=new JLabel("Payi gir : ");
L2=new JLabel("Paydayi gir : ");
T1=new JTextField(10);
T2=new JTextField(10);
TA=new JTextArea();
T2.addActionListener(this);
girdi.add(L1);
girdi.add(T1);
girdi.add(L2);
girdi.add(T2);
c.add(girdi,BorderLayout.NORTH);
c.add(TA,BorderLayout.SOUTH);
}

public double bol(int s1,int s2) throws sifiraBolunmeException
{
if(s2==0) throw new sifiraBolunmeException();
return (double) s1/s2;
}

public void actionPerformed(ActionEvent e)
{
DecimalFormat hassaslik3=new DecimalFormat("#.000");

try{
sayi1=Integer.parseInt(T1.getText());
sayi2=Integer.parseInt(T2.getText());
T1.setText("");
T2.setText("");
sonuc=bol(sayi1,sayi2);
TA.setText(sayi1+" / "+sayi2+" = "+hassaslik3.format(sonuc));
}
catch(NumberFormatException nfe)
   {TA.setText("iki tam sayi girmelisiniz.");}
catch(sifiraBolunmeException sbh)
   {TA.setText(sbh.toString());}
}
    public static void main(String s[])
    {
        JFrame f = new JFrame("Sıfıra bölme testi");
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {System.exit(0);}
        });
        JApplet applet = new sifirabolmetesti();
        f.getContentPane().add("Center", applet);
        applet.init();
        f.pack();
        f.setSize(new Dimension(800,400));
        f.setVisible(true);
    }
}
