Page 1 of 2 12 LastLast
Results 1 to 20 of 24
  1. #1
    Deyaneria is offline Member
    Join Date
    Mar 2016
    Location
    USA, Maine
    Posts
    14
    Rep Power
    0

    Post question about text boxes in GUI application.

    I'm new here so I wasn't sure where to post this. I'm working on a program for homework (just being honest) I have worked out most of the kinks in the project and kept it pretty simplistic. I'm just having an issue with a GUI textbox. Basically the application is for sales Reps...they put their information into the gui and the information gets saved to text file when they hit an enter button. Then they can choose to evaluate all the reps in this text file, by choosing the evaluate button which then runs a quick calculation to see which reps got over 8000 in sales. These reps are added to star text file. The star text file is then read and displayed in the text box when the show button is activated. I have done printlines to test if the data is being grabbed correctly from the file and it is ...I just can't get it to show up in that darn box. The text box was set that it couldn't be edited in the GUI as professors instructions. Using netbeans 8.1 with windows 10.
    Java Code:
     private void showStarsButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                
         
         //salesDataOutput.setText("Star Reps");
    
         //put this line in as a header and to test to ensure that the button press was working properly. This does show in the box. 
            
            DisplayStars reader = new DisplayStars();
            
            
       
            // instantiate a display stars object
            try {
              //  salesDataOutput.setText("why isn't this working?");
              
            // tried another setText function only one will show at a time. took away both of them to see if that was the issue for the "for" loop ....no dice          
    
                List<StarData> star = reader.readStar("StarData.txt");
    
                //list created from stardata class contains all getters and setter and toString for star reps
                for(StarData r : star )
                {
                    
                    salesDataOutput.append(r.toString());
                    salesDataOutput.append("\n");
                    //salesDataOutput.setText("I should be writing Star Reps here");
                    // added a set text line to see if the loop was working it doesn't show up even commenting out the other two setText lines 
                
                }
                
                
            } catch (IOException ex) {
                
                JOptionPane.showMessageDialog(this,"File cannot be opened.");
                Logger.getLogger(it252salesForm.class.getName()).log(Level.SEVERE, null, ex);
            }
         
            
        }

    Unfortunately the Prof takes usually around 36 hours to return an email...so in spite of asking him as well I turn to you guru's of Java who know much more than I do at this point.
    Last edited by DarrylBurke; 03-20-2016 at 08:29 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,007
    Rep Power
    34

    Default Re: question about text boxes in GUI application.

    can't get it to show up in that darn box.
    Is the code on line 23 executed? What value is returned by r.toString() when line 23 is executed?

    Is the component referenced by the variable: salesDataOutput shown in the GUI?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Deyaneria is offline Member
    Join Date
    Mar 2016
    Location
    USA, Maine
    Posts
    14
    Rep Power
    0

    Default Re: question about text boxes in GUI application.

    OK now that I have this option to reply instead of the "reply with quote" option (kept knocking me back to the login page). Here is what I've found: I tried running the debugger, to be honest I'm not well versed in it yet with netbeans as I was eclipse. However I'm not getting a value back on line 23, it just says successfully submitted. That is why I also attempted to put the set-text in there (line 25) only for testing purposes to see if the for loop seemed to be running. I commented it out after. That wasn't working either. The component shown for the salesDataOutput is a JTextArea and it does appear in the GUI in fact lines 3 and 13 will show up if they are uncommented.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,007
    Rep Power
    34

    Default Re: question about text boxes in GUI application.

    Is line 23 being executed? Add a print statement just before line 23 that prints the value of r.toString().
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Deyaneria is offline Member
    Join Date
    Mar 2016
    Location
    USA, Maine
    Posts
    14
    Rep Power
    0

    Default Re: question about text boxes in GUI application.

    no I don't believe it is I added the print line as suggested ....and it does not appear either ...just like the set text at line 25

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,007
    Rep Power
    34

    Default Re: question about text boxes in GUI application.

    That would mean the loop is not being executed and that would be because the List is empty. Check the code that returns the List to make sure the List has something in it.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Deyaneria is offline Member
    Join Date
    Mar 2016
    Location
    USA, Maine
    Posts
    14
    Rep Power
    0

    Default Re: question about text boxes in GUI application.

    ok I figured the loop was not being executed...I'm not sure why the list is not being populated....Perhaps a naming convention issue i'm not seeing. The point of the whole project was to learn how to build components separately and integrate them. I have a class that called DisplayStars that reads the correct text file and parses it and returns the String star line by line. I can printline that and it seems to be working properly. Basically with the button press of showStars it calls this class and should display the results in the textbox. Maybe i'm thinking about it too hard ( I have a tendency to do that:)

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,007
    Rep Power
    34

    Default Re: question about text boxes in GUI application.

    why the list is not being populated.
    Why is the List returned by the readStar method empty? Look at the code in that method to see what it is doing.
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    Deyaneria is offline Member
    Join Date
    Mar 2016
    Location
    USA, Maine
    Posts
    14
    Rep Power
    0

    Post Re: question about text boxes in GUI application.

    I'm not sure as I've tested that component and it is returning the list perfectly as shown by printline statements...thanks for the continued help as I am still working on this even as we speak...Here is the code for the Display stars class where the readStar method is...perhaps you may see something I missed.
    Java Code:
    package it252salesform;
    
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.StringTokenizer;
    
    /**
     *
     * @author Brandi
     */
    public class DisplayStars {
        
          
         public List<StarData> readStar(String filename) throws IOException {
            File f = new File(filename);
            FileReader reader = new FileReader(f);
            BufferedReader bReader = new BufferedReader(reader);
            // SalesData sd = new SalesData();
         
            List<StarData> star = new ArrayList<StarData>();
    
            String line = bReader.readLine();
            while (line != null) {
                StarData x;
                x = null;
                try {
    
                    //  SalesDAta = parseLine(line);
                    x = parseLine(line);
                } catch (Exception e) {
                    e.printStackTrace();
                }
    
                if (x == null) {
                    System.out.println("this line is bad." + line);
                } else {
                    
                   
                    
                    System.out.println(star);
    
                }
                line = bReader.readLine();
            }
           return star;
    
        }
    
        private  StarData parseLine(String line) throws IOException {
            String repId;
            String first;
            String last;
    
            double suppliesTot;
    
            double booksTot;
    
            double paperTot;
            String district;
            String contact;
            // setting variables for tokens
    
            StringTokenizer st = new StringTokenizer(line, ",");
            repId = st.nextToken().trim();
            first = st.nextToken().trim();
            last = st.nextToken().trim();
           
            suppliesTot = Double.parseDouble(st.nextToken().trim());
    
            booksTot = Double.parseDouble(st.nextToken().trim());
    
            paperTot = Double.parseDouble(st.nextToken().trim());
            district = st.nextToken();
            contact = st.nextToken();
    
            if (repId.length() == 0) {
                return null;
    
            } else if (first.length() == 0) {
                return null;
            } else if (last.length() == 0) {
                return null;
            } else if (suppliesTot < 1) {
                suppliesTot = 0;
            } else if (booksTot < 1) {
                booksTot = 0;
            } else if (paperTot < 1) {
                paperTot = 0;
    
            } else if (district.length() == 0) {
                return null;
            } else if (contact.length() == 0) {
                return null;
            }
            //verification for tokens
            
            
            
            StarData star = new StarData();
            star.setsRepID(repId);
          
            star.setsFirstName(first);
            //System.out.println(first);
            star.setsLastName(last);
           // System.out.println(last);
    
            star.setSbooks(booksTot);
            //System.out.println(booksTot);
    
            star.setsOffSupplies(suppliesTot);
            //System.out.println(suppliesTot);
    
            star.setSpaper(paperTot);
            //System.out.println(paperTot);
    
            star.setsDistrictChoice(district);
            star.setsContactMethod(contact);
            // setting the fields and checking to ensure they are correct
            System.out.println(" I am a" + star);
      
        
            
    
            return star;
    
        }
        
    }
    Still haven't heard from Prof but I expected that he usually doesn't reply for 36 hours and unfortunately that would put me very close to my deadline for handing this in

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,007
    Rep Power
    34

    Default Re: question about text boxes in GUI application.

    it is returning the list perfectly
    Does perfectly mean the list is empty? I'd think the ArrayList returned by readStar should have something in it.
    I don't see where the readStar method adds anything to star.
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    Deyaneria is offline Member
    Join Date
    Mar 2016
    Location
    USA, Maine
    Posts
    14
    Rep Power
    0

    Default Re: question about text boxes in GUI application.

    ok i'm going to show you my output as I think that might be more enlightening.....

    SalesData
    RepId1234, First Name: Brandi, Last Name: Schoch, Books sold: 3000.0, Supplies sold: 5000.0, Paper Sold: 200.0, District: NORTH, Contact Method: Email}
    This is the total:8200.0
    SalesData
    RepId1009, First Name: Kenneth, Last Name: Smith, Books sold: 1000.0, Supplies sold: 500.0, Paper Sold: 2000.0, District: EAST, Contact Method: Phone}
    SalesData
    RepId1012, First Name: Dwayne, Last Name: Apple, Books sold: 1000.0, Supplies sold: 5000.0, Paper Sold: 5400.0, District: NORTH, Contact Method: Email}
    This is the total:11400.0
    SalesData
    RepId1024, First Name: Matt, Last Name: Damon, Books sold: 2000.0, Supplies sold: 500.0, Paper Sold: 4500.0, District: EAST, Contact Method: Phone}
    SalesData
    RepId1030, First Name: Jan, Last Name: Baker, Books sold: 822.0, Supplies sold: 5000.0, Paper Sold: 900.0, District: EAST, Contact Method: Phone}
    //data above here is tested from original salesdata class....this file is separate from the one I am having issues with



    this line is the new arraylist[]

    I put this line before actually parsing the data and creating the arraylist so I would expect an empty arraylist


    I am aRepId1234, First Name: Brandi, Last Name: Schoch, Books sold: 5000.0, Supplies sold: 3000.0, Paper Sold: 200.0, District: NORTH, Contact Method: Email}
    //this is correct println test of the parseline method in the DisplayStars class shown above so I know it is parsing the line and setting it to star....

    []
    ///empty array out from list<stardata> readstar method, in if-else statement.... not sure why i'm getting an empty array there it's almost like even though readstar calls parseline the data isn't being pulled back in.....

    I am aRepId1012, First Name: Dwayne, Last Name: Apple, Books sold: 5000.0, Supplies sold: 1000.0, Paper Sold: 5400.0, District: NORTH, Contact Method: Email}
    //this is correct println test of the parseline method in the DisplayStars class shown above so I know it is parsing the line and setting it to star.... 2nd line in file...

    []
    ///empty array out from list<stardata> readstar method, in if-else statement same as last empty array statement as two files fit the star criteria

    IN TRY CATCH SHOWSTARs BUTTON
    //tested to ensure the try catch was working and the program didn't stop before it ....in the gui button handler....

    This is the star[]

    This is the star[]

    the two files are printlined as empty arrays within the button handler.....



    I hope this somewhat makes sense as i'm starting to feel like i'm chasing my tail at this point :)

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,007
    Rep Power
    34

    Default Re: question about text boxes in GUI application.

    Where is anything put in the star list in the readStar method? If nothing is put in the list it will be empty. That is what was discussed in posts #6 and #8.

    The code in readStar should be changed so that items are added to the list in the readStar method so that the list that is returned will not be empty.
    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    Deyaneria is offline Member
    Join Date
    Mar 2016
    Location
    USA, Maine
    Posts
    14
    Rep Power
    0

    Default Re: question about text boxes in GUI application.

    ok so sounds like something basic i'm missing here readStar sets up the file reader and the buffered reader and instantiates the arraylist called star...and a while loop is implemented to ensure the text file writes the lines that are not null. Within that loop the parseline method is called. the parseline then validates the data and sets the token to the star array...ok as I was writing this.... It hit me .....helllooo aha moment ....I'm sorry if I'm coming off numb right now ...but to be honest I have never dealt with gui's in java , arraylists,reader or writers, or components ( although components make a lot of sense to me). WE covered this material in 5.5 weeks along with switching to netbeans and I had to learn how to write an SRS for my other class....so glad this semsester is almost done. Thank you so much ..i'm definitely closer to an finishing this project...

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,007
    Rep Power
    34

    Default Re: question about text boxes in GUI application.

    Is it working now?
    If you don't understand my response, don't ignore it, ask a question.

  15. #15
    Deyaneria is offline Member
    Join Date
    Mar 2016
    Location
    USA, Maine
    Posts
    14
    Rep Power
    0

    Default Re: question about text boxes in GUI application.

    I'm feeling really silly at this point but I can't seem to get the syntax right to put the fields from star into too the arraylist which I renamed starList as this was causing confusion...

    Java Code:
    StarData star = new Stardata();
    
    List<StarData> starList = new ArrayList<StarData>();
    I'm still missing something.....

  16. #16
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,007
    Rep Power
    34

    Default Re: question about text boxes in GUI application.

    Does the List named star in post#1 now have something in it? If so, the loop on line 20 in post#1 should get the list's contents item by item and put them in the text field with the append method.

    If the List is empty, then the code in the readStar method must be changed to add something to the list.
    If you don't understand my response, don't ignore it, ask a question.

  17. #17
    Deyaneria is offline Member
    Join Date
    Mar 2016
    Location
    USA, Maine
    Posts
    14
    Rep Power
    0

    Default Re: question about text boxes in GUI application.

    "Does the List named star in post#1 now have something in it?"

    No it does not that is the issue in a nutshell, the way I understood the parseline method called in the loop was suppose to set the list fields...well at least that was how I understood it...Makes me really wish the college would go back to 2 live chats a week.....one hour doesn't cut it....

  18. #18
    Deyaneria is offline Member
    Join Date
    Mar 2016
    Location
    USA, Maine
    Posts
    14
    Rep Power
    0

    Default Re: question about text boxes in GUI application.

    I think I understand what part of the problem is I got it.....

  19. #19
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,007
    Rep Power
    34

    Default Re: question about text boxes in GUI application.

    parseline method called in the loop was suppose to set the list fields.
    The parseLine method parses a line and creates a StarData object from the data in that line and returns the object. The code that called parseLine now needs to save that object in the list that is to be returned.
    If you don't understand my response, don't ignore it, ask a question.

  20. #20
    Deyaneria is offline Member
    Join Date
    Mar 2016
    Location
    USA, Maine
    Posts
    14
    Rep Power
    0

    Default Re: question about text boxes in GUI application.

    i needed to add this line to the else statement in the readStar method....


    star.add(x);

Page 1 of 2 12 LastLast

Similar Threads

  1. using a for loop to control text boxes
    By gbonecapone in forum Advanced Java
    Replies: 4
    Last Post: 10-07-2013, 06:15 PM
  2. Java text boxes does not show
    By zAxOanL in forum New To Java
    Replies: 0
    Last Post: 03-25-2012, 05:08 AM
  3. Dialog boxes closing on EVERY application.
    By Rtme in forum AWT / Swing
    Replies: 1
    Last Post: 05-17-2011, 08:54 PM
  4. Get text from multiple text boxes/tables
    By greenhorn in forum New To Java
    Replies: 0
    Last Post: 03-08-2011, 04:32 PM
  5. Replies: 2
    Last Post: 01-23-2009, 05:09 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
  •