Results 1 to 2 of 2
  1. #1
    Danbendlin is offline Member
    Join Date
    Mar 2011
    Rep Power

    Default Please help me finish off this program

    Hi, I am working on a program and can not seem to be able to finish it exactly. I am having problems at the end. Any help would be greatly appreciated.

    Java Code:
    import java.util.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
     * This class will allow you to insert 5 numbers.
     * @author Danny Bendlin
     * @version March 23, 2011
        public class Numbers extends JFrame
             private JTextField textField;
             private JTextArea textArea, displayArea, finalArea;
             private JPanel controlPanel, bottomPanel, southPanel, displayPanel, displayFinal;
             private JButton enter, finalNumbers;
             private String input; 
             private int intInput;
             private int[] array = new int[5];
             private int entered = 0;
        public static void main(){
            Numbers myFrame = new Numbers();
            myFrame.setTitle("Numbers between 10-100 by Daniel Bendlin");
        public void createGUI()
            Container window = getContentPane();
            window.setLayout(new BorderLayout());
            controlPanel = new JPanel();
            controlPanel.setLayout(new FlowLayout());
            bottomPanel = new JPanel();
            bottomPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
            southPanel = new JPanel();
            displayPanel = new JPanel();
            textArea = new JTextArea("Please enter 5 numbers between 10-100");
            displayArea = new JTextArea("");
            finalArea = new JTextArea("");
            textField = new JTextField(2);
            enter = new JButton("Enter");
            enter.addActionListener(new EnterNum());
            finalNumbers = new JButton("Display Final Numbers");
            finalNumbers.addActionListener(new DisplayNum());
        * Method that starts all the reels which implements the ActionListener
        * @param none
        * @return none
        private class EnterNum implements ActionListener
            public void actionPerformed(ActionEvent e)
                input = textField.getText();
                intInput = Integer.parseInt(input);
                while (entered < array.length){
                        if((intInput >= 10) && (intInput <= 100)){
                            for(int i = 0; i < array.length; i++){
                                array[i] = intInput;
                                entered = entered + 1;
                                displayArea.setText("Entered number(s)..." + array[i]);
                                displayArea.setText("Input numbers that range between 10 and 100");
                }catch (NumberFormatException x){displayArea.setText("\"" + textField.getText() + "\" is not a legal number.");
        private class DisplayNum implements ActionListener
            public void actionPerformed(ActionEvent e)
                //intInput = String.valueOf(array[]);
                //displayFinal.setText("\n" + intInput);
    -The problems come at the end with the 2 lines that have //. The first is say .class expect and the second line gives me the error cant find symbol, method setText(java.lang.string). When I compile without those lines it works but does not compute the other numbers, it does the first then stops.

    The assignment is the following- Use a one-dimensional array to solve the following problem: Write an application that inputs five numbers, each between 10 and 100, inclusive. As each number is read, display it only if it's not a duplicate of a number already read. Provide for the "worst case" in which all five numbers are different. Use the smallest possible array to solve this problem. Display the complete set of unique values input after the user enters each new value. Use a GUI with a textfield to enter each value and a text area to display the unique values.
    Thank you for your time.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    1) You don't convert a String to an int via String.valueOf(...) as this for doing the exact opposite -- converting an int (or other primitive) to a String. Consider using Integer.parseInt instead.

    2) displayFinal is a JPanel, so the compiler is correct to complain that you can't call setText(...) on it since this method doesn't exist for JPanel, nor should it. Perhaps you want to call this on a JLabel or JTextField variable instead?

Similar Threads

  1. Someone help me fix/finish this
    By Apertin in forum Java Applets
    Replies: 1
    Last Post: 10-15-2010, 03:28 PM
  2. help me to finish my project..
    By syedabu in forum NetBeans
    Replies: 1
    Last Post: 07-19-2010, 09:13 PM
  3. how to finish this?
    By xpandaxlover in forum New To Java
    Replies: 2
    Last Post: 04-09-2010, 07:43 PM
  4. how to finish this?
    By xpandaxlover in forum New To Java
    Replies: 1
    Last Post: 04-09-2010, 07:42 PM
  5. Next, Finish Buttons !!!
    By pele in forum SWT / JFace
    Replies: 1
    Last Post: 07-14-2007, 05:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts