Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8202429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:10:51+00:00 2026-06-07T07:10:51+00:00

I am trying to create an applet for class. I am supposed to handle

  • 0

I am trying to create an applet for class.

I am supposed to handle two possible user input mistakes. I have handled the division by zero with an if/else statement.

However. I am trying to handle an exception if the user tries to put letters or symbols into the text boxes instead of numbers….but my catch statement will not catch the issue. instead it enacts the division by 0 else statement. Please have a look and let me know if you can help

 /*
 * Curtis Sizemore
 * IT 259 - Intermediate Java
 * Unit 8
 * Working with Applets
 * I attest that this is a product of my own creation.
 * 
 */
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;

/**
 *
 * @author Curtis
 */
public class JDivide extends JApplet implements ActionListener
{
JTextField numer = new JTextField(5);
JTextField denom = new JTextField(5);
JLabel intro = new JLabel("Please enter two numbers.");
JLabel num = new JLabel("Numerator: ");
JLabel den = new JLabel("Denominator: ");
JLabel result = new JLabel();
JButton solve = new JButton("Click Me to Solve!");
Container con = getContentPane();
double numerator;
double denominator;
 double quotient;
 String n;
String d;
 String q;


@Override
public void init()
{
    con.setLayout(new FlowLayout());
    con.add(intro);
    con.add(num);
    con.add(numer);
    con.add(den);
    con.add(denom);
    con.add(solve);
    con.add(result);
    solve.addActionListener(this);
}

@Override
public void actionPerformed(ActionEvent e) 
{



      n = numer.getText();
      d = denom.getText();
    try
      {
      double numerator = Double.parseDouble(n);
    double denominator = Double.parseDouble(d);
      }
      catch(NumberFormatException x)
      {
      result.setText("Numbers Only Please.");
      }


      if(denominator==0)
      {
      result.setText("Division by 0 is undefined.");
      }
      else
      {
      double quotient = numerator/denominator;
      q = Double.toString(quotient);
      result.setText(q);
}
 }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T07:10:55+00:00Added an answer on June 7, 2026 at 7:10 am

    You need to put the rest of your code inside of the try block, either that or throw an exception. Else the method will still try to calculate the quotient even if non-numbers are entered.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a Java applet that animates a BTree. I have
I`m trying to create a Java Applet, I was looking around on the Java
I'm trying to create two models, products and product_manufacturers so that I can pull
I have a CCLayer class where I create an animated sprite that is the
I ran into troubles trying to create a gnome-panel applet with gtkmm. I dealt
I am trying to wrap a C++ class using SWIG to create a Java
I am trying to create a simple modal dialog in XCode 4. I have
i'm trying to create a photo viewer like the Apple Photos app in iOS.
I created an audio Player using java applet but i'm stuck at trying to
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.