java - How to find a certain criteria from various text fields and display a match off from a text file? -


i supposed make inventory program gui. code can far open file. however, need make displays files match criteria. main problem text file sorted in weird way necessary decode.

so if put: bmw in make field, 21123 serial number, muffler name, 119.99 price, , 0 stock. should first 5 lines in text area.

how find criteria various text fields , display match off text file?

bmw muffler 21123 119.99 0 chevy muffler 20911 52.99 2 ford muffler 26854 129.59 2 honda muffler 23319 159.99 2 toyota muffler 27813 199.29 1 bmw catalytic converter 900122 132.33 2 chevy catalytic converter 902391 69.59 1 ford catalytic converter 905778 61.23 4 

code

package lib;  import java.io.bufferedreader; import java.io.file; import java.io.filenotfoundexception; import java.io.filereader; import java.io.ioexception;  public class show extends javax.swing.jframe {  /**  * creates new form show  */ public show() {     initcomponents(); }  /**  * method called within constructor initialize form.  * warning: not modify code. content of method  * regenerated form editor.  */ @suppresswarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="generated code">                           private void initcomponents() {      filename = new javax.swing.jtextfield();     name = new javax.swing.jtextfield();     serialnumber = new javax.swing.jtextfield();     price = new javax.swing.jtextfield();     onhand = new javax.swing.jtextfield();     make = new javax.swing.jtextfield();     jscrollpane1 = new javax.swing.jscrollpane();     display = new javax.swing.jtextarea();     open = new javax.swing.jbutton();     save = new javax.swing.jbutton();     find = new javax.swing.jbutton();     clear = new javax.swing.jbutton();     filelabel = new javax.swing.jlabel();     namelabel = new javax.swing.jlabel();     serialnumberlabel = new javax.swing.jlabel();     pricelabel = new javax.swing.jlabel();     instocklabel = new javax.swing.jlabel();     makelabel = new javax.swing.jlabel();     update = new javax.swing.jbutton();      setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close);      filename.addactionlistener(new java.awt.event.actionlistener() {         public void actionperformed(java.awt.event.actionevent evt) {             filenameactionperformed(evt);         }     });      name.addactionlistener(new java.awt.event.actionlistener() {         public void actionperformed(java.awt.event.actionevent evt) {             nameactionperformed(evt);         }     });      serialnumber.addactionlistener(new java.awt.event.actionlistener() {         public void actionperformed(java.awt.event.actionevent evt) {             serialnumberactionperformed(evt);         }     });      display.setcolumns(20);     display.setrows(5);     jscrollpane1.setviewportview(display);     display.seteditable(false);      open.settext("open");     open.addactionlistener(new java.awt.event.actionlistener() {         public void actionperformed(java.awt.event.actionevent evt) {             openactionperformed(evt);         }     });      save.settext("save");      find.settext("find");     find.addactionlistener(new java.awt.event.actionlistener() {         public void actionperformed(java.awt.event.actionevent evt) {             findactionperformed(evt);         }     });      clear.settext("clear");     clear.addactionlistener(new java.awt.event.actionlistener() {         public void actionperformed(java.awt.event.actionevent evt) {             clearactionperformed(evt);         }     });      filelabel.settext("file name");      namelabel.settext("name");      serialnumberlabel.settext("serial number");      pricelabel.settext("price");      instocklabel.settext("in stock:");      makelabel.settext("make");      update.settext("update");      javax.swing.grouplayout layout = new javax.swing.grouplayout(getcontentpane());     getcontentpane().setlayout(layout);     layout.sethorizontalgroup(         layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)         .addgroup(layout.createsequentialgroup()             .addcontainergap()             .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)                 .addgroup(layout.createsequentialgroup()                     .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.trailing)                         .addgroup(javax.swing.grouplayout.alignment.leading, layout.createsequentialgroup()                             .addcomponent(filelabel)                             .addgap(18, 18, 18)                             .addcomponent(filename, javax.swing.grouplayout.default_size, 102, short.max_value))                         .addgroup(javax.swing.grouplayout.alignment.leading, layout.createsequentialgroup()                             .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)                                 .addcomponent(namelabel)                                 .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)                                     .addcomponent(serialnumberlabel, javax.swing.grouplayout.alignment.trailing)                                     .addcomponent(pricelabel))                                 .addcomponent(instocklabel)                                 .addcomponent(makelabel))                             .addgap(18, 18, 18)                             .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)                                 .addcomponent(serialnumber, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size)                                 .addcomponent(name)                                 .addcomponent(price, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size)                                 .addcomponent(onhand, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size)                                 .addcomponent(make, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size))))                     .addgap(18, 18, short.max_value)                     .addcomponent(jscrollpane1, javax.swing.grouplayout.preferred_size, 227, javax.swing.grouplayout.preferred_size))                 .addgroup(layout.createsequentialgroup()                     .addcomponent(open)                     .addgap(18, 18, 18)                     .addcomponent(save)                     .addgap(18, 18, 18)                     .addcomponent(find)                     .addgap(18, 18, 18)                     .addcomponent(clear)                     .addpreferredgap(javax.swing.layoutstyle.componentplacement.unrelated)                     .addcomponent(update)                     .addgap(0, 0, short.max_value)))             .addcontainergap())     );      layout.linksize(javax.swing.swingconstants.horizontal, new java.awt.component[] {filename, make, name, onhand, price, serialnumber});      layout.setverticalgroup(         layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)         .addgroup(layout.createsequentialgroup()             .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)                 .addgroup(layout.createsequentialgroup()                     .addgap(34, 34, 34)                     .addcomponent(jscrollpane1, javax.swing.grouplayout.preferred_size, 144, javax.swing.grouplayout.preferred_size))                 .addgroup(layout.createsequentialgroup()                     .addgap(27, 27, 27)                     .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.trailing)                         .addgroup(layout.createsequentialgroup()                             .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline)                                 .addcomponent(filelabel)                                 .addcomponent(filename, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size))                             .addpreferredgap(javax.swing.layoutstyle.componentplacement.unrelated)                             .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline)                                 .addcomponent(name, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size)                                 .addcomponent(namelabel))                             .addpreferredgap(javax.swing.layoutstyle.componentplacement.related)                             .addcomponent(serialnumber, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size))                         .addcomponent(serialnumberlabel))                     .addpreferredgap(javax.swing.layoutstyle.componentplacement.related)                     .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline)                         .addcomponent(price, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size)                         .addcomponent(pricelabel))                     .addpreferredgap(javax.swing.layoutstyle.componentplacement.related)                     .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline)                         .addcomponent(onhand, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size)                         .addcomponent(instocklabel))                     .addpreferredgap(javax.swing.layoutstyle.componentplacement.related)                     .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline)                         .addcomponent(make, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size)                         .addcomponent(makelabel))))             .addgap(38, 38, 38)             .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline)                 .addcomponent(open)                 .addcomponent(save)                 .addcomponent(find)                 .addcomponent(clear)                 .addcomponent(update))             .addcontainergap(57, short.max_value))     );      pack(); }// </editor-fold>                          private void filenameactionperformed(java.awt.event.actionevent evt) {                                              // todo add handling code here: }                                          private void nameactionperformed(java.awt.event.actionevent evt) {                                          // todo add handling code here: }                                      private void serialnumberactionperformed(java.awt.event.actionevent evt) {                                                  // todo add handling code here: }                                              private void clearactionperformed(java.awt.event.actionevent evt) {                                           // todo add handling code here:     filename.settext("");     name.settext("");     serialnumber.settext("");     price.settext("");     onhand.settext("");     make.settext("");     display.settext(""); }                                       private void openactionperformed(java.awt.event.actionevent evt) {                                          try {         file file = new file(filename.gettext());         filereader filereader = new filereader(file);         bufferedreader bufferedreader = new bufferedreader(filereader);         stringbuffer stringbuffer = new stringbuffer();         string line;                     int i=0;                      while ((line = bufferedreader.readline()) != null) {                              stringbuffer.append(line+" ");                             if(i==4){                                 stringbuffer.append("\n");                                 =-1;                             }                             i++;                      }         filereader.close();         display.settext(display.gettext() + stringbuffer.tostring());     } catch (ioexception e) {                 display.settext("error 101: file not found! ");     }  }                                      private void findactionperformed(java.awt.event.actionevent evt) {                                          // todo add handling code here:  }                                      /**  * @param args command line arguments  */ public static void main(string args[]) {     /* set nimbus , feel */     //<editor-fold defaultstate="collapsed" desc=" , feel setting code (optional) ">     /* if nimbus (introduced in java se 6) not available, stay default , feel.      * details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html       */     try {         (javax.swing.uimanager.lookandfeelinfo info : javax.swing.uimanager.getinstalledlookandfeels()) {             if ("nimbus".equals(info.getname())) {                 javax.swing.uimanager.setlookandfeel(info.getclassname());                 break;             }         }     } catch (classnotfoundexception ex) {         java.util.logging.logger.getlogger(show.class.getname()).log(java.util.logging.level.severe, null, ex);     } catch (instantiationexception ex) {         java.util.logging.logger.getlogger(show.class.getname()).log(java.util.logging.level.severe, null, ex);     } catch (illegalaccessexception ex) {         java.util.logging.logger.getlogger(show.class.getname()).log(java.util.logging.level.severe, null, ex);     } catch (javax.swing.unsupportedlookandfeelexception ex) {         java.util.logging.logger.getlogger(show.class.getname()).log(java.util.logging.level.severe, null, ex);     }     //</editor-fold>      /* create , display form */     java.awt.eventqueue.invokelater(new runnable() {         public void run() {             new show().setvisible(true);         }     }); }  // variables declaration - not modify                      private javax.swing.jbutton clear; private javax.swing.jlabel filelabel; private javax.swing.jtextfield filename; private javax.swing.jlabel instocklabel; private javax.swing.jlabel pricelabel; private javax.swing.jbutton update; private javax.swing.jtextarea display; private javax.swing.jbutton find; private javax.swing.jscrollpane jscrollpane1; private javax.swing.jtextfield make; private javax.swing.jlabel makelabel; private javax.swing.jtextfield name; private javax.swing.jlabel namelabel; private javax.swing.jtextfield onhand; private javax.swing.jbutton open; private javax.swing.jtextfield price; private javax.swing.jbutton save; private javax.swing.jtextfield serialnumber; private javax.swing.jlabel serialnumberlabel; // end of variables declaration                    } 

jtable , rowsorter should solution.

perhaps code useful too.

 public void search() {   string s = tf.gettext();   string content = textarea.gettext(); // instead file   int index = content.indexof(s, 0);   if (index >= 0) {       try {    int end = index + s.length();    //   }  } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -