Results 1 to 5 of 5
Thread: Applet Icon
- 09-22-2008, 10:46 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 5
- Rep Power
- 0
Applet Icon
Here is a simple class to just highlight the use of Frame Object. I am however at the same time interested in getting an image icon, or title icon or applet icon, what ever is the proper name. I thought of using the setIconImage method but on checking it, I realized that an image object is required. This is where I got stomped as the image class has all sort of methods and apparently all kinds of other methods have to be used. I am hoping this is not the case. The image I intend to use is in the .ico format and is placed in the same folder as the class I am using. Here is the code thus far that works.
I have highlighted my attempt to put the icon image in the frame. This is a very simple class that simply hides and shows a frame based on the click of a button.Java Code://FrameDemo //Demonstrates a very simple frame //Danon Knox, 05/00 import java.awt.*; import java.applet.*; import java.awt.event.*; public class FrameDemo extends Applet implements ActionListener { Frame frmHello = new Frame("Hello There!"); Button btnShowFrame = new Button("Show Frame"); Button btnHideFrame = new Button("Hide Frame"); [COLOR="Red"] //this is where i failed to instantiate the image object //Image favicon = getIconImage("favicon.ico");[/COLOR] public void init() { add(btnShowFrame); add(btnHideFrame); btnShowFrame.addActionListener(this); btnHideFrame.addActionListener(this); frmHello.setFont(new Font("SansSerif", Font.BOLD, 30)); frmHello.add(new Label("Hello there!"), BorderLayout.CENTER); [COLOR="red"]// this was my failed attempt //frmHello.setIconImage(favicon);[/COLOR] }//end init public void actionPerformed(ActionEvent e) { if(e.getSource() == btnShowFrame) { frmHello.setVisible(true); frmHello.setSize(100,100); frmHello.pack(); } else { frmHello.setVisible(false); frmHello.dispose(); } } }
- 09-23-2008, 04:18 AM #2
Member
- Join Date
- Sep 2008
- Posts
- 5
- Rep Power
- 0
New Problem
I have addressed some issues in the previous code. I will highlight the code of importance.
Before
AfterJava Code://this is where i failed to instantiate the image object Image favicon = getIconImage("favicon.ico"); . . . // this was my failed attempt frmHello.setIconImage(favicon);
Now when run the applet with these adjustments I get the following error:Java Code://this is where i failed to instantiate the image object Image favicon = Toolkit.getDefaultToolkit().getImage("favicon.gif"); . . . // this was my failed attempt frmHello.setIconImage(favicon);
What do I do?Java Code:java.security.AccessControlException: access denied (java.io.FilePermission favicon.gif read)
- 09-23-2008, 01:45 PM #3
Applets are NOT allowed to read files from the local disk. The code should be written to get the image from the Applet's codebase. There is sample code on the forum showing how to do that.
Or you can give the applet permission by changing the .java.policy file or signing the applet. Again there are examples on the forum on how to do that.
- 04-30-2009, 03:48 AM #4
Member
- Join Date
- Jan 2009
- Posts
- 6
- Rep Power
- 0
- 04-30-2009, 04:05 AM #5
getResourceAsStream() - it's in most Applet threads
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
Similar Threads
-
Yes No Icon MessageBox in SWT
By Java Tip in forum SWTReplies: 0Last Post: 07-02-2008, 07:57 PM -
Example of an icon that changes form
By Java Tip in forum java.awtReplies: 0Last Post: 06-23-2008, 11:18 PM -
icon
By amith in forum AWT / SwingReplies: 1Last Post: 05-16-2008, 07:34 PM -
How to set an Icon in a Label?
By Soda in forum New To JavaReplies: 2Last Post: 12-07-2007, 12:38 PM -
To add an icon to my project
By Albert in forum AWT / SwingReplies: 1Last Post: 07-13-2007, 03:14 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks