aspose file tools*
The moose likes Applets and the fly likes WebPage to Applet to WebPage to Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "WebPage to Applet to WebPage to Java" Watch "WebPage to Applet to WebPage to Java" New topic
Author

WebPage to Applet to WebPage to Java

Kriss Reddy
Ranch Hand

Joined: Mar 29, 2005
Posts: 54
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.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
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.


Ping & DNS - my free Android networking tools app
Kriss Reddy
Ranch Hand

Joined: Mar 29, 2005
Posts: 54
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
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
Where do you want to show it - in the applet or the web page?
Kriss Reddy
Ranch Hand

Joined: Mar 29, 2005
Posts: 54
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
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
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

Joined: Mar 29, 2005
Posts: 54
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: WebPage to Applet to WebPage to Java