The Artima Developer Community
Sponsored Link

Java Answers Forum
password

1 reply on 1 page. Most recent reply: Apr 16, 2008 9:46 PM by nelson ruiz

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
nelson ruiz

Posts: 7
Nickname: nogal
Registered: Mar, 2008

password Posted: Apr 12, 2008 10:35 PM
Reply to this message Reply
Advertisement
Hi.
I am doing a JApplet where I ask the user to enter a password to a JTextField and then press ENTER. Compare it with the word "Rosebud", if it matches exactly, display "Access Granted", if not, display "Access Denied".

I haven't found the way to compare the input and the password. Could somebody help me.... Thanks




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

public class JHello extends JApplet implements ActionListener
{

Container con = getContentPane ();
JLabel please = new JLabel ("Please Enter password");
Font headlineFont = new Font("Helvetica", Font.BOLD, 36);
JTextField answer = new JTextField (10);
JButton pressMe = new JButton("Click Here");
JLabel passtyped = new JLabel ("");
String password = "Rosebud";


public void init()
{
please.setFont(headlineFont);
con.add(please);
con.add(answer);
con.add(pressMe);
con.setLayout(new FlowLayout());
pressMe.addActionListener(this);
answer.addActionListener(this);

}


public boolean action(Event e)
{

if ( answer.equals ( password ) )
{
s = null;
}
else
{
s = "Access Denied";
repaint();
}
return true;
}


public void actionPerformed(ActionEvent e)
{
String name = answer.getText();
passtyped.setText("Access granted");
con.add(passtyped);
validate();
}

}


nelson ruiz

Posts: 7
Nickname: nogal
Registered: Mar, 2008

Re: password Posted: Apr 16, 2008 9:46 PM
Reply to this message Reply
Thanks for your help. I got it.

Flat View: This topic has 1 reply on 1 page
Topic: Problem extracting text using JPedal Previous Topic   Next Topic Topic: SSL connection between standalone program to EJB on an application server

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use