Sebastian Laursen

Greenhorn
+ Follow
since Oct 18, 2014
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sebastian Laursen

Tony Docherty wrote:Please post your code remembering to UseCodeTags (← click)



Am I completely missing the logic here?
9 years ago
Okay so I got the login to work now by using this:


However, I don't think I use it as I am supposed to use it. And again, I want the display box to appear after the login.
9 years ago
Display box class:



The LoginSystem class:

9 years ago
Thank you very much for the answers, much appreciated!!.

It got me a little further, but I think my problem is that when I create the new object in the new class doing it like this:



Then, when I write log.validateUserPass(user,pass), I think I have to write the String names I have given(userName, password), but it says it cannot be resolved to a variable. Is that because it is an input and not an assigned value as such? Or is it because I need to make a local variable within the new class aswell?

Further I will only run the method display() if valiedateUserPass turns out true. Can this be done with a simple if statement or will you recommend any other option?

Not sure I have the logic correct here. Will it help to post the code or can you follow me so far?
9 years ago
Hi guys, as you may have guessed I'm quite new to Java. I have some trouble with understanding how to get two classes to get objects from each other (if that is the correct term).

Lets say I have a login class, in which I have a method checking what the user has entered into the console (I have not displayed the whole code, but this class works as it should and give the user an option to enter username and password and return it true if entered correct).

public static boolean validateUserPass(String userName, String password) {
String[] user = {"admin"};
String[] passwords = {"firkanten"};
boolean check = false;

for (int i = 0; i < user.length; i++) {
if (userName.equals(user[i])) {

if (password.equals(passwords[i])) {
check = true;

Now, in another class I want a display box to appear on the screen and give the user three options: Click yes, no or cancel. I get this to run perfectly alone, this is not the hard part for me. I want the display box only to appear when the correct username and password is given, but I can't seem to figure out how to do this probably.

Can anyone guide me in the right direction? If you can understand what I want, and if you don't please let me know what I can give of information to let you understand it better.
9 years ago