Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-27-2007, 11:26 AM
Member
 
Join Date: Dec 2007
Posts: 34
saytri is on a distinguished road
Problem with a password
I'm having a problem with a password. The password is an integer, but my problem is that when someone tries to enter a string input, the program crashes, instead i want it to display invalid like when someone tries to enter an invalid integer password. I also wish to display the password in asterik form. What do i have to do? Can someone pls help me? Thanks a lot! The code i've written is below:-

Code:
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.io.*; import java.util.Scanner; import java.util.Arrays; public class GeographyQuiz extends JFrame implements ActionListener { private static final int FRAME_WIDTH = 140; private static final int FRAME_HEIGHT = 160; private static final int FRAME_X_ORIGIN = 70; private static final int FRAME_Y_ORIGIN = 50; AnswerStore answerStore = new AnswerStore(); public static void main (String[] args) { JFrame jFrame; jFrame = new JFrame(); JOptionPane.showMessageDialog(jFrame, "This is a Geography Quiz"); JOptionPane.showMessageDialog(null, "Good Luck"); char choice; int i, choice1, Password; String yourChoice, passString; passString = JOptionPane.showInputDialog("Enter the Password"); //Password = passString.nextInt(); Password = Integer.parseInt(passString.trim()); if (Password == 123) { JOptionPane.showMessageDialog(null, "Valid. You typed the right password. Now choose from the following menu"); GeographyQuiz frame = new GeographyQuiz(); frame.setVisible(true); } else { JOptionPane.showMessageDialog(null, "Invalid Password. Try Again"); } } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-27-2007, 12:03 PM
Member
 
Join Date: Jun 2007
Location: Bali, ID
Posts: 96
wsaryada is on a distinguished road
First, to hide the password you can use the JPasswordField swing component.

Second, to prevent your program from crashing you need to catch the NumberFormatException when you parse the input string to interger value, because the parseInt() method of the Integer class throws this exception if the input is not a valid number.
__________________
Website:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
- Blog:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by wsaryada : 12-27-2007 at 12:06 PM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-27-2007, 12:06 PM
Member
 
Join Date: Dec 2007
Posts: 34
saytri is on a distinguished road
Ok thanks. :-)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Password System help quickfingers New To Java 1 06-23-2008 07:18 PM
Asking for password from a Servlet Java Tip Java Tips 0 01-27-2008 09:05 PM
add password to folder ismailsaleh AWT / Swing 1 01-08-2008 06:46 AM
How would I transmit my password through java silvia Networking 1 07-30-2007 08:29 PM
Help with password matches Albert AWT / Swing 1 07-10-2007 05:17 PM


All times are GMT +3. The time now is 01:52 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org