As the forum states "inheritance", I thought this might fit here. Anyways I've looked around quite a bit on importing Strings from another class and what ever I find hasn't seemed to work.
I want to be able to grab the username/password data from the text file, save it to a String, and import it to the login class for user input verification. Now I know it's not safe to make a login this way, but it's simply a theory test.
In "Login" the situation is where case String(a,c): /case String(b,d): are. I would like to be able to call these strings from class playerbase.
If I'm doing this in a completely ridiculous way, please notify me and give me suggestions on how to improve.
Main
package test.theory; public class Main{ public static void main(String[] args){ Login loginObject = new Login(); loginObject.login(args); } }
Login
package test.theory; import test.theory.playerbase.*; import javax.swing.JOptionPane; public class Login{ public void login(String[] args){ System.out.println("Heroes of Iskast V0.0.1"); String a = JOptionPane.showInputDialog("Enter your username","Username"); switch (a){ case String(a,c): System.out.println("Username accepted."); //This line, the 'a' and 'c' aren't being referenced from playerbase.java, same with line 17 String b = JOptionPane.showInputDialog("Enter your password","Password"); switch (b){ case String(b,d): JOptionPane.showMessageDialog(null,"You have successfully logged in, congradulations.", "Login",JOptionPane.PLAIN_MESSAGE); return; default: JOptionPane.showMessageDialog(null,"You entered the wrong password, please try again.", "Login",JOptionPane.PLAIN_MESSAGE); Main.main(args); } default: JOptionPane.showMessageDialog(null,"You entered the wrong username, please try again.", "Login",JOptionPane.PLAIN_MESSAGE); Main.main(args); } /* add an entry-per-second limiter */ } }
playerbase
package test.theory; import java.io.*; import java.util.*; public class playerbase { public Scanner x; public void openFile(){ try{ x = new Scanner(new File("playerbase.txt")); } catch(Exception e){ System.out.println("error found...somewhere"); } } public void readFile(){ while(x.hasNext()){ String a = x.next(); String b = x.next(); String c = x.next(); String d = x.next(); System.out.printf("%s%s%s%s\n", a,b,c,d); // Not quite to sure what this is going to do yet? Haven't been able to execute the code because of the String problem. } } public void closeFile(){ x.close(); } }
playerbase.txt:
OceansRythme accept Danaku1416 danaku