Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Can anyone help me finish creating a GUI for my program

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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-

    public class Numbs
    {
       public static void main( String[] args )
         {
           Numbers obj = new Numbers();
           obj.getNumbers();
         } 
    }
    SECOND CLASS-
    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.


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default 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)
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default 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 :-)

  4. #4
    Junior Member
    Join Date
    Mar 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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?


    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();
    }
       }

  5. #5
    Junior Member
    Join Date
    Mar 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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
    *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 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.
    *

    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
    }
    }}}

Similar Threads

  1. need help creating a maze program
    By helpzor in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 2nd, 2011, 03:12 PM
  2. Creating a java program to "Beat" Snake web app?
    By AkOndray in forum AWT / Java Swing
    Replies: 2
    Last Post: December 5th, 2010, 12:36 AM
  3. Creating program Blackjack - Dr.Java
    By TheUntameable in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 20th, 2010, 12:54 PM
  4. tax return program..help finish please!!
    By dscrudato21xo in forum Loops & Control Statements
    Replies: 2
    Last Post: November 5th, 2009, 03:23 PM
  5. Need help creating this program
    By ixjaybeexi in forum File I/O & Other I/O Streams
    Replies: 25
    Last Post: October 19th, 2009, 07:08 AM