Adding images in applet

Hello,
in my applet, i used 5 no of JButtons using Icon with some ".gif" file.At first ,they run well in appletviewer,But in IE,i got a security exception.After that using policy tool,i created a policy file.Then it works well in IE.But images are not displayed in button.What can i do?.This is very urgent.JButton b1=new JButton("new ImageIcon("2g.gif")");
Kindly tell your consent.
Inba Samuel.

It probably can't find the files for the images. You shouldn't need to resort to changing the policy file just to load an image.
Note that you can't access the local filesystem from an Applet (without signing it or changing the policy file). You don't need to access the local filesystem directly to load an image, though:
URL url = new URL(getDocumentBase(), "image-1.gif");
JButton button1 = new JButton(new ImageIcon(url));This will load the images from the same directory as the HTML page displaying the Applet.
Hope this helps.

Similar Messages

  • Adding Images to Applets

    I am creating a slot machine and i have
    a basic design and drawing. The only thing
    i want to do now is add an image of falling coins
    coming out of the coin slot at the botom of the slot
    machine. i need help in how to put an image in. Like i have
    the image saved on my pictures in computer but no clue at
    all how to add it into my applet. Heres the applet. Any help at
    all would be great. heres the image url of the image i want to add:
    http://perfectmove.net/media/Palm_with_coins_falling.jpg
    Applet:
    import java.awt.*;
    import java.applet.*;
    import javax.swing.*;
    public class SlotMachine extends Applet
    public void paint (Graphics page)
    page.setColor(Color.yellow);
    page.fillRect(25,50,400,400);
    page.fillArc(25,0,400,150,80,360);
    page.setColor(Color.white);
    page.fillRect(60,85,330,110);
    page.setColor(Color.black);
    page.drawLine(170,85,170,195);
    page.drawLine(280,85,280,195);
    page.drawLine(390,85,390,195);
    page.drawLine(60,85,390,85);
    page.drawLine(60,85,60,195);
    page.drawLine(60,195,390,195);
    page.fillRect(425,315,30,15);
    page.fillRect(440,155,15,160);
    page.fillRect(165,375,140,75);
    page.setColor(Color.red);
    page.fillOval(430,125,35,35);
    page.setColor(Color.cyan);
    page.drawString("Welcome to the Lucky Slots Machine",25,45);
    }Edited by: Smart_Guy_786 on Mar 24, 2008 12:49 AM

    //  <applet code="SlotMachineRx" width="500" height="700"></applet>
    import java.applet.*;
    import java.awt.*;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    public class SlotMachineRx extends Applet
        BufferedImage image;
        public void init()
            // Path for image in current directory:
            String path = "Palm_with_coins_falling.jpg";
            try
                // getResource has the ClassLoader find the
                // image. So the image must be located on
                // your classpath. Try this with the image
                // in the current directory.
                URL url = getClass().getResource(path);
                image = ImageIO.read(url);
            catch(IOException e)
                System.out.println("read error: " + e.getMessage());
        public void paint (Graphics page)
            page.setColor(Color.yellow);
            page.fillRect(25,50,400,400);
            page.fillArc(25,0,400,150,80,360);
            page.setColor(Color.white);
            page.fillRect(60,85,330,110);
            page.setColor(Color.black);
            page.drawLine(170,85,170,195);
            page.drawLine(280,85,280,195);
            page.drawLine(390,85,390,195);
            page.drawLine(60,85,390,85);
            page.drawLine(60,85,60,195);
            page.drawLine(60,195,390,195);
            page.fillRect(425,315,30,15);
            page.fillRect(440,155,15,160);
            page.fillRect(165,375,140,75);  // spout
            page.setColor(Color.red);
            page.fillOval(430,125,35,35);
            page.setColor(Color.cyan);
            page.drawString("Welcome to the Lucky Slots Machine",25,45);
            // Draw image beneath drawing.
            // Image size:  390, 538
            // Bottom of slot machine: x=25, y=450, w=400
            // Locate image origin:
            int x = 25 + (400 - 390)/2;
            int y = 450;
            page.drawImage(image, x, y, this);
    }

  • Images in applet components

    I'm developing an applet that contains a Swing GUI. The applet has a DesktopPane which contains several internal frames. These internal frames are meant to be instantiated and added on the fly depeding on user input, so all of thier setup code is contained in thier specific classes, which extend from JInternalFrame.
    The Problem is that in the frames I want to use labels and buttons with icons. I am unable to load the images into the frames. I can open an image in the applet class using the getCodeBase method to get to the file name, but I know of no way to get the code base from within the components added to the applet.
    Is there any way to load an image from a child componenet, or a way to get the codebase of the parent applet?

    That did work very wel, but now I'm left with a new problem. The class getrus the URL for the code base, and it looks the same as the original from the applet. However, when I go to create an ImageIcon using this URL, and add it to a component I get no display. No error occurs, and the applet runs fine but the image doesn't display.

  • Looking for Image Button Applet

    I'm looking for a simple image button applet (normal state, mouse-over and mouse-click) which can refer to a HTML or start a Javascript function. Can anyone help?
    Kippie

    Hi,
    This is the source code. I don't quite understand what I should do with the tokens. I hope this is allright. Thanks for your help
    Kippie.
    import java.net.URL;
    import java.awt.Color;
    import java.util.Vector;
    import java.util.Enumeration;
    import java.util.StringTokenizer;
    import java.applet.Applet;
    import java.applet.AudioClip;
    Program Name:     ImageURLButtonBar
         Author:               Paul Whitelock
         Version:          1.1
         Copyright:          (c) 1997 by Paul Whitelock and Modern Minds, Inc.
         Requires:          ImageURLButtonBar.class
                             ButtonBar.class
                             ButtonBarObserver.class (Interface definition)
                             ButtonRegion.class
                             ButtonAnimate.class
    Modifications: v1.01 (15 April 97)
                             *     Added "sticky" button behavior (controlled
                                  by applet "stick" parameter)
                             v1.03 (25 June 97)
                             *     Added applet parameter "useCodeBase". If useCodeBase
                                  is true, then image file locations will be based on the directory
                                  in which the Java class files are located. If useCodeBase is false, then
                                  the locations will be based on the HTML directory. Note that audio
                                  file locations are always based on the Java directory. The default
                                  for useCodeBase is false (use HTML directory for base).
                             *     The "stick" parameter will now accept a button number in
                                  addition to the value of "true" or "false". If a button number
                                  is specified, then that button will be "stuck" down
                                  when the button bar initializes.
                             *     Added the capability of loading multiple URLs for each button
                                  with an optional target for each URL.
                             v1.1 (25 September 97)
                             *     Added "baseBrighten" and "baseBrightenTint" parameters to control
                                  highlighting for base button bar.
                             *     Added "mouseOverBrighten" and "moBrightenTint" parameters to control
                                  highlighting for base button bar.
                             *     Added "mdBrightenTint" and "mdBrightenAll" parameters to control
                                  highlighting for base button bar. Previous versions of the applet
                                  supported "mouseDownBrighten," but only if button borders were not
                                  drawn for the button-down button bar (the "mdBrightenAll" can be set
                                  to "true" to override the this default behavior).
                             *     An "appletBGColor" parameter has been added to set the
                                  applet background color. The applet background color is
                                  sometimes visible during scrolling or during a page repaint.
         NOTE:               This source code was composed using Microsoft Visual J++
                             with tab stops of 4. Text may not be formatted correctly
                             if another editor is used.
         ******************************** PARAMETERS ********************************
              Applet Parm               ButtonBar Class Parm     Default Value
              ================== =======================     ==================
              appletBGColor
              disableBadURL                                        true
              mouseEnterAudio                                        null (audio disabled)
              mouseClickAudio                                        null (audio disabled)
              buttonDownAudio                                        null (audio disabled)
              stick                                                  false
         *     useCodeBase               base                         false (i.e., use getDocumentBase())
              orient                    barHorizontal               horizontal if applet width > height
              base                    baseBarName                    none - parameter REQUIRED
              mouseOver               mouseOverBarName          null
              mouseOver2               mouseOverBar2Name          null
              mouseDown               mouseDownBarName          null
              mouseDownOver          mouseDownOverBarName     null
              buttonsDisabled          buttonsDisabledBarName     null
              background               backgroundImageName          null
              barXPos                    barXBackgroundPos          0
              barYPos                    barYBackgroundPos          0
              buttonBorders          drawButtonBorders          ButtonBar.BORDERS_NONE
              borderColorTL          borderColorTopLeft          null (Color.white if error)
              borderColorBR          borderColorBottomRight     null (Color.gray if error)
              borderIntensity          borderIntensityPercent     50 (used only if borders)
              borderSize               buttonBorderSize          1 (used only if borders)
              downShift               downShift                    false
              downShiftAmt          downShiftAmt               buttonBorderSize
              baseBrighten          baseBrightenPct
              baseBrightenTint     baseBrightenTint
              mouseOverBrighten     mouseOverBrightenPct
              moBrightenTint          mouseOverBrightenTint
              mouseDownBrighten     mouseDownBrightenPct     
              mdBrightenTint          mouseDownBrightenTint
              mdBrightenAll          mouseDownBrightenAll
              buttonsDisabledDim     buttonsDisabledDimPct     25     (used only if no buttonsDisabled)
              grayBarBrighten          grayBarBrighten               0
              frameRate               frameRate                    150 (used only if mouseOver2)
         *     If useCodeBase is true, then all file locations are based on the Java class file
              directory (i.e., use getCodeBase()).
    public class ImageURLButtonBar extends Applet implements ButtonBarObserver {
         // Instance Variables
         ButtonBar buttonBar;
         Vector buttonURL = new Vector(10, 10);
         Vector buttonURLTarget = new Vector(10, 10);
         Vector buttonDescription = new Vector(10, 10);
         AudioClip mouseEnterAudio = null;
         AudioClip mouseClickAudio = null;
         AudioClip buttonDownAudio = null;
         // Applet Initialization
         public void init() {
              // =================================================================
              // Applet ImageURLButtonBar specific parameters
              // =================================================================
              // appletBGColor
              //          Set applet background color
              String parm = getParameter("appletBGColor");
              if (parm != null) {
                   try {     
                        setBackground(new Color(Integer.parseInt(parm, 16)));
                   catch (Exception e) {
                        reportError("appletBGColor");
              // disableBadURL
              //          If true, then any button with an invalid URL will be disabled
              parm = getParameter("disableBadURL");
              boolean disableBadURL;
              if (parm == null || !parm.equals("false")) disableBadURL = true;
              else disableBadURL = false;
              // mouseEnterAudio
              //          Sound to play each time the mouse enters any of the buttons
              parm = getParameter("mouseEnterAudio");
              if (parm != null) {
                   mouseEnterAudio = getAudioClip(getCodeBase(), parm);
                   if (mouseEnterAudio == null) reportError("Can't load " + parm);
              // mouseClickAudio
              //          Sound to play each time a mouse down click occurs in a button
              parm = getParameter("mouseClickAudio");
              if (parm != null) {
                   mouseClickAudio = getAudioClip(getCodeBase(), parm);
                   if (mouseClickAudio == null) reportError("Can't load " + parm);
              // buttonDownAudio
              //          Sound to play each time a mouse up occurs in a button (i.e, the
              //          button has be toggled through it's "down" position)
              parm = getParameter("buttonDownAudio");
              if (parm != null) {
                   buttonDownAudio = getAudioClip(getCodeBase(), parm);
                   if (buttonDownAudio == null) reportError("Can't load " + parm);
              // stickyBar
              //          If the "stick" applet parameter is "true", then buttons will stay
              //          "stuck" in the down position until another button is clicked.
              //          If the "stick" applet parameter is the number of a button in the
              //          button bar, then that button will be "stuck" down when the
              //          button bar initializes.
              int stickyBar = -1;
              parm = getParameter("stick");
              if (parm != null && !parm.toLowerCase().equals("false")) {
                   try {
                        stickyBar = Integer.parseInt(parm);
                   catch (Exception e) {
                        stickyBar = 0;
              // =================================================================
              // Class ButtonBar specific parameters
              // =================================================================
              // orient (barHorizontal)
              //          If this parameter = 'h' then the button bar is horizontal
              //          If this parameter = 'v' then the button bar is vertical
              //          If this parameter is not specified, then the button bar is
              //          horizontal if the applet width is greater than the applet height
              boolean horizontal;
              parm = getParameter("orient");
              if (parm == null) horizontal = size().width > size().height;
              else horizontal = parm.equals("h") ? true : false;
              // base     (baseBarName)
              //          The base image file for the buttons. This is the only image
              //          file that MUST be specified.
              String baseBar = getParameter("base");
              if (baseBar == null) {
                   reportError("Parameter 'base' REQUIRED!");
                   return;
              // barXPos (barXBackgroundPos)
              // barYPos (barYBackgroundPos)
              //          If a background image is specified then these to parameters
              //          represent the top-left corner location where the button bar
              //          should be placed on the background
              int barXPos = 0, barYPos = 0;
              try {
                   parm = getParameter("barXPos");
                   if (parm != null) barXPos = Integer.parseInt(parm);
                   parm = getParameter("barYPos");
                   if (parm != null) barYPos = Integer.parseInt(parm);
              catch (Exception e) {
                   reportError("barXPos or barYPos");
                   barXPos = barYPos = 0;
              // buttonBorders (drawButtonBorders)
              //          "none" = do not draw any button borders
              //          "all"     = draw borders around all button bar buttons
              //          "base"     = draw borders only around buttons on base button bar
              //          "other"     = draw borders around all button bar buttons EXCEPT base button bar buttons
              parm = getParameter("buttonBorders");
              int drawButtonBorders = ButtonBar.BORDERS_NONE;
              if (parm != null) {
                   if (parm.equals("base")) drawButtonBorders = ButtonBar.BORDERS_BASE;
                   else if (parm.equals("other")) drawButtonBorders = ButtonBar.BORDERS_OTHER;
                   else if (parm.equals("all")) drawButtonBorders = ButtonBar.BORDERS_ALL;
              // borderColorTL (borderColorTopLeft)
              // borderColorBR (borderColorBottomRight)
              //          Normally, borders are drawn around buttons by lightening or darkening
              //          the image in the border region. A specific color can be used instead
              //          for the top and left borders and/or the bottom and right borders. The
              //          value specified for either of these two parameters should be a hexadecimal
              //          number (e.g., "FF0000" for red, "888888" for medium gray, etc.).
              Color borderColorTopLeft = null;
              Color borderColorBottomRight = null;
              try {
                   parm = getParameter("borderColorTL");
                   if (parm != null) borderColorTopLeft = new Color(Integer.parseInt(parm, 16));
                   parm = getParameter("borderColorBR");
                   if (parm != null) borderColorBottomRight = new Color(Integer.parseInt(parm, 16));
              catch (Exception e) {
                   reportError("borderColorTL or borderColorBR");
                   borderColorTopLeft = Color.white;
                   borderColorBottomRight = Color.gray;
              // borderIntensity (borderIntensityPercent)
              //          If borders are drawn for buttons, and if a border color is not specified
              //          (see above), then the image in the border region will be lightened or
              //          darkened by this percentage to create the borders.
              int borderIntensityPercent = 50;
              try {
                   parm = getParameter("borderIntensity");
                   if (parm != null) borderIntensityPercent = Integer.parseInt(parm);
              catch (Exception e) {
                   reportError("borderIntensity");
                   borderIntensityPercent = 50;
              // borderSize (buttonBorderSize)
              //          The size of borders, if borders are specified.          
              int buttonBorderSize = 1;
              try {
                   parm = getParameter("borderSize");
                   if (parm != null) buttonBorderSize = Integer.parseInt(parm);
              catch (Exception e) {
                   reportError("borderSize");
              // downShift
              //          If true, then the button image is shift down and right downShiftAmt
              //          (see below) pixels when the mouse is clicked on the button.
              parm = getParameter("downShift");
              boolean downShift = (parm == null || !parm.equals("true")) ? false : true;
              // downShiftAmt
              //          If downShift is true, then the button image is shift down and right
              //          downShiftAmt (see above) pixels when the mouse is clicked on the button.
              int downShiftAmt = buttonBorderSize;
              try {
                   parm = getParameter("downShiftAmt");
                   if (parm != null) downShiftAmt = Integer.parseInt(parm);
              catch (Exception e) {
                   reportError("downShiftAmt");
              // baseBrighten (baseBrightenPct)
              //          The base bar will be lightened by this percentage
              int baseBrightenPct = 0;
              try {
                   parm = getParameter("baseBrighten");
                   if (parm != null) baseBrightenPct = Integer.parseInt(parm);
              catch (Exception e) {
                   reportError("baseBrighten");
              // mouseOverBrighten (mouseOverBrightenPct)
              //          A button will be lightened by this percentage when the mouse
              //          moves over a button.
              int mouseOverBrightenPct = 0;
              try {
                   parm = getParameter("mouseOverBrighten");
                   if (parm != null) mouseOverBrightenPct = Integer.parseInt(parm);
              catch (Exception e) {
                   reportError("mouseOverBrighten");
              // mdBrightenAll (mouseDownBrightenAll)
              //          A button will be lightened by this percentage when the mouse
              //          moves over a button.
              boolean mouseDownBrightenAll = false;
              parm = getParameter("mdBrightenAll");
              if (parm != null && parm.charAt(0) == 't') mouseDownBrightenAll = true;
              // mouseDownBrighten (mouseDownBrightenPct)
              //          A button will be lightened by this percentage when it is
              //          clicked.
              int mouseDownBrightenPct = 0;
              try {
                   parm = getParameter("mouseDownBrighten");
                   if (parm != null) mouseDownBrightenPct = Integer.parseInt(parm);
              catch (Exception e) {
                   reportError("mouseDownBrighten");
              // baseBrightenTint (mouseOverBrightenTint)
              // moBrightenTint (mouseOverBrightenTint)
              // mdBrightenTint (mouseDownBrightenTint)
              Color baseBrightenTint = null;
              Color mouseOverBrightenTint = null;
              Color mouseDownBrightenTint = null;
              try {
                   parm = getParameter("baseBrightenTint");
                   if (parm != null) baseBrightenTint = new Color(Integer.parseInt(parm, 16));
                   parm = getParameter("moBrightenTint");
                   if (parm != null) mouseOverBrightenTint = new Color(Integer.parseInt(parm, 16));
                   parm = getParameter("mdBrightenTint");
                   if (parm != null) mouseDownBrightenTint = new Color(Integer.parseInt(parm, 16));
              catch (Exception e) {
                   reportError("baseBrightenTint, moBrightenTint or mdBrightenTint");
              // buttonsDisabledDim (buttonsDisabledDimPct)
              //          If a button is disabled and if there is no buttonsDisabled image,
              //          then the button will be dimmed by this percentage.
              int buttonsDisabledDimPct = 25;
              try {
                   parm = getParameter("buttonsDisabledDim");
                   if (parm != null) buttonsDisabledDimPct = Integer.parseInt(parm);
              catch (Exception e) {
                   reportError("buttonsDisabledDim");
              // grayBarBrighten
              //          If there is no mouseOver image, then the base image will be used for
              //          the mouseOver image, and a grayscale version of the base image will
              //          be used for base button images. This parameter can be used to lighten
              //          COLORS (not grays) in the image before it is converted to grayscale.
              //          This can help if the standard conversion produces buttons that are
              //          too dark.
              int grayBarBrighten = 0;
              try {
                   parm = getParameter("grayBarBrighten");
                   if (parm != null) grayBarBrighten = Integer.parseInt(parm);
              catch (Exception e) {
                   reportError("grayBarBrighten");
              // frameRate
              //          If a mouseOver2 image is specified, then this parameter controls
              //          how quickly animation will be performed (using mouseOver and mouseOver2
              //          images) in milliseconds when the mouse is moved over a button.
              int frameRate = 150;
              try {
                   parm = getParameter("frameRate");
                   if (parm != null) frameRate = Integer.parseInt(parm);
              catch (Exception e) {
                   reportError("frameRate");
              // =================================================================
              // Instantiate the button bar
              // =================================================================
              try {
                   // Allow the use of documentBase (default) or codeBase for image file
                   // base directory.
                   URL documentBase;
                   parm = getParameter("useCodeBase");
                   if (parm == null || parm.equals("false")) documentBase = getDocumentBase();
                   else documentBase = getCodeBase();
                   // Create the button bar
                   buttonBar = new ButtonBar(
                                                 horizontal,                         /* barHorizontal */
                                                 documentBase,                         /* base */
                                                 baseBar,                              /* baseBarName */
                                                 getParameter("mouseOver"),     /* mouseOverBarName */
                                                 getParameter("mouseOver2"),     /* mouseOverBar2Name */
                                                 getParameter("mouseDown"),     /* mouseDownBarName */
                                                 getParameter("mouseDownOver"), /* mouseDownOverBarName */
                                                 getParameter("buttonsDisabled"),/* buttonsDisabledBarName */
                                                 getParameter("background"),     /* backgroundImageName */
                                                 barXPos,                              /* barXBackgroundPos */
                                                 barYPos,                              /* barYBackgroundPos */
                                                 drawButtonBorders,               /* drawButtonBorders */
                                                 borderColorTopLeft,               /* borderColorTopLeft */
                                                 borderColorBottomRight,          /* borderColorBottomRight */
                                                 borderIntensityPercent,          /* borderIntensityPercent */
                                                 buttonBorderSize,                    /* buttonBorderSize */
                                                 downShift,                         /* downShift */
                                                 downShiftAmt,                         /* downShiftAmt */
                                                 baseBrightenPct,                    /* baseBrightenPct */
                                                 baseBrightenTint,                    /* baseBrightenTint */
                                                 mouseOverBrightenPct,               /* mouseOverBrightenPct */
                                                 mouseOverBrightenTint,          /* mouseOverBrightenTint */
                                                 mouseDownBrightenAll,               /* mouseDownBrightenAll */
                                                 mouseDownBrightenPct,               /* mouseDownBrightenPct */
                                                 mouseDownBrightenTint,          /* mouseDownBrightenTint */
                                                 buttonsDisabledDimPct,          /* buttonsDisabledDimPct */
                                                 grayBarBrighten,                    /* grayBarBrighten */
                                                 frameRate                              /* frameRate */     
                   // =================================================================
                   // Add buttons to the button bar
                   // =================================================================
                   ButtonRegion buttonToAdd;
                   String buttonNbr, urlString;
                   URL urlForButton;
                   int nbr = 0;
                   int buttonStart, buttonSize;
                   // Initialize button on bar flag (used to determine if at least one button
                   // was successfully added to the button bar)
                   boolean buttonOnBar = false;
                   // This loop will be exited when no more buttons can be found in the HTML
                   while (true) {
                        // Construct the prefix for the button parameters
                        buttonNbr = "button" + ++nbr;
                        // Find the starting offset and the size of the button
                        // If null is returned as the starting offset parameter value for the
                        // button, then all buttons should have been read so the loop can
                        // be exited.
                        try {
                             parm = getParameter(buttonNbr + "Start");
                             if (parm == null) break;
                             buttonStart = Integer.parseInt(parm);
                             buttonSize = Integer.parseInt(getParameter(buttonNbr + "Size"));
                        catch (Exception e) {
                             reportError("Button" + nbr + " start or size in error or missing");
                             buttonStart = 0;
                             buttonSize = 0;
                        // Create a ButtonRegion for the button
                        // The button ID will be set to the number of the button (this will
                        // be converted to an integer later when a buttonBarEvent is received).
                        buttonToAdd = new ButtonRegion("" + nbr, buttonStart, buttonSize);
                        // If the buttons on this button bar are "sticky" buttons, then
                        // enable "sticky" behavior for this button. The button will always
                        // "pop-up" whenever another button is clicked.
                        if (stickyBar >= 0) {
                             buttonToAdd.stickyButton(true, ButtonRegion.POPUP_ALWAYS, false);
                             // If the current button number matches the value of stickyBar, then the
                             // current button should be "stuck" down for its initial state.
                             if (stickyBar == nbr) buttonToAdd.setStuck(true);
                        // Try to add the button (i.e., the ButtonRegion) to the buttonBar
                        if (buttonBar.addButton(buttonToAdd)) {
                             // Set flag to indicate that at least one button has been added
                             buttonOnBar = true;
                             // The button was successfully added, so save the button's description
                             // (which will be displayed in the status bar) and the target frame
                             // for the button URL in the appropriate Vector.
                             buttonDescription.addElement(getParameter(buttonNbr + "Desc"));
                             buttonURLTarget.addElement(getParameter(buttonNbr + "Target"));
                             // Try to create a URL for the button.
                             // If the URL is invalid, then place an error message in the
                             // buttonURLTarget Vector (this will be used to warn the user
                             // when the button is clicked). Also, if disableBadURL is true, then
                             // disable the button.
                             String theURL;
                             urlString = getParameter(buttonNbr + "URL");
                             if (urlString != null) {
                                  Enumeration urls = new StringTokenizer(urlString);
                                  while (urls.hasMoreElements()) {
                                       theURL = (String)urls.nextElement();
                                       try {
                                            urlForButton = new URL(theURL);
                                       catch (Exception e) {
                                            try {
                                                 urlForButton = new URL(getDocumentBase(), theURL);
                                            catch (Exception e2) {
                                                 reportError("Button" + nbr + " has invalid URL");
                                                 buttonURLTarget.setElementAt("Invalid URL", nbr - 1);
                                                 urlString = null;
                                                 break;
                             else {
                                  reportError("Button" + nbr + " has no URL");
                                  buttonURLTarget.setElementAt("No URL", nbr - 1);
                             buttonURL.addElement(urlString);
                   // Remove any unused elements in the Vectors
                   buttonURL.trimToSize();
                   buttonURLTarget.trimToSize();
                   buttonDescription.trimToSize();
                   // If no buttons were added, throw exception
                   if (!buttonOnBar) throw new IllegalArgumentException("No buttons on bar");
                   // Let the buttonBar know that all buttons have been defined. This is
                   // really only necessary if downShift is true, but it won't hurt calling
                   // the method in either case.
                   buttonBar.allButtonsDefined();
                   // Add the applet as an observer so that the applet will be notified
                   // when button events occur.
                   buttonBar.addButtonObserver(this);
                   // Enable the button bar now that all buttons have been defined.
                   // (the buttonBar is disabled when it is created and must be
                   // specifically enabled).
                   buttonBar.enable(true);
                   // Add the buttonBar to the applet
                   setLayout(null);
                   add(buttonBar);
              catch (Exception e) {
                   reportError("Can't create ButtonBar\n" + e);
         // buttonBarEvent
         //          This method is called by the ButtonBar whenever a button event occurs
         //          It provides the ButtonBar that the event occurred for, the button ID
         //          that the event occurred for, and the event type.
         public void buttonBarEvent(ButtonBar barID, String buttonID, int buttonEvent) {
              String description;
              // The buttonBar will send an IMAGES_READY event when all button bar images
              // have been prepared. We are not interested in this event, but only in
              // certain "action" events that occur for a button.
              if (buttonEvent != ButtonBar.IMAGES_READY) {
                   // A number in String format was assigned as the buttonID when each
                   // ButtonRegion was created. The buttonID String will now be converted
                   // back into a number that can be used as a Vector index to retrieve
                   // button specific information (i.e., URL, target frame, and description).
                   int buttonNbr = Integer.parseInt(buttonID) - 1;
                   switch (buttonEvent) {
                        // If a mouseDown event has occurred for the button, and if an
                        // AudioClip is available for this event, play the AudioClip.
                        case ButtonBar.MOUSE_CLICK:     
                             if (mouseClickAudio != null) mouseClickAudio.play();
                             break;
                        // If the mouse has been moved over a button, display the button's
                        // description in the browser's status area. If the button that the mouse
                        // is over is an active button, and if there is an AudioClip available
                        // for this event, then play the audio clip.
                        case ButtonBar.MOUSE_ENTER:     
                        case ButtonBar.MOUSE_ENTER_DISABLED:
                             description = (String)buttonDescription.elementAt(buttonNbr);
                             if (description != null) showStatus(description);
                             if (mouseEnterAudio != null && buttonEvent == ButtonBar.MOUSE_ENTER) {
                                  mouseEnterAudio.play();
                             break;
                        // If the mouse has been moved off of a button and if the button has
                        // description text associated with it, then clear the browser's
                        // browser's status area.
                        case ButtonBar.MOUSE_EXIT:
                        case ButtonBar.MOUSE_EXIT_DISABLED:
                             description = (String)buttonDescription.elementAt(buttonNbr);
                             if (description != null) showStatus("");
                             break;
                        // If the button has been depressed (i.e., a mouseDown followed by
                        // a mouseUp for the same button) then load the URL(s) for the button
                        // in the target frame(s), if specified. If the URL is null, then the
                        // URL was found to be missing or invalid, so display the text stored in
                        // the buttonURLTarget Vector in the brower's status area. If there is
                        // an AudioClip for the event, play the audio.
                        case ButtonBar.BUTTON_DOWN:
                             // Get the string of URLs and Targets for the button
                             String urlString = (String)buttonURL.elementAt(buttonNbr);
                             String targetString = (String)buttonURLTarget.elementAt(buttonNbr);
                             // If there is at least one URL for the button
                             if (urlString != null) {
                                  URL urlForButton;
                                  String theURL;
                                  String theTarget;
                                  Enumeration urls = new StringTokenizer(urlString);
                                  Enumeration targets = null;
                                  if (targetString != null) targets = new StringTokenizer(targetString);
                                  // While there is another URL for the button
                                  while (urls.hasMoreElements()) {
                                       // Get the next String token that represents a URL
                                       theURL = (String)urls.nextElement();
                                       // Convert the String to a URL
                                       try {
                                            urlForButton = new URL(theURL);
                                       catch (Exception e) {
                                            try {
                                                 urlForButton = new URL(getDocumentBase(), theURL);
                                            catch (Exception e2) {
                                                 urlForButton = null;
                                                 break;
                                       // If the String was successfully convert to a URL
                                       if (urlForButton != null) {
                                            // If there is a target for this URL
                                            if (targets != null && targets.hasMoreElements()) {
                                                 // Get the String that represents the target
                                                 theTarget = (String)targets.nextElement();
                                                 // If the target String does NOT begin with a "-",
                                                 // then load the URL in the target
                                                 if (theTarget.charAt(0) != '-') {
                                                      getAppletContext().showDocument(urlForButton, theTarget);
                                                 // Else a target for this URL should not be used
                                                 else {
                                                      getAppletContext().showDocument(urlForButton);
                                            // Else there is no target for this URL, so just show
                                            // the URL.
                                            else {
                                                 getAppletContext().showDocument(urlForButton);
                             // Else URL is missing or invalid
                             else showStatus((String)buttonURLTarget.elementAt(buttonNbr));
                             if (buttonDownAudio != null) buttonDownAudio.play();
                             break;
         // Error reporting
         private void reportError(String message) {
              message = "[ImageURLButtonBar] Error - " + message;
              System.out.println(message);
              showStatus(message);
    }

  • Error while adding Image: ORA-00001: unique constraint

    Dear all,
    I have an error while adding images to MDM I can´t explain. I want to add 7231 images. About 6983 run fine. The rest throws this error.
    Error: Service 'SRM_MDM_CATALOG', Schema 'SRMMDMCATALOG2_m000', ERROR CODE=1 ||| ORA-00001: unique constraint (SRMMDMCATALOG2_M000.IDATA_6_DATAID) violated
    Last CMD: INSERT INTO A2i_Data_6 (PermanentId, DataId, DataGroupId, Description_L3, CodeName, Name_L3) VALUES (:1, :2, :3, :4, :5, :6)
    Name=PermanentId; Type=9; Value=1641157; ArraySize=0; NullInd=0;
    Name=DataId; Type=5; Value=426458; ArraySize=0; NullInd=0;
    Name=DataGroupId; Type=4; Value=9; ArraySize=0; NullInd=0;
    Name=Description_L3; Type=2; Value=; ArraySize=0; NullInd=0;
    Name=CodeName; Type=2; Value=207603_Img8078_gif; ArraySize=0; NullInd=0;
    Name=Name_L3; Type=2; Value=207603_Img8078.gif; ArraySize=0; NullInd=0;
    Error: Service 'SRM_MDM_CATALOG', Schema 'SRMMDMCATALOG2_m000', ERROR CODE=1 ||| ORA-00001: unique constraint (SRMMDMCATALOG2_M000.IDATA_6_DATAID) violated
    Last CMD: INSERT INTO A2i_Data_6 (PermanentId, DataId, DataGroupId, Description_L3, CodeName, Name_L3) VALUES (:1, :2, :3, :4, :5, :6)
    Name=PermanentId; Type=9; Value=1641157; ArraySize=0; NullInd=0;
    Name=DataId; Type=5; Value=426458; ArraySize=0; NullInd=0;
    Name=DataGroupId; Type=4; Value=9; ArraySize=0; NullInd=0;
    Name=Description_L3; Type=2; Value=; ArraySize=0; NullInd=0;
    Name=CodeName; Type=2; Value=207603_Img8085_gif; ArraySize=0; NullInd=0;
    Name=Name_L3; Type=2; Value=207603_Img8085.gif; ArraySize=0; NullInd=0;
    I checked all data. There is no such dataset in the database. Can anybody give me a hint how to avoid this error.
    One thing I wonder: The PermanentId is allways the same but I can´t do anything here.
    BR
    Roman
    Edited by: Roman Becker on Jan 13, 2009 12:59 AM

    Hi Ritam,
    For such issues, can you please create a new thread or directly email the author rather than dragging back up a very old thread, it is unlikely that the resolution would be the same as the database/application/etc releases would most probably be very different.
    For now I will close this thread as unanswered.
    SAP SRM Moderators.

  • Problem with display of images in applets

    Hi all,
    When I run this program, the appletviewer window is showing no output (i.e. no image). I'm using the netbeans IDE 5.0.
    Blue hills.jpg is present in both the src folder and build folder.
    * <applet code="image" width =800 height=600>
    * <param name="img" value="Blue hills.jpg">
    * <\applet>
    import java.awt.*;
    import java.applet.*;
    public class image extends Applet {
    Image img;
    public void init() {
    img=getImage(getDocumentBase(), getParameter("img"));
    public void paint(Graphics g){
    g.drawImage(img,0,0,this);
    Please help in figuring out the problem....

    It will be looking for it in the folder with the HTML that invokes the applet.
    If you want to pack the image in with the applet then use getResource instead.
    And spaces in the name are probably not the best idea.

  • How to move multiple images in applet

    Hi,how to move multiple images in applet or random images in applet .
    Means moving images.gif around the applet with different starting point ,help me to create that move method ..

    why don't you check the tumbling duke applet as provided free in this site? :-)

  • Apple have a big flaw adding images to Apple TV coding error.

    Hi all, it seems Apple have a big flaw in there new version of itunes 8.2.0.23.
    So heres the problem if you have a Apple Tv system. Adding images is great however the softwares flaw is when you have a lot of images. i have over 3000, and tick boxes apear half way in the list, for know reason.
    i have add a link to show you guys and girls a screen shot...
    can anyone from apple sort this out?
    it really bugging me. as it happens of vista, xp, windows 7, and osx.
    Cheers
    Adam
    null

    apple don't monitor the forums for bug reports... this is a user-to-user support forum.
    you should report it via the official method - http://www.apple.com/feedback/appletv.html

  • Display images in applets

    hi every body.
    I want to display images in an applet when i invoke it from the jsp page . it is not working. the code is as follows.
    <html>
    <body>
    <jsp:plugin type = "applet"
         code ="Welcome.class"
         width="475" height = "350" >
    </jsp:plugin>
    </body>
    </html>
    while the code of "Welcome.java" is as follows.
    ImageIcon image = new ImageIcon("aa.gif");
    JButton button = new JButton(image);
    i have placed the aa.gif file in the same directory where i placed the Welcome.class and the jsp file.
    when i run this program the i recieve the message that the applet is not loaded.
    can some body help me how to place images in applets.
    thanks.

    You should be able to test that applet on you hard drive first. If it works check the case of the image file.
    Web servers look for case. If you are asking for ImageIcon img = new ImageIcon("abc.gif") and what is loaded on your web server is "abc.GIF" it won't find it. Same goes for basic HTML tags like
    <Img src=abc.gif>. But it will find it on you hard drive when you run the applet there.

  • Adding Images to the List component

    Adding Images to the List component while using the FLV
    PLayback
    All, ( i can send you my source files if it would help)
    I'm using the FLV Playback component and loading videos into
    it from an external xml file. I also have a list component tied to
    the FLV playback that when you click on one of the elements in the
    list, it plays that movie.
    QUESTION:
    My question is how do I add an image to the list component?
    Below is the xml file and the actionscript. I've added the image
    attribute to the XML file as img="time_square.jpg" and added the
    element of the array when calling/creating the list. Did I do this
    right?
    Any direction would be very much appreciated.

    Adding Images to the List component while using the FLV
    PLayback
    All, ( i can send you my source files if it would help)
    I'm using the FLV Playback component and loading videos into
    it from an external xml file. I also have a list component tied to
    the FLV playback that when you click on one of the elements in the
    list, it plays that movie.
    QUESTION:
    My question is how do I add an image to the list component?
    Below is the xml file and the actionscript. I've added the image
    attribute to the XML file as img="time_square.jpg" and added the
    element of the array when calling/creating the list. Did I do this
    right?
    Any direction would be very much appreciated.

  • Help with images within applets

    I created a card game applet which calls images placed within the same directory. In appletviewer the game runs fine,not in browsers. I downloaded the browser plugin since i use swing classes. If I remove the image the applet loads up without the grafix. Here is the IO error generated. I thought applets can read files within the same directory and sub directories? Would creating a jar file solve this problem? Anyhelp would be appreciated.
    java.security.AccessControlException: access denied (java.io.FilePermission main2.gif read)

    When running in a browser, your applet must be signed in order to be able to access local resources. Check out the "Signed Applets" forum for many discussions about this, as well as methods for signing applets.

  • Adding images and buttons without a frame appearing

    I would like to add images to some of my pages without having them appear in a frame. I would like to place some transparent gifs on the page to use as buttons for hyperlinks. I would also like to have some photos (with transparent backgrounds that appear on the page and are not surrounded by a picture frame. Any Suggestions

    iWeb seems to default to stroking newly-added images and shapes. Pages (iWeb's close relation) includes a way to change the default appearance, but I can't find anything similar in iWeb. You can, of course, remove the stroke using the Graphic Inspector (just set Stroke to None). Transparency in gifs and photo images is supported. Just drag into iWeb or use Insert > Choose... Again, remove the stroke if this appears.

  • Re: adding canvas to applet

    Hi
    I am trying to add a canvas to an applet. I am successful in doing so. There is a JMenuBar added to the applet. when I click on the file menu The contents are being displayed behind the canvas and as a result I am neither able to see the buttons nor select them. Could some one help me with this.
    Note: Once you compile the code you wouldn't be able to see the contents right away. Click on left top,immidiately below the applet menu. This will repaint the contentpane. This is some thing I am working on.
    applet class
    package aple;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Shape;
    import java.awt.geom.AffineTransform;
    import java.util.ArrayList;
    import javax.swing.JApplet;
    public class NewJApplet extends JApplet{
        public Graphics2D g2;
        AffineTransform atf = new AffineTransform();
        sketch sk = new sketch();   
            @Override
        public void init() {      
            getContentPane().add(sk);
           Gui gui = new Gui();
            // menubar
            this.setJMenuBar(gui.Gui());     
        @Override
    gui class
    package aple;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    public class Gui {
        JMenuBar menuBar;
        JMenu file,edit,insert,view,draw,circle;
        JMenuItem nu,close,saveAs,open,centreandradius,line,rectangle,point,arc;
        public JMenuBar Gui(){
            //Menubar
            menuBar = new JMenuBar();
            //Menus
            file = new JMenu("File");
            menuBar.add(file);
            edit = new JMenu("Edit");
            menuBar.add(edit);
            view = new JMenu("View");
            menuBar.add(view);
            insert = new JMenu("Insert");       
            draw = new JMenu("Draw");
            circle = new JMenu("Circle");
            draw.add(circle);
            insert.add(draw);       
            menuBar.add(insert);
            //MenuItems
            nu = new JMenuItem("New");
            file.add(nu);
            open = new JMenuItem("Open");
            file.add(open);
            saveAs = new JMenuItem("SaveAs");
            file.add(saveAs);
            close = new JMenuItem("Close");
            file.add(close);
            line = new JMenuItem("Line");
            draw.add(line);
            centreandradius = new JMenuItem("Centre and Radius");
            circle.add(centreandradius);
            rectangle = new JMenuItem("Rectangle");
            draw.add(rectangle);
            point = new JMenuItem("Point");
            draw.add(point);
            arc = new JMenuItem("arc");
            draw.add("Arc");
            return(menuBar);
    sketch class
    package aple;
    import java.awt.Canvas;
    import java.awt.Color;
    import java.awt.Graphics;
    public class sketch extends Canvas{
        public void sketch(){
            this.setBackground(Color.green);
        @Override
        public void paint(Graphics g){
         // g.fillRect(50,50, 50, 50); 
    }

    When you were using JPanel, your "setBackground" didn't work because you were overriding its paint(Graphics) method without calling "super.paint(g);". If you don't do this, the panel won't paint its background.
    You should also override "protected void paintComponent(Graphics g)" in any JComponent, such as JPanel, instead of just "paint(Graphics)". (And don't forget to call super.paintComponent(g) FIRST in your subclass's overridden method, if you want the background painted):
    class MyJPanelSubclass extends JPanel {
       protected void paintComponent(Graphics g) {
          super.paintComponent(g); // Paints background and any other stuff normally painted.
          // Do your custom painting here.
    }

  • Background layer seizes added images.

    I am trying to create a photo collage by scratch (not using "Collage"). First I create a new blank page for the background and save it. It is shown as "locked" with a padlock. Then I open an image file (.jpg) to add to the background layer, and I get a message that I need to unlock the background layer so I click to unlock it. However the added image locks onto the background layer and doesn't make a new layer. If I open another image file it locks on top of the others.

    The Layers panel only shows the layer(s) belonging to the currently active file. You need to arrange your image windows so that you can see your composite image as well as the source. With the source image active the Layers panel will show the source - click and drag that layer to the composite.
    So in the following, the violet image is the active image and I drag its layer to the white image I've created for my collage. In the composite image with the new layer selected I can position it where I want. Select each of the other images in turn and do the same. Refer to my previous note, you can also do this with Copy & Paste.
    When finished, your composite image and its Layers panel will look like this:
    Cheers,
    Neale
    Insanity is hereditary, you get it from your children
    If this post or another user's post resolves the original issue, please mark the posts as correct and/or helpful accordingly. This helps other users with similar trouble get answers to their questions quicker. Thanks.

  • Saving image in applet

    i used the following code to save a image it displays from applet.it works fine in appletviewer
    BufferedImage expImage = new BufferedImage( (int)this.getWidth(), (int)this.getHeight(), BufferedImage.TYPE_INT_RGB );
    Graphics g2d = expImage.getGraphics();
    // draftGrid.update(g2d);
    this.update(g2d);
    g2d.dispose();
    OutputStream out = new FileOutputStream( "guru.jpg");
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    encoder.encode(expImage);
    out.flush();
    out.close();
    expImage.flush();
    but when i run it in html through my web server the image does' get saved and it the exception i go is
    Status code:404 request:R( j
    ava/awt/image/BufferedImage.class + null) msg:null
    what should i go to save a image from applet throgh browser

    Hello,
    This is what I am doing through a servlet call.
    If you are just going to let the user download the image you could try the following:
    // This works if we are just going to download the image as is
    URL url = new URL(request.getParameter("imageURL"));
    response.setContentType("image/gif");
    response.setHeader("Content-Disposition", "attachment; "+
         "filename=\"image.gif\"");
    byte buf[] = new byte[1024];
    InputStream inputStream = url.openStream();
    ServletOutputStream out = response.getOutputStream();
    //Read and Write
    while(inputStream.read(buf) != -1)
    out.write(buf);
    out.flush();
    out.close();
    Or if you are going to manipulate the image a bit before they download it you could try the following:
    URL url = new URL(request.getParameter("imageURL"));
    response.setContentType("image/gif");
    response.setHeader("Content-Disposition", "attachment; "+
         "filename=\"image.gif\"");
    // use ImageIcon because we are getting the image from a
    // URL which might be slow - it has the MediaTracker built right in
    javax.swing.ImageIcon ii = new javax.swing.ImageIcon(url);
    Image image = ii.getImage(); // now the pixel data is in memory
    // get the height and width of the loaded image
    int width = image.getWidth(null);
    int height = image.getHeight(null);
    // create a rectangle as big as the image
    Rectangle drawRect = new Rectangle(10, 10, width, height);
    BufferedImage bufImage = new BufferedImage(width,
    height, BufferedImage.TYPE_INT_RGB);
    // get the graphics so you can draw on it
    Graphics2D g = bufImage.createGraphics();
    // create a nicce white background for the image
    g.setColor(Color.white);
    g.fillRect(0, 0, width, height);
    // reset the color
    g.setColor(Color.black);
    // add the image
    g.drawImage(image, 0, 0, null);
    // add any other things you want as well
    g.drawString("Just a string", 10, 10);
    // create the output stream
    ServletOutputStream out = response.getOutputStream();
    JPEGImageEncoder jpegImageEncoder = JPEGCodec.createJPEGEncode(out);
    // encode it
    jpegImageEncoder.encode(bufImage);
    out.flush();
    out.close();
    Hope that this helps.
    Mike

Maybe you are looking for

  • Boot issues

    When I boot my computer (MacBook Pro, 15", Early 2010, 4GB RAM, 320GB HD, 2.4GHz Intel Core i5), it does nothing for quite awhile, and eventually gives me the folder with the question mark on it, signifying it can't find a startup volume. I think I k

  • How can i figure out from my account page which kids ipad made purchases

    How can I figure out which childs ipad made an in app purchase from my main account - recent purchases page?

  • ORA-29540:class oracle/pub/runtime/dbws/DbwsProxy does not exist

    Hi we are getting below error while calling UTl_DBWS package. Database version 11.2.0.2 package definition create or replace function xxpvn_ws_test return varchar2 is   service_           sys.utl_dbws.SERVICE;   call_              sys.utl_dbws.CALL;

  • Languages and Presenter

    Hi, I understand that Presenter has a Multilingual support function, I would like to know if this also changes any audio that is in the powerpoint presentation or is it only the text on the viewer? I am fairly new to this and am doing a project where

  • Forgot sysadmin password, how to reset?

    Hi We have oracle EBS R12.0.6 instance running.Somebody who has system administrator responisiblity changed, sysadmin password. When i query help>record history does shows 'system logon=unknown'. If auditing is not enabled, how do i know who changed