Hi this is my first post here:cheesy:.
I'm having a problem with how to throw exception in an applet and how to add actionPerformed to other buttons.
This applet calculates the sqare roots of an equation.
It calculates the stuf ok but the thing is that I want to throw an
exception when any of the TextFields are emty. Other thing I want the
RESET Button to clear the TextFields when clicked.
This is the code:

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.lang.*;
import java.lang.String;

public class Kv extends java.applet.Applet implements ActionListener {



    public class Isklucok extends NumberFormatException
        {
            public Isklucok()
            {
                super("Enter a number.");
            }
        }


     Label aa = new Label("a:");
     Label bb = new Label("b:");
     Label cc = new Label("c:");

     TextField A = new TextField();
     TextField B = new TextField();
     TextField C = new TextField();

     Button otkaz = new Button("Reset");
     Button calc = new Button("Calculate");

    double X1, X2, a, b, c, D;

    public void init() {

        setLayout(new GridLayout(4,2));
        add(aa);
        add(A);
        add(bb);
        add(B);
        add(cc);
        add(C);
        add(otkaz);
        add(calc);

        calc.addActionListener(new Racunaj()); 
        otkaz.addActionListener(this);
        }
        
        class Racunaj implements ActionListener throws new Isklucok() 
        
       {
            public void actionPerformed(ActionEvent e) 
            {
            
                a = Double.parseDouble(A.getText());  
                   b = Double.parseDouble(B.getText());  
                c = Double.parseDouble(C.getText());    
            
                D = (b*b-4*a*c);

                X1 = ((-b)-Math.sqrt(D))/(2*a);     
                X2 = ((-b)+Math.sqrt(D))/(2*a);    
            
                if(D>0)
                JOptionPane.showMessageDialog(this, "the numbers are real: "+X1+" , "+X2);
                else if(D<0)
                JOptionPane.showMessageDialog(this, "the numbers are komplex");
                else
                JOptionPane.showMessageDialog(this, "the numbers are real and equal. "+X1+" , "+X2);
                
                
                if ((A.getText()==null)||(B.getText()==null)||(C.getText()==null)) throw new Isklucok();
                    
                
            }
            
            
       }
       public class Zaebi extends Kv implements ActionListener 
            {
                A.setText("");
                B.setText="";
                C.setText="";
            }
}

the html code is:

<html>
    <head>
    </head>
    <body bgcolor="000000">
        <center>
            <applet
                code    = "Kv.class"
                width    = "250"
                height    = "125"
                >
            </applet>
        </center>
    </body>
</html>

Any kind of HELP is welcome.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.