javascript - Comparing Values from a text file with value entered ,Using Java For Login purpose -


i trying make gui works login screen. code should compare value entered values in txt file. (two fields needed compared) values in text file given 2 columns separated space. code not comparing data properly.

login.txt file:

abcd xdfg kfhk ertf ffsf jfkf setg kgfb 

code part:

    import java.awt.container;     import java.awt.eventqueue;     import java.awt.event.actionevent;     import java.awt.event.actionlistener;     import java.io.bufferedreader;      import java.io.file;     import java.io.filenotfoundexception;     import java.io.filereader;     import java.util.arraylist;     import java.util.list;     import java.util.scanner;      import javax.swing.abstractbutton;     import javax.swing.jbutton;     import javax.swing.jframe;     import javax.swing.jlabel;     import javax.swing.joptionpane;     import javax.swing.jtextfield;     @suppresswarnings({ "serial", "unused" })  public class guilook extends jframe{     public jtextfield exmem;    public jtextfield clermem;    public jbutton bok;    private object egm;    private object cm;      public static void main(string[] args) {        eventqueue.invokelater(new runnable() {            public void run() {                try {                    guilook window = new guilook();                   window.setvisible(true);                } catch (exception e) {                    e.printstacktrace();                }            }        });    }        public guilook() {        initialize();       }       public void initialize() {       setdefaultcloseoperation(jframe.exit_on_close);       setlayout(null);       setsize(350,300);        clermem = new jtextfield();      clermem.setbounds(90, 114, 105, 22);      add(clermem);      clermem.setcolumns(20);       exmem = new jtextfield();      exmem.setbounds(90, 79, 105, 22);      add(exmem);      exmem.setcolumns(10);       jlabel lblexcmem = new jlabel("exmem");      lblexcmem.setbounds(220, 82, 76, 16);      add(lblexcmem);       jlabel lblclrmem = new jlabel("clrmem");      lblclrmem.setbounds(220, 117, 66, 16);      add(lblclrmem);       jbutton bok = new jbutton("ok");      bok.setbounds(144, 158, 97, 25);      bok.addactionlistener(new actionlistener() {       public void actionperformed(actionevent ae)          {              string info = readfile();             system.out.println(info);              string[] split = info.split(" ");              string egm=split[0];              string cm =split[1];              scanner s=null;                if(exmem.gettext().equals(egm) && clermem.gettext().equals(cm)){                  joptionpane.showmessagedialog(null,"requestsuccesfl");              }else{              joptionpane.showmessagedialog(null,"wrong exmem/clermem");              }               }});         add(bok);         }        private static  string readfile(){           string line=null;           string text="";           filereader filereader=null;           try{                filereader =new filereader(new file     ("/home/v3nky/downloads/eclipse_java/eurexgui/sample.txt"));                bufferedreader bf=new bufferedreader(filereader);               while((line=bf.readline()) !=null){                   text=text+line+'\n';                }               bf.close();            }catch(exception e){               e.printstacktrace();           }           return text;        }    } 

i recommend use arraylist lines of file , split them egm , cm values. this:

scanner s = new scanner(new file(//here path of file));  arraylist<string> list = new arraylist<string>();  while (s.hasnext()) {     list.add(s.nextline()); } 

now have lines of file, can split them both values, this:

for(int = 0; < list.size(); i++) {    string[] line  = list.get(i).split(" ");     egm = line[0];    cm = line[1];  } 

now can compare both values:

if (exmem.equals(egm)&& clermem.equals(cm)) {     joptionpane.showmessagedialog(null,"requestsuccesfl"); } else  {     joptionpane.showmessagedialog(null,"wrong exmem/clermem"); } 

finally, close scanner variable, this:

s.close(); 

i expect helpful you!


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -