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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:50:04+00:00 2026-06-16T05:50:04+00:00

Alright so my program is getting the user’s input to figure out the prime

  • 0

Alright so my program is getting the user’s input to figure out the prime numbers (up to the max which the user entered), and then display these results in a scrollable JFrame. I have done all of that (I believe so at least) but keep getting one error when I try and compile it. Also, if you see any other mistakes that I have missed feel free to let me know!

Code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class PrimeNumbersJ extends JFrame
{
    private static final int WIDTH=400;
    private static final int HEIGHT=300;

    //JFrame Components
    private JLabel jlblMaxNumber;

    private JTextArea  jtaOutput;

    private JTextField jtfMaxNumber;

    private JButton jbtnCalculate, jbtnClear, jbtnExit;

    private CalculateButtonHandler calculateHandler;
    private ClearButtonHandler  clearHandler;
    private ExitButtonHandler   exitHandler;

    private JScrollPane scrollingResult;

    private JPanel jpnlTop = new JPanel();
    private JPanel jpnlCenter = new JPanel();
    private JPanel jpnlBottom = new JPanel();


    public PrimeNumbersJ()
    {
        // Set the title and Size:
        setTitle("Prime Numbers with JFrame");
        setSize(WIDTH, HEIGHT);
        jpnlBottom.setLayout(new GridLayout(1, 3));

        // Instantiate the JLabel components:
        jlblMaxNumber = new JLabel("Enter the Largest Number to test: ", SwingConstants.LEFT);

        // Instantiate the JTextFields:
        jtfMaxNumber = new JTextField(10);

        // Make the JTextArea scrollable:
        jtaOutput = new JTextArea(10,1);
        scrollingResult = new JScrollPane(jtaOutput);

        // Instantiate and register the Calculate button for clicks events:
        jbtnCalculate = new JButton("Calculate");
        calculateHandler = new CalculateButtonHandler();
        jbtnCalculate.addActionListener(calculateHandler);

        // Instantiate and register the Clear button for clicks events:
        jbtnClear = new JButton("Clear");
        clearHandler = new ClearButtonHandler();
        jbtnClear.addActionListener(clearHandler);

        // Instantiate and register the Exit button for clicks events:
        jbtnExit = new JButton("Exit");
        exitHandler = new ExitButtonHandler();
        jbtnExit.addActionListener(exitHandler);

        // Assemble the JPanels:
        jpnlTop.setLayout(new GridLayout(1, 2));
        jpnlTop.add(jlblMaxNumber);
        jpnlTop.add(jtfMaxNumber);

        jpnlCenter.setLayout(new GridLayout(1, 1));
        jpnlCenter.add(scrollingResult);

        jpnlBottom.setLayout(new GridLayout(1, 3));
        jpnlBottom.add(jbtnCalculate);
        jpnlBottom.add(jbtnClear);
        jpnlBottom.add(jbtnExit);

        // Start to add the components to the JFrame:
        Container pane = getContentPane();
        pane.setLayout(new BorderLayout());

        pane.add(jpnlTop, BorderLayout.NORTH);
        pane.add(jpnlCenter, BorderLayout.CENTER);
        pane.add(jpnlBottom, BorderLayout.SOUTH);


        // Show the JFrame and set code to respond to the user clicking on the X:
        setVisible(true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);

        jpnlTop.setLayout(new GridLayout(1, 3));
        jpnlTop.add(jlblMaxNumber);
        jpnlTop.add(jtfMaxNumber);

        jpnlCenter.setLayout(new GridLayout(1, 1));
        jpnlCenter.add(scrollingResult);

        jpnlBottom.add(jbtnCalculate);
        jpnlBottom.add(jbtnClear);
        jpnlBottom.add(jbtnExit);

        // Show the JFrame and set code to respond to the user clicking on the X:
        setVisible(true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }//End Constructor


    private class CalculateButtonHandler implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {
            int iRemainder,iPrimeCheck;
            int iNumbertoTest = 0;
            boolean bValidInput = true;
            String sPrime ="";

            try
            {
                iNumbertoTest = Integer.parseInteger(jtfMaxNumber.getText());
        }
            catch (Exception aeRef)
            {
                JOptionPane.showMessageDialog(null,"Enter the Max Number to Test.", getTitle(), JOptionPane.WARNING_MESSAGE);
                bValidInput = false;
            }// end of catch


            if ( bValidInput )
            {

                for(iNumberToTest = 1;iNumberToTest <= 100;iNumberToTest++)    {
                    iRemainder = 0;
                    for(iPrimeCheck = 1;iPrimeCheck <= iNumberToTest;iPrimeCheck++){
                        if(iNumberToTest % iPrimeCheck == 0){
                                iRemainder++;
                            }
                        }
                        if(iRemainder == 2 || iNumberToTest == 1)
                        {
                                String sNumber = Integer.toString(iNumberToTest);
                                sPrime = sPrime + (sNumber + "\n");
                        }


            }
                // Populate the output by using the methods in the user defined class::

                jtaOutput.append("The Prime Numbers Are: \n" + sPrime  + "\n");
            } // end if
        } //end ActionPerformed
    }//End CalculateButtonHandler

    private class ExitButtonHandler implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {
            System.exit(0);
        }
    }//end ExitButtonHandler


    private class ClearButtonHandler implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {
            jtfMaxNumber.setText("");
            jtaOutput.setText("");
         }
    } // end ClearButtonHandler






    public static void main(String args[])
    {
        PrimeNumbersJ primNumJ = new PrimeNumbersJ();
    }
}

Error

java:120: cannot find symbol
symbol  : method parseInteger(java.lang.String)
location: class java.lang.Integer
            iMaxNumber = Integer.parseInteger(jtfMaxNumber.getText());
                                ^
  • 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-16T05:50:05+00:00Added an answer on June 16, 2026 at 5:50 am

    change Integer.parseInteger() to

    Integer.parseInt()
    

    also declare int iNumberToTest as class variable in CalculateButtonHandler class

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

Sidebar

Related Questions

Alright, I have this program to sparse code in Newick Format, which extracts both
Alright, I made a program which should work, but unfortunately doesn't. It loads a
Alright so I'm working on a program written in c++ that is running as
Alright so what I am trying to do is essentially create a program that,
Alright, I have a performancecounter in my program that calculates the CPU usage. It
Alright, so I'm trying to write a program for Android for a project for
Alright, so I'm writing this program that essentially batch runs other java programs for
Alright, I'm trying to set a program I have to receive data from a
Alright, Ill try to explain this as best as I can first... My program
Alright, I recently wrote a ajax push script which had php on the backend

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.