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.
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.setSize(600,600);
myFrame.setTitle("Numbers between 10-100 by Daniel Bendlin");
myFrame.createGUI();
myFrame.pack();
myFrame.setVisible(true);
}
public void createGUI()
{
setDefaultCloseOperation(EXIT_ON_CLOSE);
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");
textArea.setBackground(Color.white);
displayArea = new JTextArea("");
finalArea = new JTextArea("");
textField = new JTextField(2);
textField.setBackground(Color.white);
enter = new JButton("Enter");
enter.setBackground(Color.GREEN);
enter.addActionListener(new EnterNum());
finalNumbers = new JButton("Display Final Numbers");
finalNumbers.addActionListener(new DisplayNum());
controlPanel.add(textArea);
southPanel.add(textField);
southPanel.add(enter);
displayPanel.add(displayArea);
displayPanel.add(finalNumbers);
displayPanel.add(finalArea);
window.add(controlPanel,BorderLayout.NORTH);
window.add(southPanel,BorderLayout.CENTER);
window.add(displayPanel,BorderLayout.SOUTH);
textField.requestFocusInWindow();
}
/**
* 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){
try{
if((intInput >= 10) && (intInput <= 100)){
for(int i = 0; i < array.length; i++){
array[i] = intInput;
entered = entered + 1;
textField.setText("");
displayArea.setText("Entered number(s)..." + array[i]);
}
}else{
displayArea.setText("Input numbers that range between 10 and 100");
}
}catch (NumberFormatException x){displayArea.setText("\"" + textField.getText() + "\" is not a legal number.");
textField.selectAll();
textField.requestFocus();
}
}
}
}
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.