• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Making applet of java program for the first time

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys, this is my first post in this forum. I heard it is very good. Don't be rough on me cause I am a begginer. ;)
I have an idea of making a word cloud where text is read from .txt file and being presented onto the screen with most common words being written in bigger font. I wrote program in Java. It might be not sophisticated but working. I decided to make an applet of the same program.
The problem is that in initial java program(not applet) I had my graphics, readfile, sorting words methods in one class(if I remember correctly) AND NOW when I am trying to make an applet. From the examples on the net I found that graphics could/should be in constructor of class that extends JPanel. I am lost cause I don't know how to make GUI and readfile/calculations separately cause they are so connected. I know you are going criticize me for uploading too much code but it maybe the best way for you to understand what I am experiencing. Please, share your knowledge with me.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch. The amount of code is fine, but the big question is: Why an applet instead of an application? Applets can not use the local file system (as the code does in the "go" method), so it would need to load the file contents some other way - maybe via an URL from a server. But applets have fallen out of favor for security reasons, so I would question their use.
 
Jonas Kazlauskas
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for such quick reply. Why I chose to use applet? My thought process in child's words: wanted to make word cloud and put in on website. I used applet approach cause I didn't know any other alternatives(using Java language). Are there any?? I predict these things nowdays are being programmed with JavaScript?
I am gonna use my WAMP server to try to load my .txt file -> thank you for that, Ulf.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any heavy duty processing would be done on the server (possibly by a Java servlet, or a Java REST WS), and then accessed via a web page.

As regards reading a text file from a server in an applet, see the "HelloServerFile" example on https://coderanch.com/how-to/java/CodeBarnApplets.
 
Jonas Kazlauskas
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for reply. I will take your advice for using other approach then applet in the future. I told myself I am gonna finish with my plan making the applet running and move on. But it steams that I found a dead end. I spent so much time trying to get it running but failed and want to ask for your help. Please, help me
I changed the reading method as advised. Here is the code:



It runs with 4 warnings:
1) The import java.applet is never used;
2) The serializable class WCURL does not declare a static final serialVersionUID field of type long;
3) The serializable class display does not declare a static final serialVersionUID field of type long;
4) Iterator is a raw type. References to generic type Iterator<E> should be parameterized.

I created WCURL.jar file through eclipse IDE.
I created index.php file:


I put files in WCURL folder which I put in my WAMP server's www folder(local host). (See picture) The file WCURL.jar is in archive directory. And what I get is (see second picture). It should be filled with words from .txt file which is not empty. Any ideas? So lost...
Applet.png
[Thumbnail for Applet.png]
Files-on-www.png
[Thumbnail for Files-on-www.png]
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first step in debugging applets is to open the Java Console. If there are any exceptions or error messages, that's where you'll find them.

The jar file is probably not found - remove the "codebase" attribute, and put the jar file in the same directory as PHP file.

As to the warnings, unused imports can simply be deleted, and you can ignore the serialization warnings. As to the generics stuff ... well, let's get the applet working first :-)
 
Jonas Kazlauskas
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't get any exceptions or errors. Just the warnings I posted before. I removed "codebase" attribute and moved my jar file from archive dir to where my index.php and MyText.txt is. Still no good. Still getting the same view as in the picture I attached in my last post. I tried to change browsers - no effect. Looks like the file reading is done(see the picture).
Maybe the problem is in the bit of:?
Picture02.png
[Thumbnail for Picture02.png]
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can add lots of logging to the countWords method. It is called, after all, but doesn't seem to do the right thing. So printing out lots of stuff should help you narrow down the problem.
 
Jonas Kazlauskas
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. After adding:


In console I get:
Label created javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,
maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,
horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=cats,verticalAlignment=CENTER,verticalTextPosition=CENTER]
Label created javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,
maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,
horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=cats,verticalAlignment=CENTER,verticalTextPosition=CENTER]
....

So I come to conclusion that the casting is the problem. I wonder if I can somehow extract "text" attribute or is it better to try to get back before I create an Array of Objects and try somehow to get my desired string from LinkedHashSet?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

So I come to conclusion that the casting is the problem.


Why? I don't see any issue there.

I would use a specific layout, though - I'm not sure what the default layout is, you might be adding all labels on top of one another. Or use a TextArea, and add lines of text to it (unless the JLabels have some specific function).
 
Jonas Kazlauskas
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A minute after I submitted last post I figured out that it's not a casting issue but since you, Ulf, ar so great and fast in helping us - I didn't want to edit. The great news is that i got it running by (thanks to you) changing the layout

and


Now I need to play a bit with layout to make it look decent at least. I thank you very much for your help!
 
For my next trick, I'll need the help of a tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic