Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 53
  1. #21
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: password/input masking in terminal

    Quote Originally Posted by PhHein View Post
    And three passwords for each user seems strange to me. And that E for the IOException reference is not coding standard.
    well i know it is a little strange but thats how I want it.

  2. #22
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: password/input masking in terminal

    Quote Originally Posted by Tolls View Post
    You need to sort out how you explain things.

    You talk about "run a method from another class", but don't actually say what method on what class.

    In that if statement there are no println() calls, so why you say they all work is beyond me. There are none there to actually work. So you have no idea at all if you are even entering this bit of code.
    You are eating an IOException, I notice, which is poor practice. You should at the very least do E.printStackTrace().

    And if you mean you expect the JOptionPane to appear then say so. It is not a "terminal".
    stacktrace is not allowed in the level of programs i am doing. it is basically for a school project, which is why i was stressing on simplicity. what i think is that you have misunderstood what i mean to say.I am providing you with my whole code.
    after the dialogue box appears, i want to call another method, which will be displayed in the terminal window of BlueJ, but that does not happen. please help me with that.
    Java Code:
    import javax.swing.*;//importing essential p[ackages
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    class Login   extends JFrame implements ActionListener//uses action listener method
    {
    
        public static int success_of_login = 0;
        JButton SUBMIT;//button for submitting data
        JPanel panel;
        JLabel label1,label2,label3;
        JTextField  text1,text2;
        public static void main()
        {
            try//try-catch method
            {
                Loginworker frame=new Loginworker();
                frame.setSize(700,150);
                frame.setLocation(400,400);
                frame.setVisible(true);//showing frame
            }
            catch(Exception e)//exception handler
            {
                System.out.println("JAVA EXEPTION TRIGGERED.PLEASE CHECK FOR YOUR FAULTS");
                System.out.println("FAULTS SUCH AS WRONG INPUTS, WRONG INPUT OR TYPE");
            }
        }
    
        void Loginworker()//initializer+constructor
        {
            label1 = new JLabel();
            label2 = new JLabel();
            label3 = new JLabel();
    
            label1.setText("Username:");
            text1 = new JTextField(15);
            text1.setBackground(Color.yellow); 
    
            label2.setText("Password:");//password field
            text2 = new JPasswordField(15);//from java.awt
            text2.setBackground(Color.red);
    
            SUBMIT=new JButton("login");
    
            panel=new JPanel(new GridLayout(3,1));
    
            panel.add(label1);
            panel.add(text1);
            panel.add(label2);
            panel.add(text2);
            panel.add(label3);
            panel.add(SUBMIT);
    
            add(panel,BorderLayout.CENTER);
            SUBMIT.addActionListener(this);
            setTitle("PLEASE LOGIN");//title bar
        }
    
        public void actionPerformed(ActionEvent ae)//using actionlistener
        {
            String username=text1.getText();
            String password=text2.getText();
            //checking inputs
            //and password
            //and username
            if (username.equals("pratik sanyal") ||username.equals("pratik") ||username.equals("pratik sir") && password.equals("9051232032")||password.equals("cta")|| password.equals("pp"))
            {
                try
                {
                    Main_menu.main_menu();
                }
                catch(IOException E) {}
                JOptionPane.showMessageDialog(this,"WELCOME PRATIK SIR!",
                    "SUCCESS!",JOptionPane.INFORMATION_MESSAGE);
                success_of_login = 1;
    
            }
            else if (username.equals("student") && password.equals(""))
            {
                JOptionPane.showMessageDialog(this,"login successful",
                    "SUCCESS!",JOptionPane.INFORMATION_MESSAGE);
                success_of_login = 1;
            }
            else if (username.equals("harshit shah") && password.equals("hrs"))
            {
                JOptionPane.showMessageDialog(this,"WELCOME HARSHIT",
                    "SUCCESS!",JOptionPane.INFORMATION_MESSAGE);
                success_of_login = 1;
            }
            else
            {
                JOptionPane.showMessageDialog(this,"Incorrect login or password",
                    "Error",JOptionPane.ERROR_MESSAGE);
            }
        }//end of method
    
    }//end of class
    this is my awt login window.
    On success it has to launch the following method of another class
    Java Code:
    import java.io.*;
    public class Main_menu
    {
           public static void main_menu() throws IOException
        {
            BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
            System.out.print('\u000C');
            System.out.println("      _.-''''''-._.-''''''-._      ");//ascii art by harshit shah..  
            System.out.println("     ||          |          ||     ");
            System.out.println("     || WELCOME  |    THE   ||     ");
            System.out.println("     ||    TO    |  B.G.E.S ||     ");
            System.out.println("     ||          |   SCHOOL ||     ");
            System.out.println("     ||.-''''''-.|.-'''''-._||     ");
            System.out.println("     '=========='^'=========='     ");
            System.out.println("\n \n ***WELCOME TO THE INFORMATION SYSTEM OF THE B.G.E.S SCHOOL***");
            System.out.println("CLASS 9 PROJECT MADE BY HARSHIT SHAH CLASS 9A");
            System.out.println("\nENTER 1 TO KNOW ABOUT THE SCHOOL");//takes to another class
            System.out.println("ENTER 2 FOR STUDENTS MARKSHEET");//takes to another class
            System.out.println("ENTER 3 FOR ADMISSION");//takes to another class
            System.out.println("ENTER 4 FOR KNOWING THE FACULTY");//takes to another class
            System.out.println("WRONG INPUT WILL TRIGGER THE PROGRAM AGAIN...");
            int ch=0;
            try
            {
                ch = Integer.parseInt(br.readLine());//taking choice
            }
            catch (java.lang.NumberFormatException ex)
            {
                main_menu();
            }
    
            switch (ch)//switch case
            {
                case 1://case 1 input 
                try//try-catch used here to get IOexception thrown
                {
    
                }
                catch (Exception E)//exception handler
                {
                    System.out.println("JAVA EXEPTION TRIGGERED.PLEASE CHECK FOR YOUR FAULTS");
                    System.out.println("FAULTS SUCH AS WRONG INPUTS, WRONG INPUT OR TYPE");
                }
                break;  
                case 2://case 2 input
                try//case 1 input 
                {//try-catch used here to get IOexception thrown
                    Student.student();
                }
                catch (Exception E)
                {
                    System.out.println("JAVA EXEPTION TRIGGERED.PLEASE CHECK FOR YOUR FAULTS");
                    System.out.println("FAULTS SUCH AS WRONG INPUTS, WRONG INPUT OR TYPE");
                }
                break; 
                case 3:
                try
                {
                    Admission.main();
                }
                catch (Exception E)
                {
                    System.out.println("JAVA EXEPTION TRIGGERED.PLEASE CHECK FOR YOUR FAULTS");
                    System.out.println("FAULTS SUCH AS WRONG INPUTS, WRONG INPUT OR TYPE");
                }
                break;
                case 4:
                try
                {
                    TeacherTable.teacher();
                }
                catch (Exception E)
                {
                    System.out.println("JAVA EXEPTION TRIGGERED.PLEASE CHECK FOR YOUR FAULTS");
                    System.out.println("FAULTS SUCH AS WRONG INPUTS, WRONG INPUT OR TYPE");
                }
                break;
    
                default:
                System.out.println("invalid input...please try again...");
                Main_menu.main_menu();
            }
        }
    
    }
    And this class runs other methods from other classes which work fine.

  3. #23
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: password/input masking in terminal

    Quote Originally Posted by vscntkZ View Post
    CHung cac ban nhung ngay cuoi nam lam viec hang hay va quyet tam.
    Chung toi rat cam on cac bai viet co gia tri cua cac ban.
    Trang trong cam on.
    what on earth are you telling me to do??

  4. #24
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default Re: password/input masking in terminal

    So, are you saying that the main_menu text is not appearing?
    Does that JOptionPane appear?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #25
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: password/input masking in terminal

    yes, that joptionpane appears, but the menu does not.

  6. #26
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default Re: password/input masking in terminal

    OK.
    Which takes me back to an earlier post.
    Put a printStackTrace() call into that exception catching block and see whether anything is being thrown.
    That would be my guess.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #27
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: password/input masking in terminal

    well, it still runs without the method being called, and i don't see any exception thrown at all.** I am using printStackTrace().

  8. #28
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default Re: password/input masking in terminal

    Can you show me that section of code with the changes in the catch block?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #29
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: password/input masking in terminal

    Java Code:
    if (username.equals("pratik sanyal") ||username.equals("pratik") ||username.equals("pratik sir") && password.equals("9051232032")||password.equals("cta")|| password.equals("pp"))
            {
                try
                {
                    Main_menu.main_menu();
                }
                catch(Exception E) 
                {
                    E.printStackTrace();
                }
                JOptionPane.showMessageDialog(this,"WELCOME PRATIK SIR!",
                    "SUCCESS!",JOptionPane.INFORMATION_MESSAGE);
                success_of_login = 1;
    
            }

  10. #30
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: password/input masking in terminal

    bump

  11. #31
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: password/input masking in terminal

    So what is or isn't happening now?

    Also, it looks like your if block should have extra parenthesis in there, else it will be true even with a bad password, something like:

    Java Code:
    if ((this || this || that) && (some other || some other || some other still)) {
    
    }

  12. #32
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: password/input masking in terminal

    okay I got it !
    I can launch the method but it wont take input from me...
    well I am posting the code here please help me find an error.

    Java Code:
    import javax.swing.*;//importing essential p[ackages
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Toolkit;
    import java.io.*;
    class Login  
    {
        public static int success_of_login = 0;
        JButton SUBMIT;//button for submitting data
        JPanel panel;
        JLabel label1,label2,label3;
        JTextField  text1,text2;
        public static void main()
        {
            try//try-catch method
            {
                Loginworker frame=new Loginworker();
                frame.setSize(700,150);
                frame.setLocation(400,400);
                frame.setVisible(true);//showing frame
            }
            catch(Exception e)//exception handler
            {
                System.out.println("JAVA EXEPTION TRIGGERED.PLEASE CHECK FOR YOUR FAULTS");
                System.out.println("FAULTS SUCH AS WRONG INPUTS, WRONG INPUT OR TYPE");
            }
        }
    
    }//end of class
    this is my first Login class

    Java Code:
    import javax.swing.*;//importing essential p[ackages
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;
    
    class Loginworker  extends JFrame implements ActionListener
    {
        public static int success_of_login = 0;
        JButton SUBMIT;//button for submitting data
        JPanel panel;
        JLabel label1,label2,label3;
        final JTextField  text1,text2;
        Loginworker()//initializer+constructor
        {
            label1 = new JLabel();
            label2 = new JLabel();
            label3 = new JLabel();
    
            label1.setText("Username:");
            text1 = new JTextField(15);
            text1.setBackground(Color.yellow); 
    
            label2.setText("Password:");//password field
            text2 = new JPasswordField(15);//from java.awt
            text2.setBackground(Color.red);
    
            SUBMIT=new JButton("login");
    
            panel=new JPanel(new GridLayout(3,1));
    
            panel.add(label1);
            panel.add(text1);
            panel.add(label2);
            panel.add(text2);
            panel.add(label3);
            panel.add(SUBMIT);
    
            setTitle("PLEASE LOGIN");//title bar
            add(panel,BorderLayout.CENTER);
            SUBMIT.addActionListener(this);
        }
    
        public void actionPerformed(ActionEvent ae)//using actionlistener
        {
            String username=text1.getText();
            String password=text2.getText();
            //checking inputs
            //and password
            //and username
            Toolkit.getDefaultToolkit().beep();
            if (username.equals("pratik sanyal") ||username.equals("pratik") ||username.equals("pratik sir") && password.equals("9051232032")||password.equals("cta")|| password.equals("pp"))
            {
                Login.success_of_login = 1;
                JOptionPane.showMessageDialog(this,"WELCOME PRATIK SIR!",
                    "SUCCESS!",JOptionPane.INFORMATION_MESSAGE);
                try
                {
                    Main_menu.main_menu();
                }     
                catch(Exception E) {E.printStackTrace();}
            }
            else if (username.equals("student") && password.equals(""))
            {
                Login.success_of_login = 1;  
                JOptionPane.showMessageDialog(this,"login successful",
                    "SUCCESS!",JOptionPane.INFORMATION_MESSAGE);
    
            }
            else if (username.equals("harshit shah") && password.equals("hrs"))
            {
                Login.success_of_login = 1;   
                JOptionPane.showMessageDialog(this,"WELCOME HARSHIT",
                    "SUCCESS!",JOptionPane.INFORMATION_MESSAGE);
    
            }
            else
            {
    
                JOptionPane.showMessageDialog(this,"Incorrect login or password",
                    "Error",JOptionPane.ERROR_MESSAGE); 
            }
    
        }//end of method
    }
    This class Loginworker runs the main_menu class method which runs successfully however in the terminal window it does not take input from the user.

    Java Code:
    import java.io.*;
    public class Main_menu
    {
        public static void main_menu() throws IOException
        {
            while(Login.success_of_login == 1) 
            {
                BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
                System.out.print('\u000C');
                System.out.println("      _.-''''''-._.-''''''-._      ");//ascii art by harshit shah..  
                System.out.println("     ||          |          ||     ");
                System.out.println("     || WELCOME  |    THE   ||     ");
                System.out.println("     ||    TO    |  B.G.E.S ||     ");
                System.out.println("     ||          |   SCHOOL ||     ");
                System.out.println("     ||.-''''''-.|.-'''''-._||     ");
                System.out.println("     '=========='^'=========='     ");
                System.out.println("\n\n***WELCOME TO THE INFORMATION SYSTEM OF THE B.G.E.S SCHOOL***");
                System.out.println("CLASS 9 PROJECT MADE BY HARSHIT SHAH CLASS 9A");
                System.out.println("\nENTER 1 TO KNOW ABOUT THE SCHOOL");//takes to another class
                System.out.println("ENTER 2 FOR STUDENTS MARKSHEET");//takes to another class
                System.out.println("ENTER 3 FOR ADMISSION");//takes to another class
                System.out.println("ENTER 4 FOR KNOWING THE FACULTY");//takes to another class
                System.out.println("WRONG INPUT WILL TRIGGER THE PROGRAM AGAIN...");
                int ch=0;
                try
                {
                    ch = Integer.parseInt(br.readLine());//taking choice
                }
                catch (java.lang.NumberFormatException ex)
                {
                    main_menu();
                }
    
                switch (ch)//switch case
                {
                    case 1://case 1 input 
                    try//try-catch used here to get IOexception thrown
                    {
                        PDFDocument.main();
    
                    }
                    catch (Exception E)//exception handler
                    {
                        System.out.println("JAVA EXEPTION TRIGGERED.PLEASE CHECK FOR YOUR FAULTS");
                        System.out.println("FAULTS SUCH AS WRONG INPUTS, WRONG INPUT OR TYPE");
                    }
                    break;  
                    case 2://case 2 input
                    try//case 1 input 
                    {//try-catch used here to get IOexception thrown
                        Student.student();
                    }
                    catch (Exception E)
                    {
                        System.out.println("JAVA EXEPTION TRIGGERED.PLEASE CHECK FOR YOUR FAULTS");
                        System.out.println("FAULTS SUCH AS WRONG INPUTS, WRONG INPUT OR TYPE");
                    }
                    break; 
                    case 3:
                    try
                    {
                        Admission.main();
                    }
                    catch (Exception E)
                    {
                        System.out.println("JAVA EXEPTION TRIGGERED.PLEASE CHECK FOR YOUR FAULTS");
                        System.out.println("FAULTS SUCH AS WRONG INPUTS, WRONG INPUT OR TYPE");
                    }
                    break;
                    case 4:
                    try
                    {
                        TeacherTable.teacher();
                    }
                    catch (Exception E)
                    {
                        System.out.println("JAVA EXEPTION TRIGGERED.PLEASE CHECK FOR YOUR FAULTS");
                        System.out.println("FAULTS SUCH AS WRONG INPUTS, WRONG INPUT OR TYPE");
                    }
                    break;
    
                    default:
                    System.out.println("invalid input...please try again...");
                    Main_menu.main_menu();
                }
            }
            System.out.println("PLEASE LOGIN");
        }
    }
    this my Main menu class which should take input from user about going to other methods which work fine but the problem is the program wont take take any input.
    Plase help.

  13. #33
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: password/input masking in terminal

    You've still set up your password checking if block wrong. Note that it will accept *any* password if the user name is correct or will accept *any* user name if the password is correct. Again you'll need to use parenthesis to nest the logical statements on either side of the && operator.

    Next, please clarify your problem greatly. Just what do you mean that the program won't take any input? Please assume that we can't read minds and can't understand code not shown. Also, it is generally a bad idea to mix a console program with a GUI. I can see significant threading issues with your program because of this with the console locking your GUI.

  14. #34
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: password/input masking in terminal

    i understand that you cant read my mind
    but the password here is somehow working on my IDE, not accepting wrong passwords, dont know how you are getting it,
    and i mean to say that terminal window wont take input(no cursor)
    i posted all the code above, the other class references, delete them and check please.
    thanks

  15. #35
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: password/input masking in terminal

    Quote Originally Posted by harshit shah View Post
    i understand that you cant read my mind
    but the password here is somehow working on my IDE, not accepting wrong passwords, dont know how you are getting it,
    You have a block that looks something like:

    Java Code:
    if (conditionA || conditionB || conditionC && conditionD || conditionE || conditionF) {
      // do something
    } else {
      // do something else.
    }
    In this code, if *any* of the conditions are true, because of the or operators, the entire statement is true.

    This can be tested simply via:

    Java Code:
          if (true || false || false && false || false || false) {
             System.out.println("inside if block");
          } else {
             System.out.println("inside else block");
          }
    What you want instead is

    Java Code:
    if ((conditionA || conditionB || conditionC) && (conditionD || conditionE || conditionF)) {
      // do something
    } else {
      // do something else.
    }
    See the difference?

    ... and i mean to say that terminal window wont take input(no cursor)
    i posted all the code above, the other class references, delete them and check please.
    thanks
    I'm not sure what to delete and what not to and still reproduce your problem. If you still need our help, I will ask that that effort be yours to do since you're the one asking for our free advice.

  16. #36
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: password/input masking in terminal

    But again, I would urge you to change your design completely and to not mix a Swing GUI with a console program. Prompt the user completely through the GUI and get input through the GUI only. Otherwise you're in for a world of confusion and lack of function.

  17. #37
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: password/input masking in terminal

    Or if all you want to do is to use the JFrame to log the person on, and if the rest of the program is a console program, then display a JOptionPane for the login.

  18. #38
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default Re: password/input masking in terminal

    Quote Originally Posted by harshit shah View Post
    i understand that you cant read my mind
    but the password here is somehow working on my IDE, not accepting wrong passwords, dont know how you are getting it,
    and i mean to say that terminal window wont take input(no cursor)
    i posted all the code above, the other class references, delete them and check please.
    thanks
    Hang on.
    I thought your problem was that you were not seeing any output in the console?
    To quote you from earlier:
    "well, it still runs without the method being called"

    Which implies that you do not see any of that text being output.

    If it's the lack of input then that's a different problem entirely.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  19. #39
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: password/input masking in terminal

    Quote Originally Posted by Fubarable View Post
    Or if all you want to do is to use the JFrame to log the person on, and if the rest of the program is a console program, then display a JOptionPane for the login.
    YES...I just created the Jframe for login purposes as you see all the other are in terminal window.

  20. #40
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: password/input masking in terminal

    Quote Originally Posted by Tolls View Post
    Hang on.
    I thought your problem was that you were not seeing any output in the console?
    To quote you from earlier:
    "well, it still runs without the method being called"

    Which implies that you do not see any of that text being output.

    If it's the lack of input then that's a different problem entirely.
    yes...first it did not show any output but after some minor modification of my code it is being now able to show output but it wont take any input from me.

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Help with password masking, please
    By krechlich in forum New To Java
    Replies: 10
    Last Post: 03-18-2011, 11:28 AM
  2. input masking 24hour time format (hh:nn) to jTextField
    By newbiejava in forum New To Java
    Replies: 2
    Last Post: 07-24-2010, 01:12 PM
  3. Masking password for logging
    By firewalll in forum New To Java
    Replies: 1
    Last Post: 09-29-2009, 08:04 AM
  4. how to check password for 3 times enterd wrong password
    By sk.mahaboobbhasha@gmail.c in forum New To Java
    Replies: 2
    Last Post: 11-14-2008, 07:53 PM
  5. Creating a dialog to input user/password
    By prfalco in forum New To Java
    Replies: 4
    Last Post: 02-18-2008, 07:03 AM

Tags for this Thread

Posting Permissions

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