• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

WebPage to Applet to WebPage to Java

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I am new to applets and trying to solve this scenario. Any help is greatly appreciated.

I have a webpage where user needs to select a folder/directory instead of a file by browsing (same functionality when html browse button is clicked)
Get the folder path selected by the user and call a java program which would move it to a different location.

My implementation plan:
Create an applet with 'Browse' button and when clicked use JFileChooser() method to select only folder/directory.
Transfer selected folder path to java program.

Questions:
How do I call JFileChooser functionality in my applet, what are the steps that need to be followed to achieve this functionality?
Once folder is selected, how to set it to a text field on the webpage so that user could see what was selected.
later when 'transfer' button is clicked, how to pass this selected folder path to my java code which does this move?

Any other alternatives to this is good with me.

Please ask your questions.

Regards,
Kriss.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For demo code, see the FileChooserDemo and FileChooserDemo2 examples at http://java.sun.com/docs/books/tutorial/uiswing/examples/components/index.html

Note that applets need to be signed in order to be allowed to use I/O stuff. See HowCanAnAppletReadFilesOnTheLocalFileSystem for details on that.

Lastly, the applet can access the web page it's in through the Common DOM API. That way you can store the path in an HTML form field.
 
Kriss Reddy
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf,

I went over FileChooser examples, it does exactly what I was looking for. Thanks.

Now When I select a folder/directory I want to show the selected path and provide 'OK' button instead of closing the applet. Is it adding another button and calling something like close() on clikc of it?

How do I show the selected path?

Thanks,
Kriss.
 
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
Where do you want to show it - in the applet or the web page?
 
Kriss Reddy
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
First, I want to show it in the Applet, in a text field or to a label and when applet is closed want to show it on the webpage.

As I am thinking about it and implementing it, I got another question

Assume that I select a folder, how should I invoke my next code ie to move folder to another location.

Does all of this needs to be implemented in an applet? Select, display and then move.

As I am new to Applets, Swing, AWT, I would like your opinion about how much time would it need to implement this functionality and what are my options for implementation, if Applets is not the best option.

Thanks,
Kriss
 
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
For showing it in the applet, add an empty JLabel when the GUI is created, and keep a reference to it around; then you can set the label's text later on.

when applet is closed want to show it on the webpage.


What does that mean? The applet won't be closed (or rather, stopped and discarded) until the page is closed, making a change of the page contents at that point a bit pointless.

how should I invoke my next code ie to move folder to another location.


Not sure what you mean by "invoke"; once you have the path of the directory, what stops you from doing all necessary file operations? In the easiest case, it would involve a single call to "new File(path).renameTo(...)".

Anything that involves accessing the local filesystem will need to be done in the applet, because HTML/JavaScript has no facilities for doing that.
 
Kriss Reddy
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Below is my simple applet.


This is how it is called on my web page.


function loadNextPage( )
{
document.write("<APPLET name='Transfer' code='com.test.transfer.Transfer.class' archive='transfer.jar'>");
document.writeln("<param name='archive' value='transfer.jar'>");
document.writeln("<param name='code' value='com.test.transfer.Transfer.class'>");
}
<form>
<input type="button" value="Proceed" size="10" onclick="loadNextPage()">
</form>




When called, Initially applet is not loaded, when I refresh browser then applet is loaded and I see
"Transferring....9"

Why applet is not loaded for the first time.

What if I want to see as it loops?

Where in the applet framework should I put my code so that I could my program and set out output to applet?

Thanks,
Kriss.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic