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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:45:57+00:00 2026-05-30T23:45:57+00:00

My program is suppose to make a GUI that calculates the square root of

  • 0

My program is suppose to make a GUI that calculates the square root of a number that is entered. I can not figure out why this code will not compile. I keep getting the following error message:

cannot find symbol
symbol : method getText(double)

What am I doing wrong?

import java.awt.event.ActionEvent; //Next group of lines import various Java classes
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.GridLayout;
import java.text.*;

public class SquareRoot extends JFrame
{
    public static void main(String[] args) {
        //Creates Window
        JFrame frame = new JFrame();
        frame.setSize(450, 300);
        frame.setTitle("Find the Square Root");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JLabel Numberlbl = new JLabel("Enter a number:");
        final JTextField NumberField = new JTextField(10);
        NumberField.setText("");

        JLabel Answerlbl = new JLabel("Square Root of your number is:");
        final JTextField AnswerField = new JTextField(10);
        AnswerField.setText("");

        JLabel ButtonLabel = new JLabel("Calculate Square Root");
        JButton button = new JButton("√");

        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(3,2));
        panel.add(Numberlbl);
        panel.add(NumberField);
        panel.add(ButtonLabel);
        panel.add(button);
        panel.add(Answerlbl);
        panel.add(AnswerField);
        frame.add(panel);

        class CalculateListener implements ActionListener {

            public void actionPerformed(ActionEvent event) {

                double NumberX = Double.parseDouble(NumberField.getText());
                double Answer = Math.sqrt(NumberX);
                AnswerField.setText(Answer);

            }
        }

        ActionListener listener = new CalculateListener();
        button.addActionListener(listener);

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);

        }
    }
  • 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-30T23:45:59+00:00Added an answer on May 30, 2026 at 11:45 pm

    The only compilation error I got was for the AnswerField.setText() line – if you look at the API reference for setText() it takes a string, but you are trying to pass it a double.

    Have a look at the NumberFormat class for converting the double to a string correctly. A simpler option is to use a Double object (as opposed to the double data type, note capitalization), and use its toString() method. A down-and-dirty method is to write it as (“” + Answer), since it will auto-convert it for you.

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

Sidebar

Related Questions

Can anyone tell me why this crashes my program? It's suppose to make it
Suppose that I have a Java program within an IDE (Eclipse in this case).
Suppose I have a function in a single threaded program that looks like this
Say suppose I am running a java program through command line. And this program
Suppose I have a big program that consists of hundreds of methods in it.
suppose that no bytecode is generated for a program, like in Ruby, Perl, or
Suppose I create a file for writing like this: std::ofstream my_file(filename, std::ios_base::out | std::ios_base::trunc);
I'm writing a C++ program that has a large number of classes. In my
Suppose someone makes a program to play chess, or solve sudoku. In this kind
suppose if a program make a operating system function call and I have to

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.