• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

tree in frame, frame in applet

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am attempting to have a frame inside of an applet. Inside of my frame I am creating a tree structure. Why does it not see TreeDemo2 as a method of the JApplet superclass?

I am getting the following error message:
: cannot resolve symbol
Symbol : constuctor Japplet (java.lang.String)
Location: class.javax.swing.Japplet
Super(growTree);
^
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Charlotte,
A Frame (and Window) are considered top-level containers and therefore can not be added into an Applet which is not a top-level container. You can only add another applet or a panel as containers into an Applet.
Regards,
Manfred.
 
Charlotte Shearrill
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi manfred,
thank you for your comment, but i am more confused. in one of the books that i own, this small section of code works fine. it is using both applet and frame. is that not correct?

i also read in another post on this site (i am unsure of date and topic title) that it is possible as long as i create an instance of an applet and pass that instance to a frame, then something about adding it at center and setting the layout of frame as border layout. also your post on dec. 19, 2001 re: calling JFrame in Japplet. what am i misunderstanding with all of this? thanks in advance.
charlotte
 
Ranch Hand
Posts: 897
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Charlotte,
In the code you have quoted look closely:
The line
frame.getContentPane().add(applet)
Adds the applet to the frame.
You can add an applet to a frame, but not the other way round.
Have a look at Suns Java Tutorial, especially the Swing/AWT trails. They should hopefully clear things up
Hope that helps
Mark
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Charlotte,
Sorry about that I didn't look at your code. You are correctly placing the Applet into the Frame but you just described it backwards in your post.
Getting back to your original code snippet. The problem lies in all the applet methods you are calling and when you are calling them. Two points about Applets are important here:
1. Applets don't use constructors and should not even have them in the class because it just adds confusion.
2. An Applet gets kicked off by calling the init method. No constructor is ever called nor should be.
Your approach was close but the main problem is that you are calling many applet methods and when those methods are being called.
The idea is to create an Applet class and call its init method before we add it into a Frame. That is all there is to it and it will then work fine. The code below shows the changes to your original code in bold.

Regards,
Manfred.
 
Charlotte Shearrill
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi again manfred,
thank you for delving into this a little more, this is correct in what i want but i am now back to my original problem. my expandable tree is not being displayed. in the last section of the edited code the function that performs to display my tree has been commented out. the following is a vital part of this code.

how do i now get my expandable tree to be displayed and if i am still misunderstanding in a big way, where/how should my tree be displayed?
also thank you for taking a look at this mark. i think manfred pointed out my problem in that i misworded what i was doing.
thank you both,
charlotte
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Charlotte,
This is what you are setting up with your code snippet given before:
frame -> applet -> label
what does this mean? Well you have a label inside of your applet which is inside of a frame.
It sounds like you want to replace the label with some Expandable Tree. That means that you should place the stuff you are doing in the constructor into the Applet init method. Then you will be doing the following in your main method:
frame -> applet -> TreeDemo3
Regards,
Manfred.
 
Charlotte Shearrill
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi manfred,
i have taken the opportunity to put my code that use to reside in public TreeDemo3() into my public void init()

(1) since public TreeDemo3 is no longer a method, i can’t make a call to super(“TreeDemo3”) because it has no superclass? right or wrong?
(2) commenting the super(“TreeDemo3”); statement allows me to compile and run it from my command prompt fine (java TreeDemo3) with no errors. however it will not allow me to view it if i use appletviewer TreeDemo3.html at my command prompt. it gives me a java.security.AccessControlException: access denied and it references the section where i start my database stored procedure calls. i am sure that my applet is telling me that it will not allow me to create it because now my code is considered dangerous…. i don’t know exactly where my danger is. any suggestions on narrowing my search and finding danger? matinee friday….only in the movies do they go looking for danger.
thanks,
charlotte
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Charlotte,
That is the major difference between an Applet and an Application. Applets are by default serverly restricted when performing I/O.
Look at the following web site for a good explanation of how to play outside the sandbox with Applets:
http://developer.java.sun.com/developer/technicalArticles/Security/Signed/
NOTE: The super("") can only be used inside a constructor and your applet doesn't have one.
Regards,
Manfred.
 
Charlotte Shearrill
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
heah manfred…
i thought i would give you the lastest update. i got my code to work. since my applet didn’t have permission to access the sun.jdbc.odbc.JdbcOdbcDriver class, it kept bombing out when it tried to connect to my database. i had to add the following two lines of code to my java policy file located in the JAVA_HOME/jre/lib/security/ directory:
permission java.lang.RuntimePermission "accessClassInPackage.sun.jdbc.odbc";
permission java.util.PropertyPermission "file.encoding", "read";
i was then able to run my code with appletviewer FILENAME.html.
thank you so much for helping me out with this.
thanks.
charlotte
 
reply
    Bookmark Topic Watch Topic
  • New Topic