Results 21 to 40 of 53
- 01-23-2013, 04:18 PM #21
Member
- Join Date
- Jan 2013
- Location
- Kolkata,India
- Posts
- 59
- Rep Power
- 0
- 01-23-2013, 04:26 PM #22
Member
- Join Date
- Jan 2013
- Location
- Kolkata,India
- Posts
- 59
- Rep Power
- 0
Re: password/input masking in 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.
this is my awt login window.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
On success it has to launch the following method of another class
And this class runs other methods from other classes which work fine.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(); } } }
- 01-23-2013, 05:14 PM #23
Member
- Join Date
- Jan 2013
- Location
- Kolkata,India
- Posts
- 59
- Rep Power
- 0
- 01-23-2013, 05:26 PM #24
Moderator
- Join Date
- Apr 2009
- Posts
- 10,479
- Rep Power
- 16
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.
- 01-24-2013, 02:39 PM #25
Member
- Join Date
- Jan 2013
- Location
- Kolkata,India
- Posts
- 59
- Rep Power
- 0
Re: password/input masking in terminal
yes, that joptionpane appears, but the menu does not.
- 01-24-2013, 03:56 PM #26
Moderator
- Join Date
- Apr 2009
- Posts
- 10,479
- Rep Power
- 16
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.
- 01-24-2013, 04:17 PM #27
Member
- Join Date
- Jan 2013
- Location
- Kolkata,India
- Posts
- 59
- Rep Power
- 0
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().
- 01-24-2013, 05:36 PM #28
Moderator
- Join Date
- Apr 2009
- Posts
- 10,479
- Rep Power
- 16
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.
- 01-25-2013, 04:42 PM #29
Member
- Join Date
- Jan 2013
- Location
- Kolkata,India
- Posts
- 59
- Rep Power
- 0
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; }
- 01-27-2013, 05:51 PM #30
Member
- Join Date
- Jan 2013
- Location
- Kolkata,India
- Posts
- 59
- Rep Power
- 0
Re: password/input masking in terminal
bump
-
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)) { }
- 01-27-2013, 06:02 PM #32
Member
- Join Date
- Jan 2013
- Location
- Kolkata,India
- Posts
- 59
- Rep Power
- 0
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.
this is my first Login classJava 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 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 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 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.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"); } }
Plase help.
-
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.
- 01-27-2013, 06:36 PM #34
Member
- Join Date
- Jan 2013
- Location
- Kolkata,India
- Posts
- 59
- Rep Power
- 0
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
-
Re: password/input masking in terminal
You have a block that looks something like:
In this code, if *any* of the conditions are true, because of the or operators, the entire statement is true.Java Code:if (conditionA || conditionB || conditionC && conditionD || conditionE || conditionF) { // do something } else { // do something else. }
This can be tested simply via:
What you want instead isJava Code:if (true || false || false && false || false || false) { System.out.println("inside if block"); } else { System.out.println("inside else block"); }
See the difference?Java Code:if ((conditionA || conditionB || conditionC) && (conditionD || conditionE || conditionF)) { // do something } else { // do something else. }
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.... 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
-
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.
-
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.
- 01-28-2013, 10:42 AM #38
Moderator
- Join Date
- Apr 2009
- Posts
- 10,479
- Rep Power
- 16
Re: password/input masking in terminal
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.
- 01-28-2013, 02:31 PM #39
Member
- Join Date
- Jan 2013
- Location
- Kolkata,India
- Posts
- 59
- Rep Power
- 0
- 01-28-2013, 02:33 PM #40
Member
- Join Date
- Jan 2013
- Location
- Kolkata,India
- Posts
- 59
- Rep Power
- 0
Similar Threads
-
Help with password masking, please
By krechlich in forum New To JavaReplies: 10Last Post: 03-18-2011, 11:28 AM -
input masking 24hour time format (hh:nn) to jTextField
By newbiejava in forum New To JavaReplies: 2Last Post: 07-24-2010, 01:12 PM -
Masking password for logging
By firewalll in forum New To JavaReplies: 1Last Post: 09-29-2009, 08:04 AM -
how to check password for 3 times enterd wrong password
By sk.mahaboobbhasha@gmail.c in forum New To JavaReplies: 2Last Post: 11-14-2008, 07:53 PM -
Creating a dialog to input user/password
By prfalco in forum New To JavaReplies: 4Last Post: 02-18-2008, 07:03 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks