Two basic questions considering Swing

G

gajo

Hi, I have two questions considering Java Swing.
1) I have a button and I want to use it to stop my JApplet. I tried
applet.stop() but it didn't do a thing (no errors, nothing). How can I do
this?
2) When I click on another button I want a JFileChooser dialog to show up so
I can open a file. I've read Sun's tutorial but their example doesn't work
either, so I have the feeling it might have to do with me using J2SE 1.2 and
not 1.4 the newest version. However, I cannot switch to the newest version,
so can someone help me how to solve this problem? Here's the code I'm trying
to use:

JFileChooser dijalog = new JFileChooser(); // this is where the exception
occurs!
int returnVal = dijalog.showOpenDialog(getContentPane());
if(returnVal == JFileChooser.APPROVE_OPTION) {
fajl = dijalog.getSelectedFile().getName();
}

I can't quote the entire stack thread cause it gets lost out of the screen,
so I've made a JTextArea and put the exception.getMessage() string in it. It
says the following:

access denied (java.util.PropertyPermission user.dir read)

Do I need to set some permissions, or is this because I'm using an older
version of Java? I'm not trying out my applet in a browser, but by starting
appletviewer, so there shouldn't be any security issues AFAIK...

Gajo
 
I

Ian Shef

gajo said:
Hi, I have two questions considering Java Swing.
1) I have a button and I want to use it to stop my JApplet. I tried
applet.stop() but it didn't do a thing (no errors, nothing). How can I
do this?

stop() is called by the browser (or viewer) when it is about to display
something else and doesn't want your JApplet running anymore. It is YOUR
responsibility to put something there to handle this. Similarly, it is
YOUR responsibility to figure out what to do when you yourself want to stop
your JApplet.
2) When I click on another button I want a JFileChooser dialog to show
up so I can open a file. I've read Sun's tutorial but their example
doesn't work either, so I have the feeling it might have to do with me
using J2SE 1.2 and not 1.4 the newest version. However, I cannot switch
to the newest version, so can someone help me how to solve this problem?
Here's the code I'm trying to use:

JFileChooser dijalog = new JFileChooser(); // this is where the
exception occurs!
access denied (java.util.PropertyPermission user.dir read)
Applets and JApplets are not allowed to read the user's disks. You need to
set appropriate permissions or provide appropriate security certificates.
The details of this depend upon the browser that you are using.
 
P

Paul Lutus

gajo said:
Hi, I have two questions considering Java Swing.
1) I have a button and I want to use it to stop my JApplet. I tried
applet.stop() but it didn't do a thing (no errors, nothing). How can I do
this?

You could start by posting some example code -- ashort, compilable example
of the code and its problem.
2) When I click on another button I want a JFileChooser dialog to show up
so I can open a file. I've read Sun's tutorial but their example doesn't
work either,

Their example works, your embodiment doesn't. You could try posting a short
example that shows the problem. Applets are constrained in what they can do
unless you take special precautions.
so I have the feeling it might have to do with me using J2SE
1.2 and not 1.4 the newest version. However, I cannot switch to the newest
version, so can someone help me how to solve this problem? Here's the code
I'm trying to use:

JFileChooser dijalog = new JFileChooser(); // this is where the
exception occurs!

Did you import javax.swing.* ? Is this in fact an applet? Do you know what
constraints apply to applets?

Always post a short, complete, compilable example.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top