This has been bothering me for some time, and I have come the the conclusion that I need some expert advise. I am trying to write a java swing applet that asks a user to enter a password into a JTextField and to then press [Enter]. Compare the password to "javapplet". If it matches, then display "access granted" in a JLabel. If it doesn't then display "access denied". Also, the password should not be case sensitive. Here is what I have so far, but I can't even get it to work right. Please help!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JGreet5 extends JApplet implements ActionListener
{
JLabel password = new JLabel("Please Enter The Password.");
Font bigFont = new Font("TimesRoman", Font.ITALIC, 24);
JTextField answer = new JTextField("",10);
JButton pressMe = new JButton("Press Me");
FlowLayout flow = new FlowLayout();
{
pressMe.addActionListener(
this);
answer.addActionListener(t
his);
}
public void init()
{
password.setFont(bigFont);
Container con = getContentPane();
con.add(password);
con.setLayout(flow);
con.add(answer);
con.add(pressMe);
answer.requestFocus();
}
public void actionPerformed(ActionEven
t thisEvent)
{
Object source = thisEvent.getSource();
if(source == pressMe)
{
String name = answer.getText();
System.out.println("Access
Granted " + name);
}
else if(source instanceof JTextField)
{
String name = answer.getText();
System.out.println("Access
Granted " + name);
}
}
}
Start Free Trial