Advertisement

12.15.2003 at 10:59PM PST, ID: 20826790
[x]
Attachment Details

java applet

Asked by MSAJM in Java Programming Language, New to Java Programming

Tags: java, access, applet

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(this);

}
      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(ActionEvent 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
[+][-]12.15.2003 at 11:06PM PST, ID: 9947489

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.15.2003 at 11:12PM PST, ID: 9947496

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Java Programming Language, New to Java Programming
Tags: java, access, applet
Sign Up Now!
Solution Provided By: yongsing
Participating Experts: 1
Solution Grade: A
 
 
[+][-]12.15.2003 at 11:27PM PST, ID: 9947536

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.15.2003 at 11:32PM PST, ID: 9947545

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32