aspose file tools*
The moose likes Beginning Java and the fly likes Need help- 2 issues- searching for text in a list and applet not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need help- 2 issues- searching for text in a list and applet not working" Watch "Need help- 2 issues- searching for text in a list and applet not working" New topic
Author

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

Kevin Anderson
Greenhorn

Joined: Jan 14, 2013
Posts: 10

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:



and the html to load the applet:



Also, NetBeans wants me to add @Override before each of my methods. Is this correct?

Any help would be greatly appreciated.

Thanks,
Kevin
Joe Ridener
Ranch Hand

Joined: Jul 16, 2012
Posts: 86
We'll go backwards here.
Starting with 2. Getting your Applet to work. You are going to want to create a jar file. .JAVA files will not function from an HTML tag. This is similar to compiling a class file from the command line. Many beginners struggle with this, so let me know if you cannot do it.
Place your .JAVA file in the apropriate directory (this depends on where the command line is currently pointing) and turn the Java file into class files. Same as you would wen running it from the command line.
Next enter this command...

C:\Documents and Settings\Admin\Current Directory > jar cvf FileName.jar *.class
and use the .jar file in a object or Applet tag of your html file.
It is that simple.

As to the first part of your question, there is a few different ways to answer this and probably not the best person to do it. Although my way would prolly work just as well.
Class String has a compareTo() method for case sensitive evaluations and comapreToIgnoreCase() for non-case sensitive evaluations. You simply place the string to be evaluated as the argument and it will return an integer value that will be 0 if they are equal ( the password matches ) -1 or 1 if it is greater than or less than the calling instance.

I only took a quick look at your code and it seemed like I could not really tell what the problem was at a glance, but I would recommend that method for password evaluations. You can use it from any instance of class String.
Joe Ridener
Ranch Hand

Joined: Jul 16, 2012
Posts: 86
Oops!

I just looked at your code again. The problem you may be having with that is most likely generated from line 41. This should return a textual representation of that particular instance of JTextArea, which by default is the hex digit address that represents it's current location in memory if I remember correctly that is supposed to be used for hashing.

Method getText() is prolly the method you should be using. Read the UML from the menu and select the appropriate method for what you are trying to do. But that's where your problem is most likely coming from.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
Kevin Anderson wrote:NetBeans wants me to add @Override before each of my methods. Is this correct?

That's optional, but it's good practice. It saves you from typos where you meant to override method doTheFoobarThing but misremembered the name and typed that to read doThatFoobarThing instead. Without the @Override annotation, the compiler doesn't know that you intended this method override something, and will happily create a method that will never be called. If you had added an @Override annotation to it, the compiler would check that it does indeed override another method, and tell you if it doesn't due to the misspelling. That can be quite a time saver!

It can also help someone else who reads the code to understand it, as they may not always be aware of which methods are intended to override something.


Ping & DNS - my free Android networking tools app
Kevin Anderson
Greenhorn

Joined: Jan 14, 2013
Posts: 10

Thank you for your responses. I am now at a build-able state and was able to create the .jar file. Now when I try loading the applet in IE, I get ClassNotFoundException password.jar.

https://www.dropbox.com/s/ugx7v57x9sphkgp/Untitled.png

I have made sure that the html file, .jar, .java, and .class files are in the same directory. Am I missing something?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
Both class and jar file? That sounds suspicious. Use one or the other, but not both. If you use a jar file, you need to reference that in an archive attribute in your applet tag.
Kevin Anderson
Greenhorn

Joined: Jan 14, 2013
Posts: 10

I have my .html, .class, java, and .jar files on dropbox:

https://www.dropbox.com/s/rrr48gaj9e3wlhs/Password.zip

This may help.

Thank you for everyone's help
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
With all due respect, I think it is asking too much of folks here to download a zip file from an anonymous file sharing site. Can you post the file/directory layout, the full stack trace of the exception, and the applet tag you're now using?
Joe Ridener
Ranch Hand

Joined: Jul 16, 2012
Posts: 86
Kevin Anderson wrote:Thank you for your responses. I am now at a build-able state and was able to create the .jar file. Now when I try loading the applet in IE, I get ClassNotFoundException password.jar.

https://www.dropbox.com/s/ugx7v57x9sphkgp/Untitled.png

I have made sure that the html file, .jar, .java, and .class files are in the same directory. Am I missing something?


One you do not need the class file. ClassNotFoundException is something I have gotten a few times. Not the best person to answer that. Though I work my way around it somehow each time I get it. Use the .jar file exclusively and discard the .class files. Things you might want to look for in your code may include unwanted references such as the package name if your editor adds it to the beginning of the ,java file. Though good practice. it will mess things up when you compile it into a class file. Check for logical errors that include referencing things that are not there.
Kevin Anderson
Greenhorn

Joined: Jan 14, 2013
Posts: 10

Sorry about that. Here is my code:



Kevin Anderson
Greenhorn

Joined: Jan 14, 2013
Posts: 10

Joe Ridener wrote:
Kevin Anderson wrote:Thank you for your responses. I am now at a build-able state and was able to create the .jar file. Now when I try loading the applet in IE, I get ClassNotFoundException password.jar.

https://www.dropbox.com/s/ugx7v57x9sphkgp/Untitled.png

I have made sure that the html file, .jar, .java, and .class files are in the same directory. Am I missing something?


One you do not need the class file. ClassNotFoundException is something I have gotten a few times. Not the best person to answer that. Though I work my way around it somehow each time I get it. Use the .jar file exclusively and discard the .class files. Things you might want to look for in your code may include unwanted references such as the package name if your editor adds it to the beginning of the ,java file. Though good practice. it will mess things up when you compile it into a class file. Check for logical errors that include referencing things that are not there.


I tried removing the package name and the error changed to java.lang.reflect.invocationtargetexception. Also, removing the other files did not work. Thanks though.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
Try an applet tag instead; the object tag can be tricky to get working across browsers:

<applet code="password.Password" archive="Password.jar" width = 450 height = 150></applet>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help- 2 issues- searching for text in a list and applet not working