Frame protection

How can I make a frame or frames not accessible - for example, they cannot be obtained through Frame.getFrames() ?

Also, how can I protect a frame or frames from global change - for example, the following statement will change the foreground color of all labels in the application :

javax.swing.UIManager.put ("Label.foreground",java.awt.Color.RED );

Thank you

[411 byte] By [Gen.Javaa] at [2007-11-27 10:31:37]
# 1

You cannot make a frame that cannot be obtained through Frame.getFrames();

Every constructor of java.awt.Frame calls noteFrame, which adds the frame to the private aray list that getFrames reads from.

If you REALLY needed to, I guess you could try creating your own implementation of Frame by extending java.awt.Window...

jGardnera at 2007-7-28 18:10:45 > top of Java-index,Java Essentials,Java Programming...
# 2

> If you REALLY needed to, I guess you could try creating your own implementation of Frame by extending java.awt.Window...

Good suggestion, but since I never extended this class, is it too much work ?

Gen.Javaa at 2007-7-28 18:10:45 > top of Java-index,Java Essentials,Java Programming...
# 3

Oh ... "java.awt.Window" also has getWindows() which is as bad for me as getFrames(). What is left to subclass !!!

Gen.Javaa at 2007-7-28 18:10:45 > top of Java-index,Java Essentials,Java Programming...
# 4

I wouldn't suggest you do it...

If you REALLY REALLY REALLY want to, the only way that I can think of is to go to a site like docjar (http://www.docjar.com/html/api/java/awt/Window.java.html)

and basically copy and paste from that and from Frame.java.html, removing the methods you don't want.

Again, there may be an easier way, all Frame constructors (JFrame extends Frame, so even it calls super() at the least) add it to an arraylist that there is no access to.

Maybe if you could give a better description of what you are trying to accomplish, there might be an easier way to do it?

jGardnera at 2007-7-28 18:10:45 > top of Java-index,Java Essentials,Java Programming...
# 5

> Maybe if you could give a better description of what you are trying to accomplish, there might be an easier way to do it?

I am writing an application that reads and executes user classes. Those classes could contain code that do just about anything. For example, user code could use Frame.getFrames() to get and manipulate frames including my frames which the user is not supposed to. How can I protect my frames and my environment from such code.

Gen.Javaa at 2007-7-28 18:10:45 > top of Java-index,Java Essentials,Java Programming...
# 6

If you want to control what arbitrary code can do, the tool Java provides for you is java.lang.SecurityManager.

DrClapa at 2007-7-28 18:10:45 > top of Java-index,Java Essentials,Java Programming...
# 7

> If you want to control what arbitrary code can do, the tool Java provides for you is java.lang.SecurityManager.

Thank you. I have no previous experience with this class, but I will read about it now.

Gen.Javaa at 2007-7-28 18:10:45 > top of Java-index,Java Essentials,Java Programming...