Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  

Help Required



Share on Google+Share on Google+

Help Required
2 Answer(s)      8 years ago
Posted in : Swing AWT
View Answers

August 26, 2008 at 7:30 PM

Hi friend,

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

public class LoginPassword extends JPanel implements ActionListener {
private static String OK = "ok";
private static String HELP = "help";

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

public LoginPassword(JFrame f) {
//Use the default FlowLayout.
controllingFrame = f;

//Create everything.
passwordField = new JPasswordField(15);

JLabel label = new JLabel("Enter the password: ");

JComponent buttonPane = createButtonPanel();

//Lay out everything.
JPanel textPane = new JPanel(new FlowLayout(FlowLayout.TRAILING));

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



return p;

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

if (OK.equals(cmd)) { //Process the password.
char[] input = passwordField.getPassword();
if (isPasswordCorrect(input)) {
"Success! You typed the right password.");
} else {
JOptionPane.showMessageDialog(controllingFrame,"Invalid password. Try again.","Error Message",

//Zero out the possible password, for security.
Arrays.fill(input, '0');

} else { //The user has asked for help.
"You can get the password by searching this example's\n"
+ "source code for the string \"correctPassword\".\n"
+ "Or look at the section How to Use Password Fields in\n"
+ "the components section of The Java Tutorial.");

August 26, 2008 at 7:33 PM

private static boolean isPasswordCorrect(char[] input) {
boolean isCorrect = true;
char[] correctPassword = { 'b', 'u', 'g', 'a', 'b', 'o', 'o' };

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

//Zero out the password.

return isCorrect;

protected void resetFocus() {

private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("password example in java");
final LoginPassword newContentPane = new LoginPassword(frame);
frame.addWindowListener(new WindowAdapter() {
public void windowActivated(WindowEvent e) {

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

Read for more information.




Related Tutorials/Questions & Answers:
help required in coding
help required in coding  hi..... I want to display output in graphical format . Can u tell me how it can be done? using for project java swings. plzzzzzz helpp
Help Required - Swing AWT
Help Required  How to bring password field in JDialogueBox??? ... static String HELP = "help"; private JFrame controllingFrame; //needed..."); JButton helpButton = new JButton("Help
Editor help required. - Java Server Faces Questions
Editor help required.  I am having problem with editor used to design JSP page in JSF applications. I want to open JSP page with Web Page Editor... are they? Please Help me.... Thanks In advance
Required help about the concept of JSP page reloading
Required help about the concept of JSP page reloading  Hi, We have one application with Websphere portlet Factory generated JSP as front end... char set. Your inputs are highly appreciated. It will help us to have better
Required help about the concept of JSP page reloading
Required help about the concept of JSP page reloading  Hi, We have one application with Websphere portlet Factory generated JSP as front end... set. Your inputs are highly appreciated. It will help us to have better insight
HELP! Design Review & Risk Management topics (in Java projects) required - Development process
HELP! Design Review & Risk Management topics (in Java projects) required  Hi, I have to take 2 one hour sessions on the following topics... topics/examples/case studies for the same? Any help will be much appreciated
code required.!
Java Script phone number entered by person should be in numeric only. code required!  i am using javascript coding on jsp page. i want that the phone number entered by person should be in numeric only..can i get code
code required
page Will you plz help me out by providing me with the code
code required in servlet
code required in servlet  hello... you provided me the answer with javascript.. i want to check which button is clicked in the servlet.. i have only... help
E BOOK REQUIRED  Wicket in Action pdf required Urgently. Thnx
property datasource required - Spring
property datasource required  Hi I am using java springs I am using mysql as backend I am getting one error when i compile the datasource required. This is my dispatcher-servlet.xml
Urgently required SEO
Freelance SEO       Position Vacant: Urgently required SEO Job Description ...; Website:  Reference ID: Urgently required
steps required to execute a query in JDBC
steps required to execute a query in JDBC  What are the steps required to execute a query in JDBC
help   how i can send a pitcture on url in java
What skills are required to be a Hadoop developer?
What skills are required to be a Hadoop developer?  Hi, How to become a good Hadoop Developer? What skills are required to be a Hadoop developer? Thanks
help  pls help me to get the code of a java program a program to perform different shapes in a menu using javaapplet
help  i need help with this code. write a java code for a method named addSevenToKthElement that takes an integer array, and an integer k as its arguments and returns the kth element plus 7. any help would be greatly
HELP  I need this code to open in a new web browser. but no matter what i do it wont please help?? Directive 055 Storage Requirements for the Upstream Petroleum Industry
Help...  Write a class that displays your first name vertically down the screen ?? where each letter uses up to 5 rows by 5 columns of a character input by you with a blank line between each letter
Help   i have a html file.. i have take input and store in database .. Tell me the steps to perform.. i have xampp it includes mysql,tomacat,apache. and how display the data from datbase .. please explain
Help!  thanks for ur code, I'd like to ask a question: after press "c" or "C", timer starts and after every delay ms, it'll print "This line is printed only once." or just print once. I'm writting a timer but it seems to perform
Help  Hi; Can anyone help me to solve this errors. I use J2ME(wirlesee Toolkit 2.5.2. for CLDC Project "SlideImageMIDlet" loaded Project settings saved Building "SlideImageMIDlet" C:\Documents and Settings\???? ?????\j2mewtk
to the user) please tell me how could i design that. Please help me asap Thanks a lot
based on the percentage of cheating. please help me
help!!!!!!!!!!!!!!!!!!  import java.awt.; import java.sql.*; import javax.swing.*; import java.awt.event.* public class NewJFrame extends javax.swing.JFrame { JTextField1
Date Format required to change in java
Date Format required to change in java  can we change the format of date like sql as per our requirements???If yes then please give the detail solution
Hibernate required jar files - Hibernate
Hibernate required jar files  Hi, What are the jar files are required for hibernate and Springs application. I want to run complete application springs and hibernate. Where it will be available? How can i use it i.e.
jQuery required validation
jQuery required Validation: jQuery "required" is the method...;/option>. Getting Started with jQuery required : In this example there are the following steps which are used to make jQuery required. This example  Makes
Tools required to build Simple Cart
Tools required to build Simple Cart       Shopping cart application is written in Java and so... tools are required--- Java Development Kit (JDK), 1.4 or later. Apache Ant
Spring @Required Annotation
Spring @required Annotation In this tutorial you will see about spring @required annotation with an example. The @Required when written on top of setStudent... that org.springframework.beans.factory.BeanInitializationException: Property 'student' is required for bean 'college
sample JSP&Servlet application required? - JSP-Servlet
sample JSP&Servlet application required?  hey all iam new... tutorial or a project that integrate both jsp&servlets any help?  Hi Friend... will be helpful for you. Thanks  thanks for your help i need more