Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

adding Frame to Applet

 
simcel jones
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for taking time to read this
I am trying to add a frame to an Applet
see below
import java.applet.*;
import java.awt.*;
public class BioApplet extends Applet {
public void init() {
Frame f=new Frame("f");
f.setBackground(Color.yellow);
add(f);
}
public void paint(Graphics g) {}
}
compile error code
java.lang.IllegalArgumentException: adding a window to a container
at java.awt.Container.addImpl(Container.java:336)
at java.awt.Container.add(Container.java:228)
at BioApplet.init(BioApplet.java:10)
at sun.applet.AppletPanel.run(AppletPanel.java:344)
at java.lang.Thread.run(Thread.java:484)
 
Stephanie Grasson
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simcel,
I don't think you can add a frame to an applet. A frame is its own window, with title bar, icon, etc. What was the goal here? Perhaps we can find you a better way to achieve it. Please let us know.
Stephanie
[This message has been edited by Stephanie Grasson (edited March 30, 2001).]
 
yashesh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
try to put a button that opens a frame as a new container instead of creating a frame on applet..
 
Peter Gragert
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hava a look at http://www.math.utwente.nl/~gragert/Live_Math/TaylorError.html

There is a green button (an applet) wich launches (or destroys) a frame.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simcel,
You do not need to add the frame to the applet... simply remove the call :

and replace it with the following to have your frame pop up when the applet is loaded :

As others have mentioned in this thread... it's a good idea to have some action on the users part control the opening of the frame... automatic pop up windows are annoying...
HTH,
-Nate
 
Peter Gragert
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the same feeling as Nathan about 'automatic' popup windows. ;-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic