java - inserting nothing in a .setText() method After loading textfile with FileReader -


i'm finishing java project school i'm stuck @ point.

the assignment make task-planner should able t save tasks u add/edit or delete , save information on textfile in directory on computer.

this way everytime in beginning when opening app, saved tasks-information gets loaded gui..

the problem i'm facing have insert information (when loading) in textfields in gui... not textfields should completed - in other words not obligatory -

that's why .settext() method have empty argument , code won't work...

i tried solving problem inserting " " (space) everytime detects empty argument - find solution ugly since applies when clicking on new gui-window new empty textfield there automatically space , user should press backspace before writing something....

is there better solution ?

here's code loads tasks...

import java.io.bufferedreader; import java.io.filereader; import java.io.ioexception;   public class readtask extends planner {      public static void read(){          string[] myarray = new string[8];         string line = "";          taskwindownew currenttask = null;          try          {             bufferedreader br = new bufferedreader(new filereader("plannertext.txt"));                        while (( line = br.readline()) !=null)              {                 myarray = line.split("\\|");                  for(int i=0;i<myarray.length;i++)                 {                     if( myarray[i].isempty())                     {                         myarray[i] = "yoooo";                     }                 }                  system.out.println(myarray.tostring());                  try{                     currenttask = new taskwindownew();                     currenttask.popupframe.setvisible(false);                      // important = if 1 or more field(s) left empty .doclick function not work                     // need find solution this.                     currenttask.titlefield.settext(myarray[1]);                     currenttask.minutefield.settext(myarray[2]);                     currenttask.hourfield.settext(myarray[3]);                     currenttask.daysmonthfield.settext(myarray[4]);                     currenttask.monthfield.settext(myarray[5]);                     currenttask.daysweekfield.settext(myarray[6]);                     currenttask.specialsymbolfield.settext(myarray[7]);                      //this emulates action of ok-button in new task window !                     currenttask.buttonok.doclick();                   } catch (arrayindexoutofboundsexception e)                  {                   }             }              br.close();           } catch (ioexception e) {             // todo auto-generated catch block             e.printstacktrace();         }          updatescrollpanel();       }  } 

what have done closely coupled file contents.meaning @ array index 1 there title field or @ index 3 hours field.but if user not enter value indexes change , may arrayindexoutofboundsexception in cases.

so when non-mandatory fields not entered user, cannot expect display them on ui next time.

what should rather store key value pairs in file.this enable check field value rather relying on array index.

i mean :

title:mr

hours:four

specialsymbol:#

then when pre-populate should each line, split key , value , if value not empty set in appropriate variable(which come know key) of taskwindownew.

hope helps.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -