Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Requests to server

 
Ranch Hand
Posts: 837
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I have an applet that can request data from a server directly? I have a JApplet that displays some drawings made through AWT. I want to have some links on the drawing that can "lookup" data from the server, directly from the applet and return it. What choices do I have to accomplish this? Suggestions are appreciated. Thanks.

Rob
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you read this part of the Oracle tutorial regarding Applets?
 
Ranch Hand
Posts: 473
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well You can have those drawings put up in icons or labels and call mouseClicked events on the and have a method that sends request to some servlet on the server. The servlet then returns some data in string or Object form and the Applet then displays it in its assigned place. If that is an Object that server sends and applet reads, then you have to have the Class file of that Object too with the applet.

I can further help you if you tell me what you need...



Maki Jav
 
Rob Hunter
Ranch Hand
Posts: 837
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I had a simple as possible example I could work from that. So basically a JApplet that (upon clicking a JButton) would make a call directly to the server, read a textfile with first name and last name in it, and display a popup with those 2 values in it. I've read about RMI but with RMI you would need to download a jar file onto the client (correct?) and that's not something I want to do (don't want to have people download additional requirements). I just want to have an app in JApplet app that resembles a html page that utilizes AJAX (i.e. doesn't need to refresh and can directly grab info from the server behind the scenes). Does that help? If you have any additional info I'd appreciate it if you could pass it along. Thanks for your post as well.
 
Maki Jav
Ranch Hand
Posts: 473
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well it is either JApplet or Ajax; not Applet and Ajax; got me?

Well that is easy to build.

Have a server response on your server side like Servlet...

Heard that JApplet can read file from that same url from which it is loaded. And I have worked on it too.

Read textfile from url through applet and display it.

I will have to write code for you?



Maki Jav
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The https://coderanch.com/how-to/java/CodeBarnApplets page has an example applet that reads a file from a server and processes its contents. Instead of a static URL, the applet could as well access a servlet that returns dynamic content.
 
Maki Jav
Ranch Hand
Posts: 473
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok here is the code:


This is a text file readme.txt qhich has

Maki
Jav




and the Applet we have for reading is:





and to put this applet in html


you will need to have an index.html file with applet tag.


<HTML><HEAD></HEAD><BODY>
<APPLET CODE="TestIO" codebase="." WIDTH=800 HEIGHT=300></APPLET>
</BODY></HTML>






The text file and applet class and index.html will all be in the top folder of your web application.

If you need more help, please ask.


Thanks,

Maki Jav
 
Always! Wait. Never. Shut up. Look at this tiny ad.
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic