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

  • Home
  • SEARCH
  • 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 8604539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:35:53+00:00 2026-06-12T02:35:53+00:00

I have three classes. Input.java (This is the gui class) This class takes in

  • 0

I have three classes.

Input.java (This is the gui class)
This class takes in 3 values thru textfields and has button to trigger an event and finally a label to show the result of the values (double values)

package javalearning;

import javax.swing.JOptionPane;


public class Input extends javax.swing.JFrame {

    /**
     * Creates new form Input
     */
    public Input() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        result_lbl = new javax.swing.JLabel();
        value1 = new javax.swing.JTextField();
        value2 = new javax.swing.JTextField();
        value3 = new javax.swing.JTextField();
        btn1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        result_lbl.setText("jLabel1");

        btn1.setText("jButton1");
        btn1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(99, 99, 99)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btn1)
                    .addComponent(result_lbl)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(value1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE)
                        .addComponent(value2, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(value3, javax.swing.GroupLayout.Alignment.TRAILING)))
                .addContainerGap(100, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(44, 44, 44)
                .addComponent(value1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(value2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(value3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(result_lbl)
                .addGap(23, 23, 23))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

    private void btn1ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
         JOptionPane.showMessageDialog(null, "hello");
         Computation actual_triangle = new Computation(Double.parseDouble(value1.getText()),Double.parseDouble(value2.getText()),Double.parseDouble(value3.getText()));

    }

    public static void main(String args[]) {

        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Input.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Input.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Input.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Input.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new Input().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JButton btn1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel result_lbl;
    private javax.swing.JTextField value1;
    private javax.swing.JTextField value2;
    private javax.swing.JTextField value3;
    // End of variables declaration
}

Computation.java
This is the place all the values are will be computed to produce a result

package javalearning;
public class Computation {

    private double side_a, side_b, side_c,result;


   public Computation(double side_a, double side_b, double side_c)
   {
       this.side_a = side_a;
       this.side_b = side_b;
       this.side_c = side_c;
      valueException ive = new valueException();
      //here if there is a message being sent from the valueException method then the message have to be relayed back to the Input.result_lbl.setText()
      ive.checkvalidation(side_a, side_b, side_c);

   }

   public double getsSide_A()
   {
       return side_a;
   }

   public void setsSide_A(double side_a)
   {
       this.side_a = side_a;
   }

   public double getsSide_B()
   {
       return side_b;
   }

   public void setsSide_B(double side_b)
   {
       this.side_b = side_b;
   }

   public double getsSide_C()
   {
       return side_c;
   }

   public void setsSide_C(double side_c)
   {
       this.side_c = side_c;
   }

   public double calculateArea()
    {
        result = Math.sqrt(side_a*side_b*side_c);
        return result;
    }

}

valueException.java

This is the class that outputs all kinds of errors depending on the user inputs,
example 1: the user types in a string for either one or all the textfields then a message will return to the label class.
But this is the twist, this class have to be called from the Computation.java not from Input.java

package javalearning;
public class valueException {

    String message;
    double a_side, b_side,c_side,result;


    public String checkvalidation(double a_side, double b_side, double c_side)
    {
        if((a_side + b_side > c_side)||(a_side + c_side > b_side)||(c_side + b_side > a_side))
        {

           //NOTHING TO DO JUST PROCEED BACK TO COMPUTATION and go the Computation.calculatearea() method

        }

        else
        {
            message = "The values you entered cannot form a shape";
        }
      return message;  
    }

}

Problem 1:
So I am having difficulty figuring out how to relay back the message from the valueException class back to the Computation class and from there to the Input class?

Problem 2:
If there is nothing wrong with the entered values in Input.java then revert back the process to the Computation class to do the rest of the program , as this is the only class that is calling the valueException class, I am not sure the exact code to put in.

I have commented the problems where I am facing the problem, I put in these comments at places where I think they shld be.

  • 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-12T02:35:54+00:00Added an answer on June 12, 2026 at 2:35 am

    Well I think the reason you are confused is because, you are not sure how to pass values between classes.
    Since you say you are starting to learn programming (appreciate you for that). But you have take every opportunity to learn and explore new things, but not too much as this might deviate you from the objective. So what you can do for your
    problem 1:
    You can relay back the message from the exception class to computation class then again relay back to the input class

    problem 2:
    a simple break; will break the statement and returns back control to the original point of code where this loop/or in your case the class it is called from.

    I am assuming you know how to code the rest.

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

Sidebar

Related Questions

I have a java program that has some number of classes. Three methods taken
I have three classes; Classes A and B both reference class C . How
If I have three classes class A class B extends A class C extends
Have three classes User, Group and Field. Many to many relationship on User /
I have three classes that I am using and have shortened for ease of
I have three classes: PurchaseOrder, PurchaseOrderLine, Item PurchaseOrder children are PurchaseOrderLine which is related
I have three classes, I am simply display my Facebook friends in tableView. And
I have three classes that all have a static function called 'create'. I would
I have three classes: ClassA , ClassB , ClassC . ClassC extends ClassB which
In my code I have three classes as follows: Forum , Forum::Thread and Forum::Post

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.