Help Required

Help Required

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);
passwordField.setActionCommand(OK);
passwordField.addActionListener(this);

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

JComponent buttonPane = createButtonPanel();

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

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

okButton.setActionCommand(OK);
helpButton.setActionCommand(HELP);
okButton.addActionListener(this);
helpButton.addActionListener(this);

p.add(okButton);
p.add(helpButton);

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)) {
JOptionPane.showMessageDialog(controllingFrame,
"Success! You typed the right password.");
} else {
JOptionPane.showMessageDialog(controllingFrame,"Invalid password. Try again.","Error Message",
JOptionPane.ERROR_MESSAGE);
}

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

passwordField.selectAll();
resetFocus();
} else { //The user has asked for help.
JOptionPane.showMessageDialog(controllingFrame,
"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.
Arrays.fill(correctPassword,'0');

return isCorrect;
}

protected void resetFocus() {
passwordField.requestFocusInWindow();
}

private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("password example in java");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final LoginPassword newContentPane = new LoginPassword(frame);
newContentPane.setOpaque(true);
frame.setContentPane(newContentPane);
frame.addWindowListener(new WindowAdapter() {
public void windowActivated(WindowEvent e) {
newContentPane.resetFocus();
}
});
frame.setSize(500,200);
frame.setVisible(true);
}

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

Read for more information.

http://www.roseindia.net/java/example/java/swing/

Thanks.

Amardeep









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
Advertisements
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
page Will you plz help me out by providing me with the code
help
help   how i can send a pitcture on url in java
help
help  pls help me to get the code of a java program a program to perform different shapes in a menu using javaapplet
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
help
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
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...
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
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!
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
verification mail to the user) please tell me how could i design that. Please help me
Help
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
help
based on the percentage of cheating. please help me
help!!!!!!!!!!!!!!!!!!
help!!!!!!!!!!!!!!!!!!  import java.awt.; import java.sql.*; import javax.swing.*; import java.awt.event.* public class NewJFrame extends javax.swing.JFrame { JTextField1
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
ModuleNotFoundError: No module named 'required'
ModuleNotFoundError: No module named 'required'  Hi, My Python... 'required' How to remove the ModuleNotFoundError: No module named 'required... to install padas library. You can install required python with following
E BOOK REQUIRED
E BOOK REQUIRED  Wicket in Action pdf required Urgently. Thnx
maths required for data science
maths required for data science  Hi, I am beginner in Data Science... required for data science Try to provide me good examples or tutorials links so that I can learn the topic "maths required for data science". Also
statistics required for data science
statistics required for data science  Hi, I am beginner in Data...: statistics required for data science Try to provide me good examples or tutorials links so that I can learn the topic "statistics required for data
degree required for data scientist
degree required for data scientist  Hi, I am beginner in Data...: degree required for data scientist Try to provide me good examples or tutorials links so that I can learn the topic "degree required for data scientist"
data scientist required degree
data scientist required degree  Hi, I am beginner in Data Science... scientist required degree Try to provide me good examples or tutorials links so that I can learn the topic "data scientist required degree". Also tell
education required for data scientist
education required for data scientist  Hi, I am beginner in Data...: education required for data scientist Try to provide me good examples or tutorials links so that I can learn the topic "education required for data
math required for ai
math required for ai  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: math required... the topic "math required for ai". Also tell me which is the good training
Is math required for data science?
Is math required for data science?  Hi, I am beginner in Data...: Is math required for data science? Try to provide me good examples or tutorials links so that I can learn the topic "Is math required for data science?"
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 application.property datasource required. This is my dispatcher-servlet.xml
Regular Expression Help Help HELP!!!!
Regular Expression Help Help HELP!!!!  HI all I am very new to java... could help me to give a solution of how to retrieve the name and email add... the quotes ""07001", "MR Harish Ram","M.RHarish @ hotmail.com"" Help is greatly
Urgently required SEO
Freelance SEO       Position Vacant: Urgently required SEO Job Description ...  Reference ID: Urgently required SEO ADS_TO_REPLACE_4
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
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
ModuleNotFoundError: No module named 'yxs_required'
ModuleNotFoundError: No module named 'yxs_required'  Hi, My Python... 'yxs_required' How to remove the ModuleNotFoundError: No module named 'yxs_required' error? Thanks   Hi, In your python
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
the skills required to master data science is/are
the skills required to master data science is/are  Hi, I am beginner... to learn: the skills required to master data science is/are Try to provide me...;the skills required to master data science is/are". Also tell me which is the good
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.
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
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
Help me
Help me  Hi, LWUIT is working in eclipse j2me for Symbian OS
top skills required to be a Data Scientist in less time
top skills required to be a Data Scientist in less time  Hi, I want to the skills for becoming a Data Scientist. What are the top skills required... exploring the field of Data Science. You kind guide will help me in learning
help me
help me  HI. Please help me for doing project. i want to send control from one jsp page to 2 jsp pages... is it possible? if possible how to do
help me
help me  how to print from a-z, A-Z with exact order using for loop? Thanks for all concern
Help Me
Help Me  What is the source code for Sample example for Mortgage Calculator in J2ME language for developing Symbian
jQuery required validation
for this text field .With the help of this text field we check that the required field...jQuery required Validation: jQuery "required" is the method...;/option>. Getting Started with jQuery required :ADS_TO_REPLACE_1 In this example
help
help
help

Ads