aspose file tools*
The moose likes Java in General and the fly likes Applet problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Applet problems" Watch "Applet problems" New topic
Author

Applet problems

Jamie Wool
Ranch Hand

Joined: May 03, 2004
Posts: 49
I'm in the middle of creating my first applet, but it's doing some strange things. Ihaving problems mainly with the painting not quite working and the panels aren't working properly

Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1007
    
    3
I didn't go through your code with the proverbial fine toothed comb, but...

I notice that you're adding components to the content pane with BorderLayout position constants, but you set the layout manager to a new FlowLayout.

Also you should set the layout first and then start adding components.

Ryan
Jamie Wool
Ranch Hand

Joined: May 03, 2004
Posts: 49
Ok, been through the code and sorted that out, thx. But how do i control the painting as it seems to altenate between painting the buttons and the image??
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Using the paint method in an Applet or JApplet is tricky because it will draw on top of everything, including your components (see api). An easier way to get started is to use a separate image component as the content pane, set its layout and add the components to it. The image will be in the background. In Swing ('J' prefix on the components) we usually do not need to override the update method though it is common to do so for different uses in the AWT. Loading images inside an applet that has a main method is also tricky: you need an applet method, which you have above, for applet context and an application method, as in Toolkit with MediaTracker or ImageIcon, for the application context. You can avoid this with an inner or outer class that loads its own image (or with the newer ImageIO class - j2se 1.4).
Jamie Wool
Ranch Hand

Joined: May 03, 2004
Posts: 49
Thanks for that, but that seems to have brought on securtiy exceptions when loading the applet.


java.security.AccessControlException: access denied (java.io.FilePermission images/skin1.gif read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(Unknown Source)
at sun.awt.SunToolkit.getImageFromHash(Unknown Source)
at sun.awt.SunToolkit.getImage(Unknown Source)
at javax.swing.ImageIcon.<init>(Unknown Source)
at javax.swing.ImageIcon.<init>(Unknown Source)
at AnImageComponent.<init>(JF1.java:42)
at JF1.init(JF1.java:15)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Jamie Wool
Ranch Hand

Joined: May 03, 2004
Posts: 49
Ok, i've figurd out the permissions problem, but still having problems with the code. With your example i no longer get the applet pop-up in a frame and it doesn't seem to add the background or the burttons?
Jamie Wool
Ranch Hand

Joined: May 03, 2004
Posts: 49
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
The code in your last post runs okay in j2se 1.5. You might try another image file. The JFrame was meant to be a pop-up? I suggest you consider using a JOptionPane or JDialog for a pop-up container. You can launch it in your event code, say in the ActionListener of a JButton. If it must be launched during construction, ie, in init, I would opt for a JOptionPane.
 
Consider Paul's rocket mass heater.
 
subject: Applet problems