• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet problems

 
Jamie Wool
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1073
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic