Background of my applet

I want to add a background image to my applet is it possible if it is how?
Thanks

I made my code like this
       private  java.awt.Image im;
       private java.io.File yeniresim;
        yeniresim = new java.io.File("C:\\board.gif");
        try
        im =  ImageIO.read(yeniresim);
        catch(java.io.IOException e)
         e.printStackTrace();  
        }and its giving the filepermission error but there is nothing wrong with permissions
what can be the problem
here is the problems that java give
java.security.AccessControlException: access denied (java.io.FilePermission C:\board.gif read)
        at java.security.AccessControlContext.checkPermission(AccessControlContext.java:269)
        at java.security.AccessController.checkPermission(AccessController.java:401)
        at java.lang.SecurityManager.checkPermission(SecurityManager.java:524)
        at java.lang.SecurityManager.checkRead(SecurityManager.java:863)
        at java.io.File.canRead(File.java:636)
        at javax.imageio.ImageIO.read(ImageIO.java:1262)
        at SimpleGraphGUI.init(SimpleGraphGUI.java:52)
        at sun.applet.AppletPanel.run(AppletPanel.java:353)
        at java.lang.Thread.run(Thread.java:534)

Similar Messages

  • How to create a transport background for an applet ?

    HI can any one tell me the solution for this ...
    How to create a transport background for an applet ?
    please help
    -seenu_ch

    what does it mean to have a transparent background to an applet? transparent means you can "look through" it.
    What do you want to "look thorough" an applet.
    Sorry, I am still not understanding :(
    Please let me know what this means.
    regards,
    Sangeetha

  • Add a background image to applet

    Hi. Sorry if this question has been asked to death, but i have searched for the best part of the last 2 hours for a solution to my problem which is as follows:
    I have been tying to place a background image on an applet for part of a project i have to do at uni. From what i have read this is very simple and i have tried all possiblities to get it working, all to no avail.
    The code below is what i have for this:
    import java.awt.*;
    import java.applet.*;
    public class BackImage extends Applet
    Image background;
    public void init()
    background = getImage(getCodeBase(), "Images/back.gif");
    setVisible(true);
    public void paint(Graphics g)
    g.drawImage(background, 0, 0, this);
    When using textpad to compile and run this, the command window opens and closes instantly and the applet window doesnt even open. when opening the html file in firefox, all i am greeted with is a white applet area but no error messages in the console.
    I have checked and checked again that locations for the image are correct and all seems fine, so i put it to you guys to help me if you could.
    thanks
    =============
    S.Harvey

    1. Switch from the AWT to Swing.
    2. My favorite way it to draw the image with a border. That way I can
    decorate an existing container without having to subclass it. Have fun!
    import java.awt.*;
    import java.io.*;
    import java.net.URL;
    import javax.imageio.*;
    import javax.swing.*;
    import javax.swing.border.*;
    public class BackgroundBorderExample {
        public static void main(String[] args) throws IOException {
            JFrame.setDefaultLookAndFeelDecorated(true);
            JFrame f = new JFrame("BackgroundBorderExample");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JTextArea area = new JTextArea(24,80);
            area.setForeground(Color.WHITE);
            area.setOpaque(false);
            area.read(new FileReader(new File("BackgroundBorderExample.java")), null);
            final JScrollPane sp = new JScrollPane(area);
            sp.setBackground(Color.BLACK);
            sp.getViewport().setOpaque(false);
            f.getContentPane().add(sp);
            f.setSize(600,400);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
            String url = "http://blogs.sun.com/jag/resource/JagHeadshot.jpg";
            final Border bkgrnd = new CentredBackgroundBorder(ImageIO.read(new URL(url)));
            Runnable r = new Runnable() {
                public void run() {
                    sp.setViewportBorder(bkgrnd);
                    sp.repaint();
            SwingUtilities.invokeLater(r);
    import java.awt.*;
    import java.awt.image.*;
    import javax.swing.border.*;
    public class CentredBackgroundBorder implements Border {
        private final BufferedImage image;
        public CentredBackgroundBorder(BufferedImage image) {
            this.image = image;
        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
            int x0 = x + (width-image.getWidth())/2;
            int y0 = y + (height-image.getHeight())/2;
            g. drawImage(image, x0, y0, null);
        public Insets getBorderInsets(Component c) {
            return new Insets(0,0,0,0);
        public boolean isBorderOpaque() {
            return true;
    }

  • A problem changing applet's background colour

    Hi there,
    I'm hoping somebody can help me with what I believe to be a problem I have in changing the background colour of an applet, the source code of which is posted below. If super.paint(g); is commented out, the background of the applet will be changed to whatever colour is specified, however if it is not the background will remain grey. As I understand though, super.paint(g); should be part of the program. What am I doing wrong? Should super.paint(g); in this example be part of the program?
    Before posting this I searched the forums and looked at some of the Q's & A's about changing an applet's background colour but am non the wiser.
    Thank you for your help.
    Regards,
    THE_TH1NG
    import javax.swing.*;
    import java.awt.Color;
    import java.awt.Graphics;
    public class Calculate extends JApplet
    public Calculate()
    //Variables used in our calculations.
    double sum; // Add the two numbers
    double product; // Multiply the two numbers
    double quotient; // The first number divided by the second number
    double difference; // The first number minus the second number - This may result in a negative value being returned
    double userInput1; //Stores the first number as a double after being converted from type string
    double userInput2; //Stores the second number as a double after being converted from type string
    public void init()
    String number1; // The first number to be entered by the user
    String number2; // The second number to be entered by the user
    number1 = JOptionPane.showInputDialog("Please enter the first floating point number"); // The user inputs the first number as a string
    number2 = JOptionPane.showInputDialog("Please enter the second floating point number"); // The user inputs the second number as a string
    // Convert the user's input from type string to type double
    userInput1 = Double.parseDouble( number1 );
    userInput2 = Double.parseDouble( number2 );
    // Perform the calculations
    sum = (userInput1 + userInput2);
    product = (userInput1 * userInput2);
    difference = (userInput1 - userInput2);
    quotient = (userInput1 / userInput2);
    public void paint( Graphics g )
    //The applets background will be set to the desired colour if super.paint(g) is commented out
    //But the background will remain grey if the code is not commented out.
    //What am I doing wrong?
    //super.paint( g );
    setBackground(new Color(50,150,255)); //Light Blue
    g.drawRect(10,10,250,100); // Draw a rectangle 250 pixels wide X 100 pixels high to enclose the rest of the program's output
    //Dispaly the results of the calculations to the user
    g.drawString( "The numbers entered are " + userInput1 + ", " + userInput2, 25, 25);
    g.drawString( "The sum is " + sum, 25, 40);
    g.drawString( "The product is " + product, 25, 55);
    g.drawString( "The difference is " + difference, 25, 70);
    g.drawString( "The quotient is " + quotient, 25, 85);

    You could try defining
    public void update(Graphics g) {
        paint(g);
    }That's the only difference I see between your code and my applet code. If that isn't it, you could try getContentPane().setBackground(...) but I don't know how that could make much difference (I would think that the content pane is transparent...)
    Another possibility is that, if you're using Swing, you probably shouldn't be overriding paint() and should stick to the paintComponent() method or whatever is appropriate.

  • Gray applet background

    This question as been posted numerous times, but noone one has provided a solution that works.
    It has to do with getting rid of the infamous gray background when initially loading an applet.
    the setbackground() function only changes the background after the applet has loaded. I know that this can be done because I have seen applets that show a different color other than gray.
    Any ideas anyone?

    weel, not very sure but :
    1. as applet is not already loaded, it is normal that setBackground doesnot do anything.
    2. are u sure that is not a functionnality of the current browser/jvm used?
    3. how about dealing with DIV (put a DIV on foreground with some img bg while applet s not loaded then hide this DIV)?
    what do u think about this?

  • Change applet background color with a button

    Does anyone know how to change the background of an applet by clicking a button within the applet? Thanks.

    Add an ActionListener to the button which calls the setBackground method.

  • Applet's background color?

    Can I set new background color for applet?Gray is so boring.
    I maybe saw this somewhere,but I can't remeber where. :/
    Thanks for help.

    import java.awt.*;
    setBackground(Color.BLUE);
    -or-
    setBackground(java.awt.Color.BLUE);
    -or, if not blue, then -
    setBackground(new java.awt.Color(int R, int G, int B);
    ... check out java.awt.Color on the API docs

  • Adding image to JDialog in Applet

    Well.. I've decided to make my Applet load via a JDialog. Which I know is possible :). And to a start I'll make a very simple Applet in the JDialog, including a background picture, which I just can't add! So to make a long story short, I want an image in my JDialog, but my code gives me a nullPointerException during the Runtime.. Here's the exact Runtime error:
    Exception in thread "main" java.lang.NullPointerException
            at applet.<init>(applet.java:16)
            at applet.main(applet.java:100)And here's my exact applet.java file:
    import java.applet.*;
    import java.io.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.imageio.*;
    import javax.swing.plaf.metal.*;
    public class applet extends Applet implements Runnable
        private ImagePanel panel;   
    public applet()
         panel.createGUI();
        public void init()
        public void run()
    public void start()
         Thread thread = new Thread(this);
         thread.start();
    public void stop()
    public void destroy()
    public void paint(Graphics g)
    private class ImagePanel extends JPanel
        BufferedImage buffered = null;
        public ImagePanel(String name)
            try
                buffered = ImageIO.read(new File(name));
                setPreferredSize(new Dimension(buffered.getWidth(), buffered.getHeight()));
            } catch(IOException ioe)
                ioe.printStackTrace();
        public void paintComponent(Graphics g)
            if (buffered == null)
                g.drawString("No Image", 10, 40);
            else
                g.drawImage(buffered, 0, 0, null);
        public void createGUI()
         MetalLookAndFeel.setCurrentTheme(new BlackTheme());
            JFrame.setDefaultLookAndFeelDecorated(true);
            JDialog.setDefaultLookAndFeelDecorated(true);
            JPopupMenu.setDefaultLightWeightPopupEnabled(false);
         JDialog dialog = new JDialog();
      dialog.setTitle("Applet loading via. JDialog");
      Container container = dialog.getContentPane();
      ImagePanel panel = new ImagePanel("background.gif");
      dialog.pack();
      dialog.setSize(1000, 1000);
      dialog.setVisible(true);
      dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        public static void main(String[] args)
         applet app = new applet();
    }And I don't see any errors, but still.. Runtime error.. -.-' So a little bit of help would really be appretaiced!

    Okay I guess I spoke to soon.. :O Now I have no Runtime error but my JDialog is completly empty.. And my BlackTheme stopped working.. Not It's a blue theme instead..
    Here take a look at my applet.java:
    import java.applet.*;
    import java.io.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.imageio.*;
    import javax.swing.plaf.metal.*;
    public class applet extends Applet implements Runnable
        ImagePanel panel = new ImagePanel("background.gif");  
    public applet()
         panel.createGUI();
        public void init()
        public void run()
    public void start()
         Thread thread = new Thread(this);
         thread.start();
    public void stop()
    public void destroy()
    public void paint(Graphics g)
    private class ImagePanel extends JPanel
        BufferedImage buffered = null;
        public ImagePanel(String s)
            try
                buffered = ImageIO.read(new File(s));
                setPreferredSize(new Dimension(buffered.getWidth(), buffered.getHeight()));
            } catch(IOException ioe)
                ioe.printStackTrace();
        public void paintComponent(Graphics g)
            if(buffered == null)
                System.out.println("No image to display.");
            else
                g.drawImage(buffered, 0, 0, null);
        public void createGUI()
            MetalLookAndFeel.setCurrentTheme(new BlackTheme());
            JFrame.setDefaultLookAndFeelDecorated(true);
            JDialog.setDefaultLookAndFeelDecorated(true);
            JPopupMenu.setDefaultLightWeightPopupEnabled(false);
         JDialog dialog = new JDialog();
      dialog.setTitle("Applet loading via. JDialog");
      Container container = dialog.getContentPane();
      ImagePanel panel = new ImagePanel("background.gif");
      dialog.pack();
      dialog.setSize(1000, 1000);
      dialog.setVisible(true);
      dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        public static void main(String[] args)
         applet app = new applet();
    }

  • Applet isn't loading up in Internet Explorer.

    I have an applet which I wish to run in a webpage.
    I use the appletviewer for viewing my applet but the problem is when I try to run it through the internet explorer 5.0.
    Could anybody help me?
    Here's the code for my program...
    import java.awt.*;          
    import java.applet.Applet;     
    public class ComponentLabel extends Applet{
    Label lblhello;     
         public void init(){
    lblhello=new Label("Hello");
         add(lblhello);
    Here's the code for the HTML page that I've made for viewing the program.
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body bgcolor="#FFFFFF" text="#000000" background="bbg.jpg">
    <applet code="ComponentLabel.class" width="994" height="67">
    </applet>
    </body>
    </html>
    It says a ComponentLabel.class not loaded... is it something about the path or do I need a constructor or something?

    I had the same problem with the latest version of Internet Explorer (v6.0) that I downloaded from Microsoft yesterday.
    Compiling with javac -target 1.1 solved the problem a class that extends Applet. However, this does not seem to work for a class that extends JApplet. (I understand that JApplet is needed for Swing components to work correctly.) Is there any way to get Internet Explorer (v6.0) to work with Swing components and/or JApplet ?
    Thanx.

  • Back ground colour of applets?

    Can i change the colour of the background of my Applets, right now there r a really boaring gray colour,
    any info would be great
    thanxs
    Anthony

    Two ways:
    Predefined colors:
    pink
    red
    green
    blue
    darkGray
    lightGray
    gray
    orange
    to set a the color of your background, put this in init{
    setBackground(Color.red) //or any predefined colors
    Custom Colors:
    define in three ints the RGB color values of your color. The numbers have to be between 0 - 255
    //put this with variable declarations
    int red = 100;
    int blue = 5;
    int green = 7;
    Color myColor = new Color(red, blue, green);
    //put this in init
    setBackground(myColor);
    Please give me the dukes

  • Applets and Inheritance

    I'm pretty miffed.
    I'm asking someone already about the problem with my applet.
    I.E. keeps telling me that my applet can't be instantiated, but my applet works fine with appletviewer, what gives?
    My program ListApplet has a class that is made by me called MyList which inherits from the List class. I'm trying to practice inheritance since I might use it later on.
    I placed both my applets in a .jar file as suggested, and I've compiled my applet as a 1.1. Could I make sure that indeed my applet was compiled using 1.1?
    I really have to implement inheritance by the way. I feel that sidestepping this obstacle would be counterproductive.
    Thanks.
    Here's the listing for ListApplet.java(There are 3 separate files)
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.Applet;
    public class ListApplet extends Applet implements ItemListener{
    MyList lstsample=new MyList();
    Label lblsample=new Label();
    public void init(){
    setLayout(new GridLayout(2,1));
    lstsample.addItemListener(this);
    add(lstsample);
    add(lblsample);
    public void itemStateChanged(ItemEvent ie){
    if(ie.getSource()==lstsample){
    lblsample.setText("You have chosen"+ lstsample.getSelectedItem());
    MyList.java listing
    import java.awt.*;
    public class MyList extends List{
         String[] str={"Migs", "Myles", "Jet", "Lans", "Tins", "Liz"};
         MyList(){
              for(int j=0;j<str.length;j++){
                   this.add(str[j]);
    listapplet.htm listing
    <html>
    <head>
    <title>List Applet</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body bgcolor="#FFFFFF" text="#000000" background="bbg.jpg">
    <applet code="ListApplet.class" archive="MyJar.jar" codebase="." width="994" height="67">
    </applet>
    </body>
    </html>

    You wrote public class MyList extends List , but java.util.List is not a class but an interface. I suggest that you extend your class MyList from one of the classes which implement the interface java.util.List . You should also import java.util.*;

  • Java Applet won't load when a JavaScript variable "this.Document" is used.

    Hi,
    Creating a "this.Document" variable within JavaScript interferes with some versions of Java. So far it breaks on the following versions, using IE7 on Windows XP:
    * JRE 6.0 Update 7
    * JRE 6.0 Update 6
    * JRE 6.0 Update 5
    * JRE 6.0 Update 4
    [Due to time constraints JRE 6.0 to JRE 6.0 Update 3 were not tested]
    * JRE 5.0 Update 22
    [Due to time constraints JRE 5.0 Update 16 to JRE 5.0 Update 21 were not tested]
    * JRE 5.0 Update 15
    [Due to time constraints JRE 5.0 Update 1 to JRE 5.0 Update 14 were not tested]
    * JRE 5.0
    The following HTML demonstrates this problem when you have any of the above versions of Java installed:
    <html>
        <head>
            <title>Java Bug</title>
            <script type="text/javascript" language="javascript">
                this.Document = 'string'; // Remove this line to get it to work again
            </script>
        </head>
        <body style="background-color:black">
            <applet id="testVM" alt="Something is wrong. Java is not working."
                codebase="http://www.java.com/applet" code="testJava2_1/TestVMApplet"
                archive="TestVM2-test.jar" width="500" height="280">
                <param name="locale" value="en" />   
                <param name="titleSize" value="22" />
                <param name="subtitleSize" value="18" />   
            </applet>
        </body>
    </html>The page only displays a white box where the Java Applet should be. If you then remove the "this.Document" variable or simply rename it to something else then the applet loads without problems. Normally I would just use a different variable name but the variable name is placed within the Mootools JavaScript Framework and is not easily changed without forking my own project.
    Does anyone know why this happens and if it can be fixed without having to update to the latest version of Java?
    Thanks

    EJP wrote:
    'this.document' is a predefined variable that defines the URL source of the current page. If you are referring to the predefined variable that provides access to the Document Object Model then I believe you are mistaken, that is 'window.document' or just 'document'.
    EJP wrote:
    Your name either conflicts with that or is getting confused with it somewhere.The 'document' variable is a parent of the window object e.g. 'window.document' but my variable has the context of 'this'. That means 'this.document.URL' returns 'undefined' instead of the URL for the current page.
    JavaScript is also case sensitive so 'document.URL' is not the same as 'Document.URL', the last of which returns 'undefined'.
    If Java relealy was confusing my variable with the predfined one then I would expect the same behaviour if I were to use differnt variations of the variable. However the follwoing JavaScript doesnt affect the Applet in anyway:
    <script type="text/javascript" language="javascript">
        //this.Document = 'string'; // Remove this line to get it to work again
        this.document = 'string';
        document = 'string';
        Document = 'string';            
    </script>For some strange reason it only affects the Applet when 'this.Document' is used. Why would Java be affected in this way in the first instance? Even setting the 'scriptable' parameter to false doesn’t help:
    <param name="scriptable" value="false">Are there any other settings I am not aware of that could maybe prevent Java from loooking at the JavaScript?
    EJP wrote:
    Use another name.As I mentioned in my original post this is not easily done, I can edit the source code on my own site but the code still remains unchanged on the Mootools JavaScript Framework website.
    Thanks

  • IE says that my applet can't be instantiated

    Okay, the applet I've made can be viewed by the appletviewer whereas IE says it can't be instantiated. Is there a problem with regards to inheritance? I've tried using javac -target 1.1 to compile the code and it still didn't work. It does work for my other applets.
    I'm posting the codes for the html and the two files I've made.
    listapplet.html<html>
    <head>
    <title>List Applet</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body bgcolor="#FFFFFF" text="#000000" background="bbg.jpg">
    <applet code="ListApplet.class" width="994" height="67">
    </applet>
    </body>
    </html>
    ListApplet.java
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.Applet;
    public class ListApplet extends Applet implements ItemListener{
    MyList lstsample=new MyList();
    Label lblsample=new Label();
    public void init(){
    setLayout(new GridLayout(2,1));
    lstsample.addItemListener(this);
    add(lstsample);
    add(lblsample);
    public void itemStateChanged(ItemEvent ie){
    if(ie.getSource()==lstsample){
    lblsample.setText("You have chosen"+ lstsample.getSelectedItem());
    MyList.java
    import java.awt.*;
    public class MyList extends List{
         String[] str={"Migs", "Myles", "Jet", "Lans", "Tins", "Liz"};
         MyList(){
              for(int i=0;i<str.length;i++){
                   this.add(str);

    Errmmm... errors?
    How could it have errors when it runs perfectly well with appletviewer? I used the modification you suggested and it did run using appletviewer.
    Better yet, it can be compiled by java. I don't think there are errors, really since that kind of error you stated I feel should be found by the Java compiler, that's where I usually encounter such errors.
    I'm not really sure if it's how I compiled it(Since somebody told me to compile it using javac -target 1.1 ArchiveName.java and it worked on my other projects that don't have inheritance and uses other classes) I really don't have an idea if it was compiled using 1.1 JVM since I only mostly know the principles of Java and not exactly the more advanced parts.
    Besides MyList.java:9 reads like this               
    this.add(str);
    the value i indicates an integer.
    So it's not a String array rather a String object. Maybe something wrong with my post?

  • Using Background Save in IDM

    My account in IDM is set up so that I don't need any approvals to edit or add users. When I edit a user and add resources to the user and click 'SAVE' on the forms, it works fine, but when I click 'SAVE IN BACKGROUND' it says that it is awaiting approval. How do I get the save in background feature to work properly?
    Thanks,
    Jody

    Did you look at the Task after you save in background? The applet which displays the workflow status is a bit confusing when you save in background. It stops at the moment the workflow is saved and doesn't progress any further down the diagram because it is paused until the Scheduler can pick it up and finish it in background.
    It may have actually completed as expected. Go to the Tasks page and search for it.
    Jason

  • Error when update from 10g (9.0.4) to 10g(10.1.2.0.2)

    hi
    I developed forms using Oracle Developer Suite 10g (9.0.4) and it is work correctly
    then I install Oracle Developer Suite 10g(10.1.2.0.2) and I compile it their is no error
    when I run it the browser a bear as gray screen and in the states bar write applet started and their is nothing a bear after that

    You are welcome,
    Therefore, check in formsweb.cfg parameter
    # Forms applet parameter
    width=1
    # Forms applet parameter
    height=1
    SeperateFrame=True
    I had set to 1
    When using SeperateFrame=True (in formsweb.cfg) a black area is shown in the
    browser where normally the forms-applet resides and the forms will be opened as
    an seperate applet window
    In this case background of the applet will be reduced
    Setting width and height during runtime
    =======================================
    In this case where "SeperateFrame=True" ,it's possible to specify the
    exact size using the following command:
    SET_WINDOW_PROPERTY('window_name', WINDOW_SIZE, <width>, <height>);
    or
    This is mine and work
    SET_WINDOW_PROPERTY(FORMS_MDI_WINDOW, WINDOW_STATE, MAXIMIZE);
    Regards

Maybe you are looking for

  • Problems with Elements 7

    Hello, I have Windows Vista Home Premium on my laptop and I'm using Windows 8.  I've been using my Elements 7 since 2009.  I've been having problems with it - today I was trying to put some textures (layers) on one of my images and wasn't able to. Th

  • JSP vs Crystal Report Export to PDF problem

    I have problem using JSP and Crystal Report 10. When I exporting report to PDF my font become ?????? (Only thai font but En font is work fine) This mean when deploy report on J2EE (I used tomcat 5.0.27) It not support other language or I must use oth

  • Document user status not changed from follow-up document

    Hi gurus! My task is to set new user status of primary document (service order) from follow-up document (task) after follow-up document is created. To do this I've created Badi-impl. of ORDER_SAVE Badi and in PREPARE method when saving newly created

  • My photo want sync and my you tube doesn't work after update and my battery drains fast.

    this new update doesn't work like i should work my photo doesn't upload my you tube doesn't work & my battery drain faster than ever now

  • Itunes Store error 414

    Hi All, When I try to update all my applications in itunes, I receive an unable to process request, unknown error 414. I've updated all my billing info(including security code). Any ideas on why this is happening? Thanks in advance.