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 6911623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:58:51+00:00 2026-05-27T08:58:51+00:00

So i was writing a program to solve a quadratic equation, and everything works

  • 0

So i was writing a program to solve a quadratic equation, and everything works apart from when it comes to making 2 JLabels (previously empty) show the answers, (this happens when the user clicks a JButton)

Here is the whole program, because i have no idea where the error is.

import java.awt.event.*;

import javax.swing.*;


public class Third implements ActionListener {

    //--------------
    //Data Members
    //--------------
/**
 * Top level window 
 */
JFrame top;
/**
 * Changed into a string by ConvertToDouble(string str);
 */
double a, b, c; 
double answer1,answer2;
JTextField inputA, inputB, inputC;  
JLabel describeA, describeB, describeC, print1, print2;
JButton submit;
String aa, bb, cc;
String result1, result2;
String strA, strB, strC;




    public Third(){

    top = new JFrame("Ned's quadratic equation solver");
    top.setVisible(true);
    top.setLayout(null);
    top.setBounds(50,50,250,250);


    inputA = new JTextField(12);    
    inputA.setBounds(100,30,200,25);
    inputB = new JTextField(12);    
    inputB.setBounds(100,105,200,25);
    inputC = new JTextField(12);    
    inputC.setBounds(100,185,200,25);

    describeA = new JLabel("Enter A here:");
    describeA.setBounds(10,30,200,25);
    describeB = new JLabel("Enter B here:");
    describeB.setBounds(10,105,200,25);
    describeC = new JLabel("Enter C here:");
    describeC.setBounds(10,185,200,25);

    print1 = new JLabel();
    print1.setBounds(15,290,1000,10);
    print2 = new JLabel();
    print2.setBounds(15,310,1000,10);

    submit = new JButton ("WHAT DOES X = ???");
    submit.setBounds(50,230,150,25);
    submit.addActionListener(this);



    top.add(inputA);
    top.add(inputB);
    top.add(inputC);

    top.add(describeA);
    top.add(describeB);
    top.add(describeC);

    top.add(submit);
    top.doLayout();
    }


    public void actionPerformed(ActionEvent event) {

        aa = inputA.getText();
        bb = inputB.getText();
        cc = inputC.getText();

        a = convertToDouble(aa);
        b = convertToDouble(bb);
        c = convertToDouble(cc);

        makeAns(a,b,c);

     /*
      * DEBUG CODE
      *
      * System.out.println(a);
      * System.out.println(b);
      * System.out.println(c);
      * System.out.println(answer1);
      * System.out.println(answer2);
      */
        result1 = "x = " + answer1;
        result2 = "x = " + answer2;

            print1.setText(result1);
            print2.setText(result2);

            //System.out.println(result1);

            top.doLayout();


    }



private void makeAns(double x,double y,double z){   

        answer1 =(-y + Math.sqrt (y*y-4*x*z))/(2*x);
        answer2 =(-y - Math.sqrt (y*y-4*x*z))/(2*x);

    }

private double convertToDouble (String str) {

    Double dubb = new Double(str);
    return  dubb.doubleValue(); 
}


}
  • 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-05-27T08:58:52+00:00Added an answer on May 27, 2026 at 8:58 am

    You’ve got to add a component to the GUI first before it can display anything. Where do you add your print1 and print2 JLabels to the GUI or to any container for that matter?

    Also, you’ll want to use layout managers rather than null layout and absolute positioning to make coding your GUI’s much easier.

    Also, you’ll want to call setVisible(true) on the JFrame after adding all components.

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

Sidebar

Related Questions

As part of a program I'm writing, I need to solve a cubic equation
I'm having difficulty writing a program to solve this exercise from a Java text
I'm writing a scientific program to solve Maxwell's equation with C++. The task in
If you are writing a program that is executable from the command line, you
I'm writing a program to read from a POP3 mailbox and upload the email
I'm writing a program to solve the result of primitive recursive functions: 1 --Basic
I'm writing a program to solve a geometry problem. My algorithm doesn't treat collinear
I am writing a Prolog program to solve a problem. The problem takes three
I'm writing a program to solve an 8 tile sliding puzzle for an AI
I am writing a program to try to solve a math problem. I need

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.