Results 1 to 4 of 4

Thread: Login System

  1. #1
    Chaosje is offline Member
    Join Date
    May 2011
    Posts
    6
    Rep Power
    0

    Default [Solved]Login System

    Hey there, everyone thx for possibly helping me out :D
    wouldnt know what to do without this forum...

    let me start by explaining my current situation....
    im creating a programm that needs a log in system..
    ive come up with a solution that i thought would work, but Obviously it didnt work(why else would I post here...)
    i want to be able to check if the input in "gebruikersnaamInvoer"(username field) and wachtwoordInvoer(password field) is the same as a specific users name and password....

    what i came up with was this..

    Java Code:
    import javax.swing.*;
    
    /**
     *
     * @author Chaos
     */
    public class Login  extends JPanel{
    
        private JLabel Gebruikersnaam, Wachtwoord;
        private JTextField gebruikersnaamInvoer, wachtwoordInvoer;
    
        public Login() {
    
            Gebruikersnaam = new JLabel("Gebruikersnaam");
            add(Gebruikersnaam);
            gebruikersnaamInvoer = new JTextField(20);
             add(gebruikersnaamInvoer);
            Wachtwoord = new JLabel("Wachtwoord");
            add(Wachtwoord);
            wachtwoordInvoer = new JTextField(20);
            add(wachtwoordInvoer);
            
            
    
    
        }
        public void controleerInlogStatus()
       {
            boolean ingelogd = false;
           String naam = "robin";
            String wachtwoord = "admin";
    
          if(wachtwoord == wachtwoordInvoer && naam == gebruikersnaamInvoer)
          {
              ingelogd = true;
          }
       }
        
    }
    at first i tried to implement this code in the Main gui but the gui couldnt recognise the wachtwoordInvoer and gebruikersnaamInvoer(the input fields for username and password cause they were in the class "Login")
    after that i tried to put it directly in the "Login class" but ofcourse another problem showed up...
    incomparable types, java.lang.String and java.lang.Textfield
    i get what the error is saying, i cant compare those 2, but then how do i check? :$
    ive read about some key listeners and such, but is that what i need? or am I totally thinkin in the wrong direction?

    Thx in advance...

    Chaosje
    Last edited by Chaosje; 05-04-2011 at 11:45 PM.

  2. #2
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    382
    Rep Power
    3

    Default

    Unfortunately the Javadoc for JTextField didn't spell it right out, or I would've pointed you there (although it is at JTextField (Java Platform SE 6) in case you want to look anyway). Either way, you use the getText-function to get the text in a textfield. Also, you can't use == with Strings; use .equals instead (so if (text1.equals(text2)) ).

  3. #3
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    Maybe you should read up Swing Tutorial and the JTextField doc.
    Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)
    JTextField (Java 2 Platform SE v1.4.2)

    Looking at the JTextField doc, you can see that JTextField is a child of JTextComponent which has a getText() method to retrieve the text inside the text field.
    e.g.
    JTextField jt = new JTextField();
    String text = jt.getText();

  4. #4
    Chaosje is offline Member
    Join Date
    May 2011
    Posts
    6
    Rep Power
    0

    Default

    Thank you!

    *updated code* this should work then ?

    Java Code:
    if((wachtwoord.equals(wachtwoordInvoer))  && (naam.equals(gebruikersnaamInvoer) ))
    so now i just need to use gettext to actually get the text out of the textfield and put that in to make it work?

    this is actually how a login system could work? or is there a waaaay better way? (cant use any third party shit ) so i actually have to do it myself...

    *edit wow I had another response while typing XD * thx a LOT :D
    never knew all those documentation was available :D(god i feel like a sucker now XD )

    thx again :D

Similar Threads

  1. Database for Login system
    By Chris_X in forum JDBC
    Replies: 1
    Last Post: 11-27-2010, 01:14 AM
  2. Replies: 3
    Last Post: 02-07-2010, 08:34 PM
  3. Replies: 5
    Last Post: 08-16-2008, 04:33 PM
  4. Replies: 0
    Last Post: 06-25-2008, 12:41 PM
  5. Applet Login System Tutorial
    By Free-JavaTutorials in forum Java Applets
    Replies: 0
    Last Post: 03-15-2008, 02:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •