ArrayIndexOutOfBound Exception for image

Hi All,
I my application i want to convert image into inverted format.So for this i have written this code.
ParameterBlock pb = new ParameterBlock();
                    pb.add(bufferedImage);          
PlanarImage im = (PlanarImage)JAI.create("awtImage", pb);          
ParameterBlock pb1 = new ParameterBlock();               
               pb1.addSource(im);               
PlanarImage newImage = JAI.create("invert", pb1);
ParameterBlock pb2 = new ParameterBlock();
               pb2.addSource(newImage);
               pb2.add(jpegFilePath);
               pb2.add("jpeg");
               pb2.add(null);
               pb2.add(true);
RenderedOp op = JAI.create("filestore", pb2,null);
But i am getting this error while storing image.
java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
     at sun.awt.image.BytePackedRaster.getByteData(BytePackedRaster.java:378)
     at sun.awt.image.BytePackedRaster.getDataElements(BytePackedRaster.java:273)
     at java.awt.image.BufferedImage.getData(BufferedImage.java:1415)
     at javax.media.jai.RenderedImageAdapter.getData(RenderedImageAdapter.java:158)
     at javax.media.jai.PointOpImage.computeTile(PointOpImage.java:794)
     at com.sun.media.jai.util.SunTileScheduler.scheduleTile(SunTileScheduler.java:904)
     at javax.media.jai.OpImage.getTile(OpImage.java:1129)
     at javax.media.jai.PlanarImage.copyData(PlanarImage.java:2343)
     at javax.media.jai.RenderedOp.copyData(RenderedOp.java:2299)
     at javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2525)
     at javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2546)
If any one knows how to invert image using JAI or java please reply me as soon as possible
Thanks & Regsrds
AP_java

Hi, Thanks for your reply.
But seeing the 2nd println statement is not my point. I was trying to point out that the NullPointerException caused within Image.createImage could not be caught even when i enclosed only the statement within a try-catch. This is not good because my users will get a shock when they see the exception.
Maybe there is a bug in the Image.createImage method. I will go log a bug in the bugbase later.
But anyway, i observe that this exception does not occur all the time. It only happen after i print a few images and more often when i use color. I guess it's a memory issue here.
So i went around it by reducing the memory usage of my app and using less colors. Up to 256 colors is quite safe.

Similar Messages

  • Java.lang.Outof Memory Exception for Image

    Hi
    I am having an applet which displays some tiff image. when i am trying to print that image , iam getting OutOf Memory exception ....
    I increased heap size by setting the environment variable...
    i.e Variable : JAVA_OPTS
    Value : -Xms128m -Xmx 512m
    Even though i increased the heap size, i am getting the same exception...
    Can any body solve it ....
    Exception is :..........
    Java.lang.OutOfMemoryError
    Thanks

    Hello,
    I have the same pb... (see "TIFF : how to read with tiles")
    I just know that we have to divide the tiff into a grid of "tiles".
    By playing with tiles, images are processed gradually instead of being entirely stored in the memory.
    But I don't know how to do...

  • My book was rejected for containing images with embedded text. Does Apple not make exceptions for graphic novels, etc.?

    I created my first book with iBooks Author, and am trying to publish it as a paid book in the iBookstore. It is a book of writing and photography, and each page contains one or more photographs. Some of the photographs are of handwritten notebook pages, and these are an essential and expressive part of the book. The handwritten notes were written when taking the photographs, and the book is a thoughtful visual journal about walking and photography. Replacing the handwriting with typewritten text would not work at all.
    However, Apple rejected my book because "Embedding text in images creates issues that cause a large number of customer complaints."
    I understand the reasoning behind this requirement, and certainly it is appropriate for most books. But does Apple make exceptions for books that need to present text visually? I would call my book an "artist's book", but it could be thought of as a graphic novel. Surely there are other books besides mine that require text embedded in images.

    This sounds like something you have to take up with Apple directly rather than here in the user/user forums.  You might want to try the contacts listed at the bottom of the FAQ:
    http://www.apple.com/itunes/content-providers/book-faq.html
    It might be helpful to find some things in the store yourself that demonstrate such exceptions, so you can ask for equal treatment.

  • GoPro Camera Raw Lens Profile settings not working for image sequence in Photoshop/AE/Premiere CS6

    Hey Everyone,
    I'm in need of assistance in either Photoshop CS6, After Effects CS6, or Premiere Pro CS6.  I just installed the trials after seeing Russell Brown demo the GoPro Lens Profile correction feature in Camera Raw.  Basically what I'm looking to do is make adjustments (in Adobe Camera Raw) to a series of still images (shot with the time-lapse mode on the GoPro) and then either export those stills through Photoshop or Bridge to a temporary movie file that will be imported into a timeline (with other video clips), or import the JPG files (with Camera Raw settings) directly into After Effects or Premiere as an image sequence.  The latter would be preferable as it'd avoid the extra step of having to render the intermediate/temporary movie file.
    Right now, my current workflow for GoPro time-lapses is:
              - use Bridge CS4 to do basic color correction on the still images
              - save those as TIF files
              - run the TIF files through a custom script to have Hugin 2012.0.0 (open source pano stitcher) remove the fisheye distortion
              - open the new TIF image sequence into QuickTime Player 7 (Pro)
              - export the image sequence as a QuickTime movie file
              - import the movie file into Premiere Elements 10 to place on a timeline with other video clips (as Premiere Elements can't handle the sequence(s) of thousands of still images without crashing)
    If I can go directly from Bridge to a timeline, it'd save a lot of processing time (and it'd be much nicer to preview the images in Bridge without the fisheye distortion)!
    I can prepare the GoPro JPG files through Adobe Camera Raw in Bridge CS6, though when I go to import the JPEG image sequence into Premiere Pro CS6 or After Effects CS6, none of the Camera Raw settings are applied.  If I export the Camera Raw files in Bridge CS6 as DNG files (a step I'd really prefer to avoid) and then import the DNG image sequence into After Effects CS6, the Camera Raw settings are applied except for the Lens Profile settings -- I can pick other cameras but not the GoPro lens profiles when the DNG image sequence loads in After Effects.  It also appears that once I open the DNG files in After Effects CS6, I can no longer access the GoPro Lens Profile in Adobe Bridge CS6 -- the list changes to the same list I get in After Effects.  Premiere Pro CS6 doesn't let me import the DNG files at all.  I've also tried to import the JPG files (as well as the converted DNG files) into an image sequence in Photoshop CS6, though it doesn't allow me to do so (the Image Sequence checkbox is grayed out after I apply the Camera Raw settings in Bridge).
    There could be an issue going on with different Camera Raw versions.  I didn't have Premiere Pro CS6 installed during my initial testing, though now do notice that the Camera Raw dialog in Bridge CS6 only lets me choose compatibility up to "Camera Raw 7.1 and later" when I choose to export the files as DNG.  I thought Camera Raw 8.2 was an option there a couple days ago when I only had installed Photoshop CS6 and After Effects CS6 (though am not 100% certain).
    Please let me know if there is some workaround to get the GoPro lens profile Camera Raw corrections applied in an image sequence in one of the Adobe CS6 products (without having to export the files as temporary TIF or JPG files out of Camera Raw).  I'd greatly prefer to shorten my current workflow for these files.  (I just updated the CS6 trials and have tested all three programs again though I still get the same results described above.)
    Does Lightroom 5 have any option to export Camera Raw image sequences as movie files (or any other feature that might help in simplifying my current workflow)?  I can't install the trial right now as it's not compatible with OS X 10.6.8.  I'd consider upgrading OS X if I knew Lightroom 5 would do what I need, though am waiting for any potential color profile issues to be resolved in OS X 10.9.
    I can open the image sequence in Photoshop CS6 if no Camera Raw settings are applied and then use the Lens Correction Filter to apply the GoPro Lens Profile settings, though I really prefer the Camera Raw interface in Bridge for tweaking image settings.  As soon as I apply Camera Raw settings to the first image, Photoshop CS6 grays out the image sequence checkbox.
    If there isn't a way to take Camera Raw files straight from Adobe Bridge to a timeline, I may stick with my current workflow using CS4 and see what I can do to better automate some of the steps as the TIF export in Bridge, fisheye distortion removal in Hugin, and render in QuickTime Player all take quite a while.  I won't mind waiting for all the processing if I can set it and check back on it in later the next day when it's fully complete.  Is there a way to have Adobe ExtendScript execute an external shell command (i.e.: a command I could type into the bash shell in Terminal in OS X)?  If not, is there a way to call/run an ExtendScript script from the command line and pass a parameter to it that my custom script could use?
    Thanks in advance,
    Mark

    Can you zip up a few of your GoPro images, upload them to dropbox.com and post a share link, here, so others can experiment with them, or do you mean this issue is global to all camera models?

  • HT2905 i have just followed all the insrtuctions in support to remove duplicates from my library but now most of my musicis gone except for my recent purchases. How come and how do i fix it?

    i have just followed all the instructions in support to remove duplicates from my library but now most of my music is gone except for my recent purchases. How come and how do i fix it?

    Final Cut is a separate, higher end video editor.  The pro version of iMovie.
    Give iPhoto a look at for creating the slideshow.  It's easy to assemble the photos in an album in iPhoto, put them in the order you want and then make a slideshow of them.  You can select from various themes and transitions between slides and add music from your iTunes library.
    When you have the slidshow as you want use the Export button at the bottom of the iPhoto window and export with Size = Medium or Large.
    Save the resulting Quicktime movie file in your Movies folder.
    Next, open iDVD, choose your theme and drag the QT movie file into the menu window being careful to avoid any drop zones.
    Then follow this workflow to help assure the best qualty video DVD:
    Once you have the project as you want it save it as a disk image via the File ➙ Save as Disk Image  menu option. This will separate the encoding process from the burn process. 
    To check the encoding mount the disk image, launch DVD Player and play it.  If it plays OK with DVD Player the encoding is good.
    Then burn to disk with Disk Utility or Toast at the slowest speed available (2x-4x) to assure the best burn quality.  Always use top quality media:  Verbatim, Maxell or Taiyo Yuden DVD-R are the most recommended in these forums.
    The reason I suggest iPhoto is that I find it much easier to use than iMovie (except for the older iMovie 6 HD version).  Personal preferences showing here.

  • DrawImage takes long time for images created with Photoshop

    Hello,
    I created a simple program to resize images using the drawImage method and it works very well for images except images which have either been created or modified with Photoshop 8.
    The main block of my code is
    public static BufferedImage scale(  BufferedImage image,
                                          int targetWidth, int targetHeight) {
       int type = (image.getTransparency() == Transparency.OPAQUE) ?
                        BufferedImage.TYPE_INT_RGB :
                        BufferedImage.TYPE_INT_RGB;
       BufferedImage ret = (BufferedImage) image;
       BufferedImage temp = new BufferedImage(targetWidth, targetHeight, type);
       Graphics2D g2 = temp.createGraphics();
       g2.setRenderingHint
             RenderingHints.KEY_INTERPOLATION, 
             RenderingHints.VALUE_INTERPOLATION_BICUBIC
       g2.drawImage(ret, 0, 0, targetWidth, targetHeight, null);
       g2.dispose();
       ret = temp;
       return ret;
    }The program is a little longer, but this is the gist of it.
    When I run a jpg through this program (without Photoshop modifications) , I get the following trace results (when I trace each line of the code) telling me how long each step took in milliseconds:
    Temp BufferedImage: 16
    createGraphics: 78
    drawimage: 31
    dispose: 0
    However, the same image saved in Photoshop (no modifications except saving in Photohop ) gave me the following results:
    Temp BufferedImage: 16
    createGraphics: 78
    drawimage: 27250
    dispose: 0
    The difference is shocking. It took the drawImage process 27 seconds to resize the file in comparison to 0.78 seconds!
    My questions:
    1. Why does it take so much longer for the drawImage to process the file when the file is saved in Photoshop?
    2. Are there any code improvements which will speed up the image drawing?
    Thanks for your help,
    -Rogier

    You saved the file in PNG format. The default PNGImagReader in core java has a habit of occasionally returning TYPE_CUSTOM buffered images. Photoshop 8 probably saves the png file in such a way that TYPE_CUSTOM pops up more.
    And when you draw a TYPE_CUSTOM buffered image onto a graphics context it almost always takes an unbearably long time.
    So a quick fix would be to load the file with the Toolkit instead, and then scale that image.
    Image img = Toolkit.getDefaultToolkit().createImage(/*the file*/);
    new ImageIcon(img);
    //send off image to be scaled A more elaborate fix involves specifying your own type of BufferedImage you want the PNGImageReader to use
    ImageInputStream in = ImageIO.createImageInputStream(/*file*/);
    ImageReader reader = ImageIO.getImageReaders(in).next();
    reader.setInput(in,true,true);
    ImageTypeSpecifier sourceImageType = reader.getImageTypes(0).next();
    ImageReadParam readParam = reader.getDefaultReadParam();
    //to implement
    configureReadParam(sourceImageType, readParam);
    BufferedImage img = reader.read(0,readParam);
    //clean up
    reader.dispose();
    in.close(); The thing that needs to be implemented is the method I called configureReadParam. In this method you would check the color space, color model, and BufferedImage type of the supplied ImageTypeSpecifier and set a new ImageTypeSpecifier if need be. The method would essentially boil down to a series of if statements
    1) If the image type specifier already uses a non-custom BufferedImage, then all is well and we don't need to do anything to the readParam
    2) If the ColorSpace is gray then we create a new ImageTypeSpecifier based on a TYPE_BYTE_GRAY BufferedImage.
    3) If the ColorSpace is gray, but the color model includes alpha, then we need to do the above and also call seSourceBands on the readParam to discard the alpha channel.
    3) If the ColorSpace is RGB and the color model includes alpha, then we create a new ImageTypeSpecifier based on an ARGB BufferedImage.
    4) If the ColorSpace if RGB and the color model doesn't include alpha, then we create a new ImageTypeSpecifier based on TYPE_3BYTE_BGR
    5) If the ColorSpace is not Gray or RGB, then we do nothing to the readParam and ColorConvertOp the resulting image to an RGB image.
    If this looks absolutely daunting to you, then go with the Toolkit approach mentioned first.

  • Need to create 500 designs, all identical in every way except for a unique QR code

    Hi there. I am using Photoshop CS6.
    I have a design from which I want to create 500 versions of an image. All will be identical, except for the QR code which will be unique for every one.
    The placement of the QR code will be identical in all of them. It's just the actual QR code that changes.
    Any idea how I can achieve this in an automated way? I have the QR codes in a folder, already created, and I have the design already created. I just need to marry up the 2 now and end up with 500 design files to give to the printers for printing.
    Thanks for any direction on how to do this!

    I think you can do it with variables.   I haven't ever tried it, but someone posted up a link to it a few weeks back when a similar question came up.  I bookmarked it because it looked interesting:
    PS CS5 - Working with Variables | The Complete Picture with Julieanne Kost | Adobe TV
    And here's a walkthrough:
    Using Variables in Photoshop with External Data Source

  • Pop Up blocker exceptions are not saved in the browser for use, the next time the PC reboots. How do you save these exceptions for long term use?

    Pop Up blocker exceptions are not saved in the browser for use, the next time the PC reboots. How do you save these exceptions for long term use?

    In case you are using "Clear history when Firefox closes":
    *do not clear the Site Preferences
    *Tools > Options > Privacy > Firefox will: "Use custom settings for history": [X] "Clear history when Firefox closes" > Settings
    *https://support.mozilla.org/kb/remove-browsing-search-and-download-history
    Note that clearing "Site Preferences" clears all exceptions for cookies, images, pop-up windows, software installation, passwords, and other website specific data.
    If you have software like Advanced SystemCare (Surfing Protection feature) that might reset some files to older versions to protect these files against changes then check the settings or uninstall this software.

  • GetSystemClipboard().setContents fails for images?

    I had already posted this thread to the JAI forum (which i believe is an improper place for it after reviewing all available locations). If somebody can point me to a way of removing it I would be happy to.
    http://forums.sun.com/thread.jspa?threadID=5355247&messageID=10546446
    The clipboard is giving me some trouble... If I copy an image selection with transparency data and then create a BufferedImage from the clipboard contents (paste), then everything works fine everywhere. However if I have a BufferedImage with transparency data that I want to SET to the clipboard (copy) then I observe two different behaviors between Ubuntu and Windows XP -- both incorrect.
    On Ubuntu:
    getTransferDataFlavors of my Transferable is called once. isDataFlavorSupported and getTransferData are never called. The clipboard is unaltered. No exception is thrown -- nothing. It just silently fails to do anything. Calling Toolkit.getDefaultToolkit().getSystemClipboard().getAvailableDataFlavors() shows me that DataFlavor.imageFlavor is indeed present.
    On Windows:
    My getTransferData is indeed called and the clipboard is modified. However, the image is set on a BLACK background -- the transparency data is lost.
    Additional Notes:
    I'm am running Java 1.6
    My paste destination is in GIMP, on a new image with transparent background.
    A self contained code example which reproduces the problem I'm experiencing is as follows. Paste works (slowly) and copy fails
    import java.io.IOException;
    import java.net.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.imageio.*;
    import java.awt.datatransfer.*;
    public class CopyTest extends JPanel{
         public static void main(String args[]) throws Exception{
              final CopyTest copyTest = new CopyTest();
              JFrame f = new JFrame();
              f.addWindowListener(new WindowListener(){
                   public void windowClosed(WindowEvent e){}
                   public void windowClosing(WindowEvent e){ System.exit(0); }
                   public void windowIconified(WindowEvent e){}
                   public void windowDeiconified(WindowEvent e){}
                   public void windowActivated(WindowEvent e){}
                   public void windowDeactivated(WindowEvent e){}
                   public void windowOpened(WindowEvent e){}
              f.setLayout(new BorderLayout());
              JButton btnCopy = new JButton("Copy");
              JButton btnPaste = new JButton("Paste");
              JPanel southPanel = new JPanel();
              southPanel.add(btnCopy);
              southPanel.add(btnPaste);
              f.add(copyTest, BorderLayout.CENTER);
              f.add(southPanel, BorderLayout.SOUTH);
              btnCopy.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent e){ copyTest.copy(); }
              btnPaste.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent e){ copyTest.paste(); }
              f.setSize(320, 240);
              f.setVisible(true);
         private static final int SQUARE_SIZE=6;
         private BufferedImage image;
         // Constructor
         public CopyTest() throws Exception{
              this.image = ImageIO.read(new URL("http://forums.sun.com/im/duke.gif"));
         // Copy
         public void copy(){
              Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
                        new Transferable(){
                             public DataFlavor[] getTransferDataFlavors() { return new DataFlavor[]{DataFlavor.imageFlavor}; }
                             public boolean isDataFlavorSupported(DataFlavor flavor) { return DataFlavor.imageFlavor.equals(DataFlavor.imageFlavor); }
                             public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
                               if(!DataFlavor.imageFlavor.equals(flavor)){ throw new UnsupportedFlavorException(flavor); }
                               return image;
                        , null);
         // Paste
         public void paste(){
              // Get the contents
              BufferedImage clipboard = null;
              Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
              try {
                if (t != null && t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
                     clipboard = (BufferedImage)t.getTransferData(DataFlavor.imageFlavor);
            } catch (Exception e) { e.printStackTrace(); }
            // Use the contents
            if(clipboard != null){
                   image = clipboard;
                   repaint();
         // Paint
         public void paint(Graphics g){
              // Paint squares in the background to accent transparency
              g.setColor(Color.LIGHT_GRAY);
              g.fillRect(0, 0, getWidth(), getHeight());
              g.setColor(Color.DARK_GRAY);
              for(int x=0; x<(getWidth()/SQUARE_SIZE)+1; x=x+1){
                   for(int y=0; y<(getHeight()/SQUARE_SIZE)+1; y=y+1){
                        if(x%2 == y%2){ g.fillRect(x*SQUARE_SIZE, y*SQUARE_SIZE, SQUARE_SIZE, SQUARE_SIZE); }
              // Paint the image
              g.drawImage(image, 0, 0, this);
    }1. Run the application
    2. Press the copy button
    3. Attempt to paste somewhere (such as GIMP)
    ideas?

    I have this problem as well, and I have been banging my head against it for quite some time. But as far as I can tell, Java does not support transparent images on the clipboard (please, somebody, prove me wrong!). My main requirement is that users need to paste images to Microsoft Office, so I use the following work around:
    import java.awt.*;
    import java.awt.datatransfer.*;
    import java.awt.event.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import java.util.Arrays;
    import javax.imageio.ImageIO;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    public class CopyExample
            extends JFrame
            implements ActionListener {
        public static void main(String[] args) {
            new CopyExample();
        public CopyExample() {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setSize(200, 200);
            JButton button = new JButton("Copy");
            button.addActionListener(this);
            add(button);
            setVisible(true);
        public void actionPerformed(ActionEvent e) {
            try {
                Transferable transf =
                        new ImageTransferable(createImage());
                Toolkit.getDefaultToolkit()
                        .getSystemClipboard()
                        .setContents(transf, null);           
            } catch(IOException ex) {
                ex.printStackTrace();
        private BufferedImage createImage() {
            final BufferedImage image = new BufferedImage(
                    200, 200, BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2 = image.createGraphics();
            g2.setComposite(AlphaComposite.Clear);
            g2.fillRect(0, 0, 200, 200);
            g2.setComposite(AlphaComposite.SrcOver);
            g2.setColor(Color.GREEN);
            g2.fillRect(50, 50, 100, 100);
            g2.dispose();
            return image;
    class ImageTransferable implements Transferable {
        private File imageFile;
        public ImageTransferable(BufferedImage image) throws IOException {
            imageFile = File.createTempFile("copy", ".png");
            imageFile.deleteOnExit();
            ImageIO.write(image, "png", imageFile);
        public DataFlavor[] getTransferDataFlavors() {
            return new DataFlavor[] {
                DataFlavor.javaFileListFlavor
        public boolean isDataFlavorSupported(DataFlavor flavor) {
            return flavor.match(DataFlavor.javaFileListFlavor);
        public Object getTransferData(DataFlavor flavor)
                throws UnsupportedFlavorException, IOException {               
            return Arrays.asList(imageFile);
    }I take the image and write it to a temporary png file and then put it on the clipboard as a DataFlavor.javaFileListFlavor. But this does not work in Photoshop or MS Paint.

  • Xmp sidecars for images moved to dvd

    I have only one catalog with a folder where I put all my images (organized in sub folders). In the catalog settings / metadata tab I marked the option "automatically write changes into xmp". When I change any parameter for the image in the develop module, automatically a XMP is created/updated in the same folder where the image is located.
    From times to times I move some folders to DVDs for archiving and to free HDD space. When I do that, I simply record the entire folder (including RAWs, JPGs, PSDs, XMPs, etc) to a DVD-R and delete it from the HDD. Then I import it (from current location, creating previews) back to Lightroom.
    I'm happy with this system and it's working ok, except for the following:
    I had modified some developing parameters for the DVD's images (after they were recorded and deleted and reloaded from the DVD) but the .xmp files are not updated, since they are read-only now. I want to export the modifications I made after the archiving to refresh the DVD's XMPs with the new ones, but I don't know how. I tried to export as catalog, but no .xmp files are created this way.
    The question is: How to export/backup updated XMPs for the read-only media files?
    Any idea?
    thanks
    [windows xp / lightroom 1.3.1]

    "unless you need to open the files from Bridge or directly in Photoshop."
    Yes, I want to have the XMP settings readily available so I can use the files in other computer(s) that has only Photoshop (not Lightroom).
    The answer on flickr says: "move the image+xmp back into your working environment, make your changes and then move to another dvd-r and re-import next time you need to free space"
    Well, I already did the changes for the files that *are* on DVD-r. The changes are stored in the Lightroom catalog and I don't want to lose them. I just can't find a way to export them other than exporting as catalog and that way I can't use the updated settings on the other computer I have. Plus I don't like to waste disk space with a big catalog file if the XMPs are so small and do what I want.

  • Help with ArrayIndexOutOfBounds Exception

    Hi all,
    I am very new to programming in general and Java in particular. I'm working on a program from a book that is supposed to read 72 hourly readings of voltage and then print the mean voltage over that time period and any hours where the voltage varies from the mean by more than ten percent.
    I have an array set up that should have 72 elements created randomly, between 12000-14000. I'm getting an ArrayIndexOutOfBounds Exception when I try to run the program. So far as I understand, this means that somewhere in the program I'm trying to reference an array index that doesn't exist. I just can't see where that is! I've tried a couple different things to see if they've worked but have had no luck.
    I'm sure this is just a simple thing, but I'm feeling a little under the weather and I think my brain is pickled from looking at this code for too long. Any suggestions or ideas are gladly welcomed! I'll paste the code below to take a look at. Sorry if it's ugly or messy... I'm just figuring this stuff out still!
    Thanks so much-
    Heather
    import java.lang.*;
    import java.util.*;
    class VoltageReport {
    VoltageReport () throws IOException {
    System.out.println("Welcome to the voltage meter program!");
    //int place = 0;
    int MeterReadings[] = new int [71];
    int place = 0;
    for (int i = 0; i <= 71; i++) {
    //if (place == 72) break; thought this would do it, but it doesn't.
    MeterReadings[place] = (int) (Math.random()*2000+12000);
    place++;
    place = 0;
    int VoltageMean;
    VoltageMean = 0;
    for (int i = 0; i <= 71; i++) {
    VoltageMean = VoltageMean + MeterReadings[place];
    place++;
    place = 0;
    VoltageMean = VoltageMean / 72;
    for (int i = 0; i <= 71; i++) {
    if (MeterReadings[place] < (.9 * VoltageMean)) {
    System.out.println("Hour " + place + " is more than 10% lower than the " + "mean of " + VoltageMean + " .");
    else if (MeterReadings[place] > (.9 * VoltageMean)) {
    System.out.println("Hour " + place + " is more than 10% higher than the " + "mean of " + VoltageMean + " .");
    place++;
    System.out.println("That's all the information I have. Goodbye!"); }
    public static void main (String [] args) throws IOException {
    new VoltageReport();
    }

    if (MeterReadings[place] < (.9 * VoltageMean))
        System.out.println("Hour " + place + " is more than 10% lower than the " + "mean of " + VoltageMean + " .");
    else if (MeterReadings[place] > (.9 * VoltageMean))
        System.out.println("Hour " + place + " is more than 10% higher than the " + "mean of " + VoltageMean + " .");The problem lies in the else-if. You are checking if the voltage is over 90% of the mean. I think you want to check if it is over 110% of(10% over) the mean.
    else if(MeterReadings[place] > (1.1 * VoltageMean))
    ....And a few other things.
    Arrays
    int[] temp = new int[5]; // you have indexes (indices?) 0, 1, 2, 3 & 4 is the last one
    // Count them, there is 5 there.  Since we always start at 0, the last one is always 1 less than the length.
    // Never do temp[temp.length], this will ALWAYS end in IndexOutOfBoundsException.
    // temp[temp.length-1] is the way to get the last element.
    Posting code
    Since you were unusually nice, no one has cut sick at you, but in the future when you post code, put it between [ code ] and [ /code ] tags (I added spaces so the forum doesn't recognize them, but you get the idea).
    Cheers,
    Radish21

  • JSP causes strange ArrayIndexOutOfBounds exception

    Hello.
    I'm having a jsp, that outputs some information (this part is not important).
    I'm using Tomcat 5.0
    Sometimes it happens that that jsp throws ArrayIndexOutOfBounds: 45, and Tomcat starts to throw OutOfMemory exception.
    This would be not so strange if I had any array in the jsp. However, I do not. And furthermore, the line shown in the stacktrace log contains...a closing bracket.
    Also, I cannot reproduce this - it happens to some of my users.
    My suspection is, that someone is making an attack via the input parameters.
    I use Integer.parseInt to get the numeric values of the request parameters.
    Is there any vulnerability, or any way that Integer.parseInt throw an "ArrayIndexOutOfBounds" Exception, or I should look for something else. Thanks

    Hello.
    I'm having a jsp, that outputs some information (this part is not important).
    I'm using Tomcat 5.0
    Sometimes it happens that that jsp throws ArrayIndexOutOfBounds: 45, and Tomcat starts to throw OutOfMemory exception.
    This would be not so strange if I had any array in the jsp. However, I do not. And furthermore, the line shown in the stacktrace log contains...a closing bracket.
    Also, I cannot reproduce this - it happens to some of my users.
    My suspection is, that someone is making an attack via the input parameters.
    I use Integer.parseInt to get the numeric values of the request parameters.
    Is there any vulnerability, or any way that Integer.parseInt throw an "ArrayIndexOutOfBounds" Exception, or I should look for something else. Thanks

  • This is my Jsp code for image upload in database:

    This is my Jsp code for image upload in database:
    -----------Upload.jsp----------------
    <html>
    <head>
    </head>
    <body bgproperties="fixed" bgcolor="#CCFFFF">
    <form method="POST" action="UploadPicture.jsp" enctype="multiform/form-data">
    <%! int update=0; %>
    <%@ page import="java.util.*" %>
    <%@ page import="java.sql.*" %>
    <%@ page import="java.text.*" %>
    <%@ page import="java.sql.Date" %>
    <%@ page import="java.io.*"%>
    <%@ page language = "java" %>
    <%
    try
    String ct="3";
    String path;
    File image=new File(request.getParameter("upload"));
    path=request.getParameter("upload");
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:itPlusElectronics","","");
    PreparedStatement pstmt=con.prepareStatement("insert into graphics values(?,?,?)");
    pstmt.setString(2,path);
    pstmt.setString(3,ct);
    InputStream is=new FileInputStream(path);
    pstmt.setBinaryStream(1, is, (int)(image.length()));
    int s=pstmt.executeUpdate();
    if(s>0)
    out.println("Uploaded");
    else
    %>
    unsucessfull
    <%}
    is.close();
    pstmt.close();
    catch(Exception e)
    }%>
    </p>
    <p><br>
    <img src="UploadedPicture.jsp">image</img>
    <p></p>
    </form>
    </body>
    </html>
    My database name is itPlusElectronics and the table name is "graphics".
    I have seen as a result of the above code that the image is stored in database as "Long binary data". and database table is look like as follows-------
    picture path id
    Long binary data D:\AMRIT\1-1-Picture.jpg 3
    To retrive and display i use this JSP code as--
    ------------------------UploadedPicture.jsp------------------------------
    <html>
    <head>
    </head>
    <body bgproperties="fixed" bgcolor="#CCFFFF">
    <%! int update=0; %>
    <%@ page import="java.util.*" %>
    <%@ page import="java.sql.*" %>
    <%@ page import="java.text.*" %>
    <%@ page import="java.io.*"%>
    <%@ page language = "java" %>
    <%@page import="javax.servlet.ServletOutputStream"%>
    <%
    try
    String path;
    path=request.getParameter("upload1");
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:itPlusElectronics","","");
    PreparedStatement pst = con.prepareStatement("SELECT * FROM graphics WHERE id ='3'");
    // pst.setString(3, id);
    ResultSet rs = pst.executeQuery();
    path=rs.getString("path");
    if(rs.next()) {
    byte[] bytearray = new byte[4096];
    int size=0;
    InputStream sImage;
    sImage = rs.getBinaryStream(1);
    response.reset();
    response.setContentType("image/jpeg");
    response.addHeader("Content-Disposition","filename=path");
    while((size=sImage.read(bytearray))!= -1 )
    response.getOutputStream().write(bytearray,0,size) ;
    response.flushBuffer();
    sImage.close();
    rs.close();
    catch(Exception e)
    %>
    </body>
    </html>
    Now after browsing a jpg image file from client side and pressing submit button ;
    I am unable display the image in the Upload.jsp file.Though I use
    <img src="UploadedPicture.jsp">image</img> HTML code in Upload.jsp
    file .
    Now I am unable to find out the mistakes which is needed for displaying the picture in the Upload.jsp page..
    If any one can help with the proper jsp code to retrive and display the image ,please please help me !!!!!!!!!!!!!!!!!!!!!!!!!!

    dketcham wrote:
    cotton.m wrote:
    >
    2) I'm looking at how you called stuff, and you're trying to call the jsp file as an image? That jsp isn't the source of the image, just a page linking to an image. I think if you really want to do things that way you're going to need to just include that jsp within the jsp you're calling it from (or you can do it the easy way, and if you have the information to get the path of the image you want, you could simply call the image from the first jsp you posted)This is incorrect.
    There are two JSPs. The second when called will (if it worked) return the source of an image as stored in the database.even when called with <img src=xx.jsp>??
    Yes.
    If any of what I say next seems obvious or otherwise negative I apologize, just trying to explain and I don't know what you know vs what you don't.
    The link in the src is just a URL not a filetype. So just because it ends with JSP does not mean it has to return HTML. The content type is determined by the browser using the Content-Type header returned by the server in the HTTP response. In this case the header is set to be a jpeg so that's what the browser will attempt to interpret the content part of the response as.
    So in fact one is not limited to just HTML or images but whatever content type you would like to return (that the browser can understand anyway). This could be HTML or it could be an image of some type or it could be a PDF or it could be an Excel spreadsheet. All you have to do in the JSP is set the header appropriately and then send content that is actually in that format.
    This does not just apply to JSP by the way but all other web programming languages. You can do similar things to produce the same results in PHP, Perl, ASP etc.
    The only JSP/Servlet complication is whether or not doing this in a JSP is a "good" idea but I am not an expert enough at that to make a definitive statement. Mostly though JDBC in a JSP is a no-no.

  • All content except for PDF are stuck in GenWWW - IBR IS converting them..

    Hello,
    We are having a serious issue with our UCM/IBR where all new documents except for PDF's are successfully converted (we confirmed this through IBR weblayout directory and log files) but they are never Released.
    We have tried the following:
    1. Reindexing
    2. Rebooting both servers (including admin server)
    We are using Direct PDFExport and Digital Media Graphics for conversion.
    The connection status is OK and there are no errors in the logs and I can't even begin to tell you what some of this means in the trace log.
    I don't usually say this but... Please help!!

    Guys. It DID go through IBR. The conversion files, such as the thumbnails and web renditions for images are all being created and the trace logs in IBR even confirm that they were successfully converted. The issue is NOT that files are not being converted, it is that they are not getting released from GenWWW. We have rebuilt the Index twice and rebooted the services on each box.
    Yes we are using PassThru for PDF's because there is no need to convert them. We are using Digital Media Graphics and PDFExport for the rest. This morning when we got in most of them had finally converted, but there are a few that are not, and we submitted some an hour ago and they are showing the same symptoms.
    I have noticed a couple of strange things from the trace logs, as well as the weblayout folder:
    1. The weblayout folder that contains the conversions in question from yesterday (there were about 3 dozen jpg's from the same folder) have something interesting going on. We recently renamed the parent folder from "Photos" to "Project Visuals," however within that weblayout folder there is ONLY a "Photos" folder - yet it contains all the newly converted files (which are in Project Visuals folder). I am thinking this might be a problem.
    2. In the IBR logs I notice at the beginning and end of the job the COPYJOB operation does not get passed a job id. The exact errors are:
    refinery/6     03.08 16:51:21.009     IdcServer-3047     entered m_postConvertedJobsTable edit with action: COPYJOBS; on jobID: <no id passed>
    refinery/6     03.08 16:51:36.219     IdcServer-3048     entered m_postConvertedJobsTable edit with action: COPYJOBS; on jobID: <no id passed>
    refinery/6     03.08 16:51:41.305     IdcServer-3049     entered m_postConvertedJobsTable edit with action: COPYJOBS; on jobID: <no id passed>
    refinery/6     03.08 16:51:41.352     IdcServer-3050     entered m_postConvertedJobsTable edit with action: COPYJOBS; on jobID: <no id passed>
    refinery/6     03.08 16:51:44.082     Job_10396_prod_ucm     starting conversion: DIGITAL MEDIA GRAPHICS; is subconversion: false
    refinery/6     03.08 16:51:44.082     Job_10396_prod_ucm     Script: TRUE
    refinery/6     03.08 16:51:44.082     Job_10396_prod_ucm     Evaluated to: TRUE
    refinery/6     03.08 16:51:44.082     Job_10396_prod_ucm     Script: DigitalGraphicRenditions
    refinery/6     03.08 16:51:44.082     Job_10396_prod_ucm     Evaluated to: DigitalGraphicRenditions
    refinery/6     03.08 16:51:44.082     Job_10396_prod_ucm     Starting step: DigitalGraphicRenditions
    refinery/6     03.08 16:51:44.082     Job_10396_prod_ucm     Script: onErrorFail, producesRequiredWebviewable...
    refinery/6     03.08 16:51:45.408     Job_10396_prod_ucm     Finished step: DigitalGraphicRenditions
    refinery/6     03.08 16:51:45.408     Job_10396_prod_ucm     Steps completed for Job: 10396
    refinery/6     03.08 16:51:45.408     Job_10396_prod_ucm     DigitalGraphicRenditions: 1: C:/app/oracle/product/fmw/USER_P~1/domains/prod_ibr_domain/ucm/ibr/vault/~temp/prod_ucm/10396/prod_032539~4.jpg
    refinery/6     03.08 16:51:45.408     Job_10396_prod_ucm     dConversionState = Converted
    refinery/6     03.08 16:51:45.408     Job_10396_prod_ucm     dConvMessage = Success
    refinery/6     03.08 16:51:45.408     Job_10396_prod_ucm     dFormat = image/jpeg
    refinery/6     03.08 16:51:45.408     Job_10396_prod_ucm     dWebExtension = jpg
    refinery/6     03.08 16:51:45.408     Job_10396_prod_ucm     RefineryConvertedFile = prod_032539~4.jpg
    refinery/6     03.08 16:51:45.408     Job_10396_prod_ucm     RefineryPrimaryConvertedPath = C:/app/oracle/product/fmw/USER_P~1/domains/prod_ibr_domain/ucm/ibr/vault/~temp/prod_ucm/10396/prod_032539~4.jpg
    refinery/6     03.08 16:51:45.408     Job_10396_prod_ucm     AdditionalRenditions = THUMBNAIL_PNG,ZIPRENDITIONS
    refinery/6     03.08 16:51:45.408     Job_10396_prod_ucm     finished conversion: DIGITAL MEDIA GRAPHICS; is subconversion: false
    refinery/6     03.08 16:51:49.136     QueueLockId_10396     entered m_postConvertedJobsTable edit with action: ADDJOB; on jobID: 10396
    refinery/6     03.08 16:51:51.429     IdcServer-3052     entered m_postConvertedJobsTable edit with action: COPYJOBS; on jobID: <no id passed>
    refinery/6     03.08 16:51:53.847     IdcServer-3054     entered m_postConvertedJobsTable edit with action: DELETEJOB; on jobID: 10396
    refinery/6     03.08 16:52:06.639     IdcServer-3059     entered m_postConvertedJobsTable edit with action: COPYJOBS; on jobID: <no id passed>As you can see the job has finished successfully from the log as well.
    Do any of you know what is the normal expected behavior for these two scenarios? Shouldn't the conversion process create a new folder and update all the references from the photos folder?
    I will continue with my troubleshooting as you have suggested. I appreciate the feedback.
    thank you
    s
    Edited by: SethBW on Mar 9, 2012 7:59 AM
    Edited by: SethBW on Mar 9, 2012 7:59 AM
    I'm not sure why but it won't let me get rid of the jive quote tag... that's a problem with this forum and the default output of the trace logs.
    Edited by: SethBW on Mar 9, 2012 8:21 AM

  • 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);
    }

Maybe you are looking for