Results 1 to 2 of 2
  1. #1
    pls3399 is offline Member
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Default Need help- 2 issues- searching for text in a list and applet not working

    Hello all,

    I am trying to create an applet and have the following issues:

    1. Not sure of the syntax to search for variable "password" in list "anArraylist"
    2. Cannot get my applet to work

    Here is my code for the applet:

    Java Code:
    package password;
    
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Arrays;
    import javax.swing.*;
    
    
    public class Password extends JApplet implements ActionListener
    
    {
      JLabel greeting = new JLabel("Enter password (and click OK):");
      Font font1 = new Font("Arial", Font.BOLD, 22);
      Font font2 = new Font("Arial", Font.BOLD, 14);
      JTextField textbox = new JTextField(10);
      JButton OK = new JButton("OK");
      JLabel granted = new JLabel("Access Granted");
      JLabel denied = new JLabel("Access Denied");
      Container con = getContentPane();
      
      String[] anArray = { "rosebud", "redrum", "jason", "surrender", "dorothy" };
      List anArraylist = (List) Arrays.asList(anArray);
      
        
       
      public void init()
      {
          greeting.setFont(font1);
          granted.setFont(font2);
          con.add(greeting);
          con.add(OK);
          con.setLayout(new FlowLayout());
          con.setBackground(Color.GRAY);
          OK.addActionListener(this);
          textbox.addActionListener(this);
      }
        
       public void actionPerformed(ActionEvent e)
       {
           String password = textbox.toString();
            
           
           if (anArraylist.contains(password))    //Here's where I am having the issue searching in the list
           {
           con.add(granted);
           validate();
           }
           else 
           {
               con.add(granted);
           }
           
       }
    }
    and the html to load the applet:

    Java Code:
    <html>
        <object code = "Password.java" width = 450 height = 150>
    </object>
    </html>
    Also, NetBeans wants me to add @Override before each of my methods. Is this correct?

    Any help would be greatly appreciated.

    Thanks,
    Kevin

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Need help- 2 issues- searching for text in a list and applet not working

    Quote Originally Posted by pls3399 View Post
    Hello all,
    Hello and welcome to the java-forums.org!

    I am trying to create an applet and have the following issues:

    1. Not sure of the syntax to search for variable "password" in list "anArraylist"
    2. Cannot get my applet to work
    Please elaborate. What do you mean by 'Not sure of the syntax to search for variable "password" in list "anArraylist"'? What have you tried? How is it not working? And how is your applet not working? What errors are you seeing in the Java console?

    and the html to load the applet:

    Java Code:
    <html>
        <object code = "Password.java" width = 450 height = 150>
    </object>
    </html>
    I don't do applets, but are you sure about the .java extension? I would expect either .class or .jar no extension.

    Also, NetBeans wants me to add @Override before each of my methods. Is this correct?
    @Override use is a good idea if you ever override methods as it will queue the compiler to tell you if your method signature is not correct, if it does not match that of the parent type.

Similar Threads

  1. Efficiency of searching a list
    By fam2315 in forum New To Java
    Replies: 9
    Last Post: 06-29-2011, 04:34 AM
  2. what code for searching in drop down list?
    By Harmesh Goyal in forum Advanced Java
    Replies: 1
    Last Post: 03-03-2011, 05:43 AM
  3. searching a row using text fields
    By bigj in forum New To Java
    Replies: 1
    Last Post: 02-03-2010, 12:28 PM
  4. Searching for a String within an linked list
    By phil128 in forum Advanced Java
    Replies: 5
    Last Post: 04-13-2009, 03:18 AM
  5. Searching through a list.
    By wethekings in forum New To Java
    Replies: 3
    Last Post: 02-24-2009, 01:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •