Solved

renameTo() problem second part

Posted on 1998-06-20
10
279 Views
Last Modified: 2012-08-13
I would like to submit this again;to restate: I have the
code for a applet which will rename a directory when a
button is pushed. I believe the problem is in the action
event performer which is the last part. Ragnar thought
I was going to input from the command line but this is
not the way I meant. The button does work and readout
of the action but no action is performed to rename the
directory. This ends restatement. This time I uploaded the
.java file to http://users.aol.com/baywooddr/Choosing.java
Ragnar answer the first part, perhaps he can try again;
the suggestion he gave did not solve the problem.
0
Comment
Question by:johnh619
10 Comments
 
LVL 6

Expert Comment

by:gadio
ID: 1223438
If you can repeat your original question and describe the problem exactly it would be helpfull.
0
 

Author Comment

by:johnh619
ID: 1223439
Edited text of question
0
 
LVL 5

Expert Comment

by:fontaine
ID: 1223440
Are you signing the applet? If you don't do it, you will not be able to rename a directory,
which is a local resource and is outside of the Java sandbox.
0
 

Author Comment

by:johnh619
ID: 1223441
Fontaine I uploaded a file Choosing.java to http://users.aol.com/
baywooddr/ and I copied part of it. I found a renameTo example
and the guy had put the renameTo method in the system.out.printlin parentheses. I did not know I could do that
but it works that way. I really dont know about signing it
and I will have to look that up. The next problem I resubmitted
after I got this part working. I compiled it and put it in a
html page and it would not start properly. I thought maybe it
should have more work in the applet part about standalone
programs. So I guess I might email you again later after I
read up on this signing idea. Thanks
I also uploaded Choosing.java to http://www.geocities.com/
ResearchTriangle/Lab/6810








0
 

Author Comment

by:johnh619
ID: 1223442
When you signing the applet did you mean like a method signature?
I looked up signature and found this table saying
z=boolean
b=byte
and so on
this is a method signature I believe. I did not see reference
to signing an applet in my books.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 5

Expert Comment

by:fontaine
ID: 1223443
Here is a link that provides you with information on this:

http://www.geocities.com/SiliconValley/Vista/1337/java-s1.html

With an application, you can access local resources such as files, connect to an arbitrary
server, i.e. do all you would do with another language such as C++. An applet however,
has some restrictions that prevent bad guys to do bad jokes such as grab confidential
data from your disk, or whatever. An applet can't connect to an arbitrary host, but only
the machine that has served the applet and does not have access to local resources.
To gain these accesses, you need to sign the applet, what opens the security sandbox
the applet works in. This page explains you that:

http://www.javasoft.com/products/jdk/1.2/docs/guide/security/spec/security-spec.doc1.html

0
 
LVL 2

Expert Comment

by:aziz061097
ID: 1223444
Hi John,

       Yes your program works if you do not run it from the browser. As fontaine said ,You need to sign the Applet before you can load in the browser. I converted your program to Applet instead of running as an application (Frame) if that is what you are trying by doing Standalone??? . It works fine when run from appletviewer but will and does give Security exceptions when the buttons are clicked in browser, since browsers have security restrictions that can not do operations on the Harddisk (local resources) .

           The applet will work after you sign it, which eases the security of the browsers.

http://www.geocities.com/SiliconValley/Park/9841/sign.html

has some info on Signing .
0
 

Author Comment

by:johnh619
ID: 1223445
I guess also I dont understand the idea of interfaces also.
It seems if I start with extend from frame then I do not get
the error message saying the type File was in the declarations
or top of the program. If I entend applet I do get an error
at line
File f1= new file ("path")
saying that File was not recognized. I am presently reading
about multiple inheritance and it says I can have an interface
made of methods which will let me inherit from applet and
Frame or should it be applet and io classes.
In any case I shall read the file about signing which I did not
know existed until you told me. Perhaps then this may be the
end of this questioning.
0
 

Author Comment

by:johnh619
ID: 1223446
I can see now since reading up on signing that it is no wonder
that my applet would not run in the browser since it involved
file security. I of course at present think that making it a
stand alone java applet would be easier than trying to get a
signing certicate. I am a disabled veteran and this is my hobby
and is not a money making adventure. So now I can see how the
standalone idea becomes interesting. But really I am assuming
by standalone that they mean the applet does not require a
browser. I have a copy of java cafe and jbuilder and they support
creating an application I believe so I will try to make the
standalone applcation. Or I could let my user download a copy
of java.exe I suppose since it is only 5120 bytes. I am right
about that?
0
 
LVL 5

Accepted Solution

by:
fontaine earned 50 total points
ID: 1223447
Whenever an applet tries to access local resources or connect to a machine that is not
the one that has served it, signing is required.

Info on the security model:
http://www.javasoft.com/products/jdk/1.2/docs/guide/security/spec/security-spec.doc1.html

Info on signing:
http://www.geocities.com/SiliconValley/Vista/1337/java-s1.html

You extended Frame when you wrote your prog. as an application.
-> no security problem, file accesses are OK

To write an applet, you extend java.applet.Applet. With an applet, file accesses are not
permitted, except if you sign it (see above).

Multiple inheritance does not exist in Java. An interface simply defines a set of method signatures your class has to implement. They don't have a default implementation.
If you write:

public class Test extends AClass implements AnInterface {
 //...
}

all the methods of AnInterface have to be present in the code of Test, but you have to
implement them yourself, you are not inheriting any default implementation like in class
inheritance.

Your users only need the classes(.class) you have developed in order to run the app. as
well a Java virtual machine. The users should consult their machine vendor (HP, DEC, etc.)
in order to get one (for free). If MyClass is the name of the '.class' that contains the main()
of the app., users will typically type:

java MyClass

to run the application. I guess you should have some doc. with the IDE that explains you
how to distribute what you have created.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now