Results 1 to 10 of 10
Thread: Do all over again, how?
- 06-06-2012, 10:26 PM #1
Senior Member
- Join Date
- May 2012
- Posts
- 170
- Rep Power
- 2
- 06-06-2012, 10:45 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,619
- Rep Power
- 5
Re: Do all over again, how?
See Branching Statements (The Java™ Tutorials > Learning the Java Language > Language Basics), especially the last example on that page
- 06-06-2012, 11:05 PM #3
Senior Member
- Join Date
- May 2012
- Posts
- 170
- Rep Power
- 2
- 06-06-2012, 11:14 PM #4
Re: Do all over again, how?
The next to the last example at that link may be what you are looking for.
If you don't understand my response, don't ignore it, ask a question.
- 06-06-2012, 11:30 PM #5
Senior Member
- Join Date
- May 2012
- Posts
- 170
- Rep Power
- 2
- 06-06-2012, 11:34 PM #6
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,619
- Rep Power
- 5
- 06-06-2012, 11:40 PM #7
Senior Member
- Join Date
- May 2012
- Posts
- 170
- Rep Power
- 2
Re: Do all over again, how?
Ehh ok:
Java Code:public void run(){ try { try { lolag://<<<<<<<<< I want it to start from this point>>>>>>>>>>>>>>> INPUT = new Scanner(SOCK.getInputStream()); OUT = new PrintWriter(SOCK.getOutputStream()); Scanner checkUser = null; boolean gotusername = false; boolean gotpassword = false; boolean allowmenu = false; boolean gotinmenu = false; boolean continuep = true; boolean goteverything = false; String username = "NotFound"; String userpassword = "NotFound"; while(true) { CheckConnection(); if(!INPUT.hasNext()) { return;} if(goteverything == false) { username = INPUT.next(); userpassword = INPUT.next(); System.out.println("User's username: " + username +"\n" + "User's password: " + userpassword); goteverything = true; } username.replaceAll("\b", ""); userpassword.replaceAll("\b", ""); File userFile=new File(username+".ini"); //File userFile=new File("lionlev.ini"); System.out.println("looking for " + userFile); boolean exists = userFile.exists(); if(!exists){ OUT.println("wp" + EOF); OUT.flush(); goteverything = false; System.out.println("Invalid username."); break lolag;//<<<<<<<<<<<<I want it to restart from this point>>>>>> } else { try { checkUser = new Scanner(new File(username+".ini")); //checkUser = new Scanner(new File("lionlev.ini")); } catch (Exception e) {} checkUser.next(); String cpass = checkUser.next(); //System.out.println("Entered pass: " + userpassword); //System.out.println("REal pass: " + cpass); if(allowmenu == false){ if(userpassword.equals(cpass)){ System.out.println("Login is alright, sending "+username+ " to the menu.."); OUT.println("ok1" + EOF); OUT.flush(); allowmenu = true; } else{ OUT.println("wp" + EOF); OUT.flush(); System.out.println("WARNING: Wrong password"); goteverything = false; break lolag;//<<<<<<<<<<<<<<<<<<<<<I want it to restart from this point } } else { System.out.println("allowmenu is true"); goteverything = false; } } if(goteverything == true){ String menu1 = INPUT.next(); while (gotinmenu == false){ if(menu1.indexOf("menu") > -1){ System.out.println("User "+username+ " is in the menu."); gotinmenu = true; } } } /*for(int i = 0; i<Connector.ConnectionArray.size(); i++) { //Socket TEMP_SOCK = (Socket) Connector.ConnectionArray.get(i); //PrintWriter TEMP_OUT = new PrintWriter(TEMP_SOCK.getOutputStream()); //TEMP_OUT.println("Someone: " + MESSAGE + EOF); //TEMP_OUT.flush(); // System.out.println("Sent to: " + TEMP_SOCK.getLocalAddress().getHostName()); }*/ } }
- 06-06-2012, 11:46 PM #8
Senior Member
- Join Date
- May 2012
- Posts
- 170
- Rep Power
- 2
Re: Do all over again, how?
Simply, it checks if user exists in the file and if the password is right. if not then it restart almost everything
- 06-06-2012, 11:49 PM #9
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,619
- Rep Power
- 5
Re: Do all over again, how?
For future reference, that is not an SSCCE. Don't expect unpaid volunteers to wade through your code. In this case you are in luck it is just a syntax error: the label has to identify the loop
Note the location of the label - before the loop, not before the variables that are before the loop.Java Code:MYLABEL: while(true) { if ( somecondition ){ break MYLABEL; } }
- 06-06-2012, 11:52 PM #10
Senior Member
- Join Date
- May 2012
- Posts
- 170
- Rep Power
- 2


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks