Welcome to Dream.In.Code
Become a Java Expert!

Join 150,166 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,333 people online right now. Registration is fast and FREE... Join Now!




cant find symbol method getUserid()

 
Reply to this topicStart new topic

cant find symbol method getUserid(), login message box

sya_lea23
23 Aug, 2008 - 01:35 PM
Post #1

New D.I.C Head
*

Joined: 23 Aug, 2008
Posts: 4

hai...
crazy.gif crazy.gif
i cant really think right now..
i need ur help..
i want to create a login page that user must enter correct user id and password.
and i have to set my own user id and password.
after ok is clicked, the program will check whether the user id and password is correct or not.
Then i have to prompt a suitable message to tell user whether he/she
has entered valid or invalid user id and password.

so far, i've made this :

CODE


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Arrays;

public class PasswordDemo extends JPanel implements ActionListener {
    private static String OK = "ok";
    private static String CANCEL = "cancel";

    private JFrame controllingFrame; //needed for dialogs
    private JPasswordField passwordField;
    private JTextField useridField;

    public PasswordDemo(JFrame f) {
        //Use the default FlowLayout.
        controllingFrame = f;
      
        useridField = new JTextField(10);
        passwordField = new JPasswordField(10);
        useridField.setActionCommand(OK);
        passwordField.setActionCommand(OK);
        passwordField.addActionListener(this);
        useridField.addActionListener(this);

        JLabel label2 = new JLabel("User id:  ");
        label2.setLabelFor(useridField);
        
        JLabel label = new JLabel("Password: ");
        label.setLabelFor(passwordField);
        

        JComponent buttonPane = createButtonPanel();

        //Lay out everything.
        JPanel textPane = new JPanel(new FlowLayout(FlowLayout.TRAILING));
        textPane.add(label);
        textPane.add(label2);
        textPane.add(useridField);
        textPane.add(passwordField);
        

        add(textPane);
        add(buttonPane);
    }

    protected JComponent createButtonPanel() {
        JPanel p = new JPanel(new GridLayout(0,1));
        JButton okButton = new JButton("OK");
        JButton cancelButton = new JButton("CANCEL");

        okButton.setActionCommand(OK);
        okButton.addActionListener(this);
        cancelButton.setActionCommand(CANCEL);
        cancelButton.addActionListener(this);

        p.add(okButton);
        p.add(cancelButton);

        return p;
    }

    public void actionPerformed(ActionEvent e) {
        String cmd = e.getActionCommand();

        if (OK.equals(cmd)) { //Process the password.
            char[] input = useridField.[color=#FFFF66]getUserid[/color]() && passwordField.getPassword();
            
            if (isUseridCorrect(input) && isPasswordCorrect(input)){
                JOptionPane.showMessageDialog(controllingFrame,
                    "Success! You've typed the right user id.Please proceed to enter your password");
            } else {
                JOptionPane.showMessageDialog(controllingFrame,
                    "Invalid user id. Try again.",
                    "Error Message",
                    JOptionPane.ERROR_MESSAGE);
            }

            Arrays.fill(input, '0');

            useridField.selectAll();
            passwordField.selectAll();
            resetFocus();
        } else {      
        JOptionPane.showMessageDialog(controllingFrame,
                "Thank you");
        }
    }

      
    private static boolean isPasswordCorrect(char[] input) {
        boolean isCorrect = true;
        char[] correctPassword = { 'a', 'm', 'y', '2', '0', '1', '2' };
        

        if (input.length != correctPassword.length) {
            isCorrect = false;
        } else {
            isCorrect = Arrays.equals (input, correctPassword);
        }

        //Zero out the password.
        Arrays.fill(correctPassword,'0');

        return isCorrect;
    }


    private static boolean isUseridCorrect(char[] input) {
        boolean isCorrect = true;
        char[] correctUserid = { 'm', 'i', 'n', 't'};
        

        if (input.length != correctUserid.length) {
            isCorrect = false;
        } else {
            isCorrect = Arrays.equals (input, correctUserid);
        }

        //Zero out the user id
        Arrays.fill(correctUserid,'0');

        return isCorrect;
    }
    
    
    
    //Must be called from the event dispatch thread.
    protected void resetFocus() {
        useridField.requestFocusInWindow();
    }

    private static void createAndShowGUI() {

        JFrame frame = new JFrame("Login");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      
        final PasswordDemo newContentPane = new PasswordDemo(frame);
        newContentPane.setOpaque(true);
        frame.setContentPane(newContentPane);

        frame.addWindowListener(new WindowAdapter() {
            public void windowActivated(WindowEvent e) {
                newContentPane.resetFocus();
            }
        });

        
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
              
        UIManager.put("swing.boldMetal", Boolean.FALSE);
        createAndShowGUI();
            }
        });
    }
}




but then,
it says cannot find symbol method getUserid()

hmph...
i dont really know if im doing the right thing..
so..
pleaassseee guide me!!!
ph34r.gif ph34r.gif
User is offlineProfile CardPM
+Quote Post

nick2price
RE: Cant Find Symbol Method GetUserid()
23 Aug, 2008 - 02:04 PM
Post #2

D.I.C Regular
***

Joined: 23 Nov, 2007
Posts: 338



Thanked: 12 times
My Contributions
No where have you created a getUserid method, and i cant see any such method in the api, unless i have overlooked it. For a text field, you could however create a method

CODE
String getUsername() { //method to retrieve username
return useridField .getText();
}


This will return the input of the text entered into the textfield, then you can parse this into a char array, if you know the inputs going to be a character by checking for it.
User is offlineProfile CardPM
+Quote Post

sya_lea23
RE: Cant Find Symbol Method GetUserid()
23 Aug, 2008 - 10:49 PM
Post #3

New D.I.C Head
*

Joined: 23 Aug, 2008
Posts: 4

firstly,thank you very much!
(because you spend your time to guide me..)
really appreciate it!

im sorry...
as u can see, im a beginner..
and im not really understand what am i doing right now.
getting confused day by day.. crazy.gif
im really sorry i cant really understand what
are u trying to say to me..

can you please..
explain what am i trying to do based on the code
that i have created..
and what are my mistakes?

can u please edit my code so that there will be no
mistakes at all?
User is offlineProfile CardPM
+Quote Post

pbl
RE: Cant Find Symbol Method GetUserid()
24 Aug, 2008 - 05:20 AM
Post #4

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
QUOTE(sya_lea23 @ 23 Aug, 2008 - 11:49 PM) *

can you please..
explain what am i trying to do based on the code
that i have created..
and what are my mistakes?


What you are trying to do based on the code that YOU write ?

If you wrote it you must know what it is supposed to do.

You are sure YOU wrote it ?

User is offlineProfile CardPM
+Quote Post

sya_lea23
RE: Cant Find Symbol Method GetUserid()
24 Aug, 2008 - 08:25 AM
Post #5

New D.I.C Head
*

Joined: 23 Aug, 2008
Posts: 4

honestly,
i dont know how to do it
so i search it through internet.
ive got some examples
and i add some features that
is required for my assignment.

for ur information,
ive to explore this by myself so i am quite lost.
sorry if u think that i didnt work hard
but im totally trying my best to understand all of
the code.
still, i dont get it.
User is offlineProfile CardPM
+Quote Post

pbl
RE: Cant Find Symbol Method GetUserid()
24 Aug, 2008 - 03:30 PM
Post #6

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.
And this applies to the code YOU wrote
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 02:54AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month