Applet DIViSION

 Apple divers program 


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.Applet;
/*<applet code="Divers.class"width=600 height=300>
</applet>*/
public class Divers extends Applet implements ActionListener 
{
    Label l1, l2, l3;
    TextField t1, t2, Result;
    Button b1;
    public void init()
     {
        l1 = new Label("Enter first num");
        add(l1);
        t1 = new TextField(10);
        add(t1);

        l2 = new Label("Enter second num");
        add(l2);
        t2 = new TextField(10);
        add(t2);

        l3 = new Label("The result:");
        add(l3);
        Result = new TextField(10);
        add(Result);

        b1 = new Button("Divide");
        add(b1);

        b1.addActionListener(this);
    }

    public void actionPerformed(ActionEvent e) 
    {
        if (e.getSource() == b1) 
        {
            try {
                int value1 = Integer.parseInt(t1.getText());
                int value2 = Integer.parseInt(t2.getText());
                int res = value1 / value2;
                Result.setText(String.valueOf(res));
            } 
            catch (NumberFormatException nfe) 
            {
                JOptionPane.showMessageDialog(null, "Not a number");
            } catch (ArithmeticException ae) 
            {
                JOptionPane.showMessageDialog(null, "Arithmetic Exception");
}
}
}
}



output :


Comments

Popular posts from this blog

SINGLE LINKED LIST by smd

CLL by smd

QUEUE USING ARRAYS by smd