# Can anyone help me finish creating a GUI for my program

• March 27th, 2011, 07:24 PM
danbendlin
Can anyone help me finish creating a GUI for my program
Hi, I am doing a program for class, heres what it asks to give you a background information- 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. - here is what I have so far,
FIRST CLASS-

Code Java:

```public class Numbs { public static void main( String[] args ) { Numbers obj = new Numbers(); obj.getNumbers(); } }```
SECOND CLASS-
Code Java:

```public class Numbers { public void getNumbers() { Scanner input = new Scanner(System.in); int[] array = new int[5];   int count = 0; int entered = 0; int num = 0;   while (entered < array.length) { System.out.println("Enter numbers: "); num = input.nextInt();   if ((num >= 10) && (num <= 100)) { boolean containsNumber = false; entered++;   for (int i = 0; i < array.length; i++) { if (array[i] == num)   containsNumber = true; }   if (!containsNumber) { array[count] = num;   count++; }   else   System.out.printf(" has already been entered\n", num);   }   else System.out.println("numbers must range between 10 and 100");     for (int i =0; i< entered; i++) {   System.out.print(array[i] + " "); }   System.out.println(); } } public void createGUI() { setDefaultCloseOperation(EXIT_ON_CLOSE); Container window = getContentPane(); window.setLayout(new BorderLayout());   controlPanel = new JPanel(); controlPanel.setLayout(new FlowLayout(FlowLayout.LEFT));   textArea = new JTextArea(); textArea.setBackground(Color.white);   }   public static void main(String args[]) { UserInterface myApplication = new UserInterface(); } }```
-Now the problem I am having is creating the GUI, everything works except for that and here it is saying cannont find symbol (EXIT_ON_CLOSE) and other than that I believe my GUI class is not finished, any help would be appreciated.
• March 28th, 2011, 10:39 AM
JavaPF
Re: Can anyone help me finish creating a GUI for my program
Is this all of your code? There are quite a few errors.. For starters, you haven't imported anything.

You need to do some more reading on creating a GUI - Lesson: Using Swing Components (The Java™ Tutorials > Creating a GUI With JFC/Swing)
• March 29th, 2011, 08:50 AM
Mr.777
Re: Can anyone help me finish creating a GUI for my program
Atleast start creating the GUI in a way so that we could help you finishing your GUI :-)
• March 16th, 2012, 08:27 PM
rickster31
Re: Can anyone help me finish creating a GUI for my program
this is my GUI for no duplication of one dimensional array ( in JaVa)
i need you guys help and hint in order to complete the GUI
basically on the JLabel the 5 numbers will be entered by the user
JtextField will display the 5 numbers to the user and after hitting enter it will also display 5
unique array numbers that is not the same as what the user entered.

Display the complete set
of unique values input after the user enters
each new value.
i Use a GUI with a text field to enter each value and a text area to display to numbers

how to display the unique values?

Code :

```import javax.swing.*; import java.awt.event.*; import java.awt.*;   public class GUI extends JFrame implements ActionListener{   private JPanel panel, bottomPanel; private JLabel lbl1, lbl2, lbl3, lbl4, lbl5; //display labels private JTextField numb1, numb2, numb3, numb4, numb5; //add digits private JButton btn1; //add final button private JTextArea txaResults; //display numbers   public GUI(){ super("Dimensional Arrays Five digits"); final int Width = 420, Height = 420; //window's size setSize(Width, Height); setLayout(new GridLayout(2,1)); buildPanel(); add(panel); add(bottomPanel); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); btn1.addActionListener(this); }   //build the structure label and textfield to add numbers. public void buildPanel(){ lbl1 = new JLabel("digit 1"); numb1 = new JTextField(); lbl2 = new JLabel("digit 2"); numb2 = new JTextField(); lbl3 = new JLabel ("digit 3"); numb3 = new JTextField(); lbl4 = new JLabel ("digit 4"); numb4 = new JTextField(); lbl5 = new JLabel ("digit 5"); numb5 = new JTextField();   btn1 = new JButton (" Enter "); panel = new JPanel(); bottomPanel = new JPanel();   // basically takes all the information and puts it into a grid format panel.setLayout(new GridLayout(6,2)); // sets up the rows and columns for the java table panel.add(lbl1); panel.add(numb1); panel.add(lbl2); panel.add(numb2); panel.add(lbl3); panel.add(numb3); panel.add(lbl4); panel.add(numb4); panel.add(lbl5); panel.add(numb5);     panel.add(btn1); bottomPanel.add(txaResults); }   public void actionPerformed(ActionEvent e){   // add it on DimArrays to initiate..   //DimensionalArrays dimensionalarrays = new DimensionalArrays(numb1.getNumber()); //add getText to end   //assign grades to student object //DimArraysGUI.calcAverage();   //display results //txaResults.append('\n' + DimensionalArrays.getNumber() + '\t' + '\t' + DimArraysGUI.getAverage()); // .\'n' returns the name and grade   //numb1.setNumber(""); //numb2.setNumber(""); //numb3.setNumber(""); //numb4.setNumber(""); //numb5.setNumber(""); //numb6.setNumber(""); }   public static void main(String args[]){ GUI array= new GUI(); array.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); array.setVisible(true); GUI myGUI = new GUI(); } }```
• March 16th, 2012, 08:34 PM
rickster31
Re: Can anyone help me finish creating a GUI for my program
my other program class is my one dimensional array

/** this is the main objective:

* One dimensional array to set up the amount of numbers and return the average.
* 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
*"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 text field to enter each
*value and a text area to display the unique values.

basically my code should be displaying a non duplicate array to the user
after he enters 5 numbers in a one dimensional array. the numbers each between 10 and 100 inclusively
i think i need a binary search or a search, then maybe 2 loops

* @author
* @version 03/8/2012
*/
/**
* One dimensional array to set up
* the amount of numbers and return the average.
*

Code :

```import javax.swing.*; import java.awt.event.*; import java.awt.*; import java.util.Scanner; //import   public class UniqueDimensionalArrays{ int [] array = new int [5]; // create 5 elements in a one dimensional array program   Scanner keyboard = new Scanner(System.in);   int inputNumber = 1; //to show the input digit from a person //create variables int arrayPosition = 0; // to add array position   { System.out.println(" Enter unique 5 digits ? 10 to max 100: "); //display message box asking a user to start to add numbers to the program { while (array[arrayPosition] == 0) { // start bracket   boolean insideArray = false; //digit to tell if input number is store in array   inputNumber = keyboard.nextInt(); //input found on keyboard for input numbers   if ((inputNumber > 9) && (inputNumber < 101)) // the numbers must be 10-100 so user will not go over the numbers {     for (int existCount = 0; (existCount < array.length); existCount++) //for loop for second time ti display unique digits   { //start the for loop test to see if digits exist if (array[existCount] == inputNumber) //array # equals input # {//start if loop insideArray = true; // digit from user exist on the array } //end if loop } // end for loop if input digits is in the array   //display message box for unique numbers System.out.println("The Unique digits are: "); if (insideArray == false) //if inside array number is not correct   { array[arrayPosition] = inputNumber; }       else { //start else loop System.out.println(" Incorrect Number, already contain that number "); }//end else loop     } else //orint error and goes to next input number { //start else System.out.println(" Not correct, choose numbers from 10 - 100 ? "); } //end else   //print all the numbers in an array //the for loop will print array elements on the screen System.out.println(" The Digits in the Array are : "); //print message to user before numbers shows up     for (arrayPosition = 0; arrayPosition < array.length; arrayPosition++) { System.out.print(array[arrayPosition] + " "); } System.out.println ("\n"); //print empty line } }}}```