| | |
actionPerformed and exceptions help?
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2007
Posts: 3
Reputation:
Solved Threads: 0
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:
the html code is:
Any kind of HELP is welcome.
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:
Java Syntax (Toggle Plain Text)
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:
Java Syntax (Toggle Plain Text)
<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.
![]() |
Similar Threads
- weird exceptions:( (Python)
- JTextPane (Java)
- How to handle exceptions in constructor? (Java)
- Help with program...Please...... (Java)
- Exceptions (Java)
- Arithmetic Exceptions and exception-handling statements (Java)
Other Threads in the Java Forum
- Previous Thread: how do i apply this binary search into this libary program
- Next Thread: java program to calculate simple interest
Views: 1080 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Java
911 addball addressbook android api append apple applet application arguments array arrays automation binary bluetooth button chat class classes client code component css csv database draw eclipse ee error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me java javaarraylist javaprojects jmf jni jpanel julia jvm key linux list loan loop map method methods mobile netbeans newbie number object oracle output packets phone print problem program programming project recursion reporting robot scanner screen se server service set size sms socket software sort sql stream string swing test threads time transfer tree ubuntu windows wrong






