user interface - Writing to and reading from an ArrayList using java with NetBeans GUI -


what im trying code college project creating app using netbeans, adding information players in ryder cup. have text fields variables(team, name, dob, home, college, prof, years, matches, won, captain, pga, champion , intern) on gui, when gui save , read add in info players, ill delete text fields , save button.

what want whole page when user clicks radio button either team usa or team europe, info players in team appear. im thinking of using labels display each players info.

so stuck on save , read part. when add in info first player , save it, works. if add in players info, read first players info. not sure how save next array list , not on top of first array list object.

i hope have made clear trying do. appreciate help, thank you!

//my instantiable class code  package rydercup;  import java.io.serializable;  public class players implements serializable {      private string team;     private string name;     private string dob;//date of birth , age     private string home;//hometown     private string college;     private string prof;//turned professional      private string years;//years played     private string matches;//total matches     private string won;//total points won     private string captain;//team usa captain years      private string pga;//pga tour     private string champion;//champions tour victories     private string intern;//international victories      public players() {         team = new string();         name = new string();         dob = new string();         home = new string();         college = new string();         prof = new string();         years = new string();         matches = new string();         won = new string();         captain = new string();         pga = new string();         champion = new string();         intern = new string();     }      public void setteam(string team) {         this.team = team;     }      public void setname(string name) {         this.name = name;     }      public void setdob(string dob) {         this.dob = dob;     }      public void sethome(string home) {         this.home = home;     }      public void setcollege(string college) {         this.college = college;     }      public void setprof(string prof) {         this.prof = prof;     }      public void setyears(string years) {         this.years = years;     }      public void setmatches(string matches) {         this.matches = matches;     }      public void setwon(string won) {         this.won = won;     }      public void setcaptain(string captain) {         this.captain = captain;     }      public void setpga(string pga) {         this.pga = pga;     }      public void setchampion(string champion) {         this.champion = champion;     }      public void setintern(string intern) {         this.intern = intern;     }         public string getname() {         return name;     }      public string getdob() {         return dob;     }      public string getteam() {         return team;     }      public string gethome() {         return home;     }      public string getcollege() {         return college;     }      public string getprof() {         return prof;     }      public string getyears() {         return years;     }      public string getmatches() {         return matches;     }      public string getwon() {         return won;     }      public string getcaptain() {         return captain;     }      public string getpga() {         return pga;     }      public string getchampion() {         return champion;     }      public string getintern() {         return intern;     } }  //my gui code package rydercup;  import java.io.file;  import java.io.fileinputstream;  import java.io.fileoutputstream;  import java.io.ioexception;  import java.io.objectinputstream;  import java.io.objectoutputstream;  import java.util.arraylist;  import javax.swing.joptionpane;   public class ryderplayer extends javax.swing.jframe {      //variables     private arraylist <players> usalist;     private string team, name, dob, home, college, prof, years, matches, won;     private string captain, pga, champion, intern;     private int count;      public ryderplayer() {         initcomponents();         usalist = new arraylist <> ();         team = new string();         name = new string();         dob = new string();         home = new string();         college = new string();         prof = new string();         years = new string();         matches = new string();         won = new string();         captain = new string();         pga = new string();         champion = new string();         intern = new string();         //initialise count 0         count = 0;     }       //generate code ....         private void savebtnactionperformed(java.awt.event.actionevent evt) {                                                  file outfile;         fileoutputstream fstream;         objectoutputstream ostream;          try{             outfile = new file("usa.data");             fstream = new fileoutputstream(outfile);             ostream = new objectoutputstream(fstream);              ostream.writeobject(usalist);              joptionpane.showmessagedialog(null,"file written successfully");              ostream.close();         }         catch(ioexception e){             system.out.println(e);         }     }                                                private void readbtnactionperformed(java.awt.event.actionevent evt) {                                                  file infile;         fileinputstream fstream;         objectinputstream ostream;          try{             infile = new file("usa.data");             fstream = new fileinputstream(infile);             ostream = new objectinputstream(fstream);              arraylist <players> xlist;             xlist = (arraylist<players>)ostream.readobject();             for(players x:xlist){             joptionpane.showmessagedialog(null, "team: "+x.getteam()   +                                                   "\n name: "+x.getname()  +                                                   "\n date of birth: "+x.getdob()  +                                                   "\n home: "+x.gethome()  +                                                   "\n college: "+x.getcollege()  +                                                   "\n turned professional:"+x.getprof()  +                                                    "\n years played: "+x.getyears()  +                                                   "\n total matches: "+x.getmatches()  +                                                   "\n total points won: "+x.getwon()  +                                                   "\n usa captain years: "+x.getcaptain()  +                                                    "\n pga tour: "+x.getpga()  +                                                   "\n champion tour: "+x.getchampion()  +                                                   "\n international: "+x.getintern());             }              ostream.close();         }         catch(ioexception e){             system.out.println(e);         }         catch(classnotfoundexception ex){             system.out.println(ex);         }      }       //generate code ....  } 


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -