Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / September 2005

Tip: Looking for answers? Try searching our database.

panel question..

Thread view: 
Frances - 23 Aug 2005 23:17 GMT
can u set a border, set background color, etc.. to panels?  (or can you
only do this to JPanels?)

I have to do this applet and have a somewhat tight dealine..  am torn
betw. doing it in just AWT or SWING, since don't know SWING very well..

(is only diff. that you need to extend JApplet instead of Applet and do
init() instead of main method?)

thank you..

Frances
Andrew Thompson - 24 Aug 2005 06:45 GMT
> can u set a border, set background color, etc.. to panels?  (or can you
> only do this to JPanels?)
>
> I have to do this applet and have a somewhat tight dealine..  am torn
> betw. doing it in just AWT or SWING, since don't know SWING very well..

Use AWT.

> (is only diff. that you need to extend JApplet instead of Applet and do
> init() instead of main method?)

No.

Further, while an Applet might be 1.1 compatible,
JApplets inherently require Java 1.2+.

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"..and now you do what they want ya', ..now you're under control"
Rage Against the Machine 'Killing In The Name'

Frances - 24 Aug 2005 14:45 GMT
>>can u set a border, set background color, etc.. to panels?  (or can you
>>only do this to JPanels?)
[quoted text clipped - 11 lines]
> Further, while an Applet might be 1.1 compatible,
> JApplets inherently require Java 1.2+.

here's a neat new interface...
http://www.google.com/talk/index.html

I wonder if you can do windows w/rounded corners like this w/SWING..

(it don't mean a thing, if it ain't got that SWING....:)
Andrew Thompson - 24 Aug 2005 17:02 GMT
>>>can u set a border, set background color, etc.. to panels?  (or can you
>>>only do this to JPanels?)
>>>
>>>I have to do this applet and have a somewhat tight dealine..  

It might take a while to convert over AWT experience to
Swing.  There are a number of 'gotchas', and the extra
components that Swing offers also take some time to get
the hang of.

If the deadline is short, leave 'learning Swing' for
another time, and stick with what you know.

As it is, it sounds like you are inexperienced with
Applets, and that is already a huge hurdle to tackle
for this project.  Adding the learning of Swing to
that could well be disastrous.

>>> am torn
>>>betw. doing it in just AWT or SWING, since don't know SWING very well..
>>
>> Use AWT.
..
>> Further, while an Applet might be 1.1 compatible,
>> JApplets inherently require Java 1.2+.
>
> here's a neat new interface...
...
> I wonder if you can do windows w/rounded corners like this w/SWING..

Are you afraid your users will cut themselves
on sharp corners?

> (it don't mean a thing, if it ain't got that SWING....:)

Sure.. but are you keeping the rhythm, giving it
everything you got?  ;-)

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"It makes no difference if it's sweet or hot, just keep that rhythm, give
it everything you got."
Brian Setzer Orchestra 'It Don't Mean A Thing, If It Ain't Got That Swing'

Frances - 24 Aug 2005 20:38 GMT
>>>>can u set a border, set background color, etc.. to panels?  (or can you
>>>>only do this to JPanels?)
[quoted text clipped - 37 lines]
> Sure.. but are you keeping the rhythm, giving it
> everything you got?  ;-)

Andrew, what would I do without your sense of humor to cut thru my
frustrations....;)

yes, you're right, I don't know much about applets, but I'm learning as
I'm working thru this assignment I've been given at work and I'm an
aspiring programmer and I have this job now (where I have been for over
a year now) that is a great opportunity for me to learn everything I
want to learn and they assigned this project to me knowing exactly what
my skills are, and they do expect me to learn here as I go along..
this is the situation..  :)

right now dealing with security-issues w/applet..  is biggest
frustration of all (even though we signed applet it still won't connect
to server (but I can connect fine to server w/a jsp..)

thank you for your response.....;)
Andrew Thompson - 25 Aug 2005 07:36 GMT
> right now dealing with security-issues w/applet..

A signed applet as well (shakes head sadly) you really have
your work cut out for you.
<http://www.physci.org/codes/javafaq.jsp#security>

I suggest you develop this as a combined application/applet.
That will make devlopment much faster.

Ask your managers why they specifically want an applet.

A JWS application can be launched straight from a web-page
that has few of the quirks associated with applets.

(Oh, and yes - postpone learning Swing and do this as AWT.
Tell your managers they have bitten off more than you can chew.)

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"Everybody's groovin' to their own song."
Josh Abrahams/Amiel Daemion 'Addicted to Bass'

Frances - 25 Aug 2005 14:02 GMT
>>right now dealing with security-issues w/applet..
>
[quoted text clipped - 12 lines]
> (Oh, and yes - postpone learning Swing and do this as AWT.
> Tell your managers they have bitten off more than you can chew.)

Andrew..  you do underestimate don't you..??  ok, will try to forget
that..  we HAVE signed applet, but applet STILL won't connect..  a
developer here told me I had to put some code from here in applet
http://java.sun.com/j2se/1.5.0/docs/api/java/security/AccessController.html

but I can't even find out if this is right or not, b/c, even though I'm
importing java.net.* (and java.security.*), I get a can't-find-symbol
error on var 'perm' here...

SocketPermission perm = new SocketPermission("<server:port>", "connect");
    AccessController.checkPermission(perm);

(I do have right code to connect to server, can connect fine w/a jsp,
which I did the other day just for testing purposes..)

and, yes, it has to be an applet.. (I don't need to ask why, I know
exactly why, and yes, we do need an applet..)
Andrew Thompson - 25 Aug 2005 14:07 GMT
> (I don't need to ask why, I know exactly why, ..

I don't know why, which is why I asked.

>..and yes, we do need an applet..)

..convince me.

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"Any minute now, I'm expectin' all hell to break loose.."
Bob Dylan 'Things Have Changed'

Frances - 25 Aug 2005 14:22 GMT
>>(I don't need to ask why, I know exactly why, ..
>
[quoted text clipped - 3 lines]
>
> ..convince me.

Andrew..  this will be incorporated into a large web app we're running,
it has to run on a browser...  (don't ask me for a url, only clients
have access...)

(after this project is over I hope to be forever immunized against
applet-induced stress.....;)
Dag Sunde - 25 Aug 2005 15:19 GMT
>>>(I don't need to ask why, I know exactly why, ..
>>
[quoted text clipped - 10 lines]
> (after this project is over I hope to be forever immunized against
> applet-induced stress.....;)

Can you post some code that refuse to connect to the server?
And preferably give some context. AFAIK there should be no need
for signing an applet if you only connect to the same base url
as the applet came from.

I have done quite a bit of work in this area, so I might be
able to help you if you give me more to work with...

Signature

Dag.

Frances - 25 Aug 2005 15:40 GMT
>>>>(I don't need to ask why, I know exactly why, ..
>>>
[quoted text clipped - 18 lines]
> I have done quite a bit of work in this area, so I might be
> able to help you if you give me more to work with...

THANK YOU VERY MUCH...  let's see..  applet WILL be connecting to a
server DIFFERENT from where it's coming from, so unfortunately yes, need
to sign it and all that, BUT: it's been signed already...  now am trying
to deal w/this with stuff from AccessController class..  such as..

            try {
     SocketPermission perm = new SocketPermission("jabber.org:5222",
"connect");
    AccessController.checkPermission(perm);
 }  catch(AccessControlException AControllerE) {
    System.out.println("Exception Caught: " + AControllerE.getMessage() + "
[AccessController] " + AControllerE);
        }
      }

evidently don't have permission,

Exception Caught: access denied (java.net.SocketPermission
jabber.org:5222 connect,resolve) [AccessController]
java.security.AccessControlException: access denied
(java.net.SocketPermission jabber.org:5222 connect,resolve)
Exception in thread "Thread-5" java.lang.NullPointerException

so need to figure out what to do.. am just now reading up on the methods
for AccessController class...

again, thank you very much.........  Frances
Dag Sunde - 25 Aug 2005 17:00 GMT
<snipped/>

>> Can you post some code that refuse to connect to the server?
>> And preferably give some context. AFAIK there should be no need
[quoted text clipped - 25 lines]
> access denied (java.net.SocketPermission jabber.org:5222 connect,resolve)
> Exception in thread "Thread-5" java.lang.NullPointerException

What does your  ${java.home}/lib/security/java.policy
and ${user.home}/.java.policy files contain?

Is there anything there overriding?

Signature

Dag.

Frances - 25 Aug 2005 17:21 GMT
> <snipped/>
>
[quoted text clipped - 32 lines]
>
> Is there anything there overriding?

in C:\java\jre\lib\security are the following files:

   -- local_policy.jar
   -- US_expoert_policy.jar
   -- cacerts
   -- java.policy
   -- javaws.policy
   -- java.security

(I can't open java.policy)
(JRE is 1.5)

thank you very much for yr help...

Frances
Dag Sunde - 26 Aug 2005 00:03 GMT
>>evidently don't have permission,
>>>
[quoted text clipped - 20 lines]
> (I can't open java.policy)
> (JRE is 1.5)

Its a text-file... Use Notepad.
Frances - 26 Aug 2005 14:40 GMT
>>>evidently don't have permission,
>>>
[quoted text clipped - 22 lines]
>
> Its a text-file... Use Notepad.

ok.. thank you very much...  I did try that yesterday and it looked like
gibberish, but I just tried again and it opened fine.. it's rather long,
I have posted it here..
http://www.francesdelrio.com/java_policy.txt
(this applet will have to work for a lot of different people on their
machines, though..)

again, thank you very much for all your help..  Frances
Dag Sunde - 29 Aug 2005 13:02 GMT
>>>>evidently don't have permission,
>>>>
[quoted text clipped - 29 lines]
> (this applet will have to work for a lot of different people on their
> machines, though..)

The reason I wanted to see your policy file is that rights can be explicitly
denied there. But by default, a signed (and accepted by the user) applet
have
all rights. If not overridden in the policy file.

Your policy file looks clean (read "not edited").

This means that there is something else wrong since your signed applet,
accepted by the user, on a machine with an original policy file should
have all rights neccessary to do cross-domain access.

BUT!...

The rights are applied in the context of the complete call-chain. This means
that if you call the applets method from JavaScript in the browser,
JavaScripts
permissions will apply, even if the Applet have the rights.

One way to avoid this, is to have Javascript call a method in the applet
that
just sets a flag 'callCrossDomain'. Then, in your applet, have a thread that
loops, just checking for this flag. When set, execute the cross-domain call
and reset the flag.

In this scenario the cross-domain call is not initiated by javascript, and
only the applets permissions apply...

Signature

Dag.

Frances - 29 Aug 2005 16:04 GMT
>>>>>evidently don't have permission,
>>>>>
[quoted text clipped - 56 lines]
> In this scenario the cross-domain call is not initiated by javascript, and
> only the applets permissions apply...

  Dag, I will digest everything you said..  thank you very much for
your help..
Dag Sunde - 29 Aug 2005 17:30 GMT
<snipped reason='too long'/>
>> BUT!...
>>
[quoted text clipped - 18 lines]
>   Dag, I will digest everything you said..  thank you very much for your
> help..

I just tested what i theorized above, and it works excactly like that.

A signed applet with absolutely no permission-checks or security code
whatever succeeds calling the following code:

 // Get timestring from another server
 public String getTimeFromServer( String urlString ) {

   String inputLine = new String("");

   try {
     this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

     String content = new String("");

     // URL of CGI-Bin script.
     URL url = new URL(urlString);

     HttpURLConnection connection = (HttpURLConnection)
url.openConnection();
     connection.setDoInput(true);
     connection.setDoOutput(true);
     connection.setUseCaches(false);
     connection.setRequestProperty("Content-Type",
                                   "application/x-www-form-urlencoded");
     connection.setRequestMethod("POST");

     // Prepare the output stream....
     PrintWriter out = new PrintWriter(connection.getOutputStream());
     out.println(content);
     out.flush();
     out.close();

     BufferedReader in = new BufferedReader(
         new InputStreamReader(connection.getInputStream()));

     StringBuffer inputBuffer = new StringBuffer("");
     while ( (inputLine = in.readLine()) != null) {
       inputBuffer.append(inputLine);
     }
     in.close();
     inputLine = inputBuffer.toString();
     connection.disconnect();
     this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
   }

   catch (MalformedURLException eURL) {
     eURL.printStackTrace();
   }

   catch (NoRouteToHostException eURL) {
     JOptionPane.showMessageDialog(this,
                                   "Can't connect to server, please try
later!",
                                   "Communication error!",
                                   JOptionPane.ERROR_MESSAGE);

   }

   catch (IOException eURL) {
     eURL.printStackTrace();
   }

   return inputLine;

 }

but if I call this from JavaScript, I get:
   java.security.AccessControlException:
       access denied (java.net.SocketPermission machinename resolve)

Signature

Dag.

Frances - 01 Sep 2005 18:01 GMT
> <snipped reason='too long'/>
>
[quoted text clipped - 91 lines]
>     java.security.AccessControlException:
>         access denied (java.net.SocketPermission machinename resolve)

Sunde, we finally managed to connect to server..  thank you very much
for all your help, very much appreciated.. Frances
Dag Sunde - 01 Sep 2005 19:15 GMT
<snipped />
> Sunde, we finally managed to connect to server..  thank you very much for
> all your help, very much appreciated.. Frances

You never said...

Did your original code call one of the applets methods from JavaScript?

...or was it something else?

I'm just curious to what was wrong...

Signature

Dag.

Frances - 01 Sep 2005 22:35 GMT
> <snipped />
>
[quoted text clipped - 8 lines]
>
> I'm just curious to what was wrong...

it was just the way we had signed the applet..  I'm not sure yet how to
do this..  a developer helped me out in the end...  again, many thanks
for all your help...  Frances
Dag Sunde - 25 Aug 2005 17:01 GMT
<snipped/>
> THANK YOU VERY MUCH...  let's see..  applet WILL be connecting to a server
> DIFFERENT from where it's coming from, so unfortunately yes, need to sign
[quoted text clipped - 12 lines]
>
> evidently don't have permission,

You migt want to read:
http://java.sun.com/developer/technicalArticles/Security/applets/index.html

Signature

Dag.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.