Using ImageIcon load an image

Hi I'm having a lot of trouble getting the below code to work. Its copied out of my textbook and its supposed to load an image using the getImage method in the ImageIcon class. The strange thing is I have gotten this to work before, but after I installed Windows 2000 the image doesn't seem to load right anymore.
getWidth and getHeight - on the image afterwards returns -1.
Could this be windows 2000's problem? I'm pretty sure it isn't .. but when you run out of ideas, it feels good to put the blame on something other than yourself.
import java.awt.*;
import javax.swing.*;
import java.net.*;
public class DisplayImage extends JApplet
public void init()
ImageIcon icon = null;
try
icon = new ImageIcon(new URL(getCodeBase(), "Images/backTile.bmp"));
catch(MalformedURLException e)
System.out.println("Failed to create URL:\n"+e);
return;
int imageWidth = icon.getIconWidth();
int imageHeight = icon.getIconHeight();
resize(imageWidth, imageHeight);
ImagePanel imagePanel = new ImagePanel(icon.getImage());
getContentPane().add(imagePanel);
class ImagePanel extends JPanel
public ImagePanel(Image image)
this.image = image;
public void paint(Graphics g)
g.drawImage(image,0,0,this);
Image image;
Again thx a lot. I know its a lot of code to read. Any help at all would be much appreciated.

".bmp" ? Windows bitmap isn't a supported file type, you should save your image as .gif, .png, or as .jpg.

Similar Messages

  • Set "Referer" when loading an Image through Toolkit

    To load an Image using an HttpURLConnection, I use the abstract java.awt.Toolkit.getImage(URL url) method, which is implemented by sun.awt.windows.WToolkit. This method uses the HttpURLConnection to load the Image.
    The problem I have, is that I don't know how I can set the HTTP "Referer" request header. There is a method in the HttpURLConnection called setRequestProperty(String key, String value), which I could use, but I can't reach the HttpURLConnection being used to load the Image.
    I would consider another way to load Images, but that would mean quite a bit of refactoring. I would prefer not to use Reflection, though.

    I did look at the HttpsURLConnection (of which we also have our own implementation), but that still doesn't solve the problem, unfortunately.
    Is there maybe another way to load an image from an HttpURLConnection or HttpsURLConnection? If there's a way that I can provide or access the connection being used and still get an Image object, I would be a happy man!

  • Applet loading of images -- network or JAR approach faster?

    hi all,
    i'm stumped. my applet used to load images over the network. (it was actually designed by someone else.) yes, the applet used to load each image file independently over the network and incurred a network hit per image file.
    to avoid the overhead of a separate network connection for each image file, i bundled all the images into the same JAR file that contains the applet. yet, the loading time for the applet is somehow slower now. i'm totally mystified.
    i put the code for loading each image into a separate thread as well. here's the thread code:
    BEGIN CODE
    public class ImageLoaderThread extends Thread {
         private Hashtable images;
         private DesignApplet applet;
         public ImageLoaderThread(DesignApplet applet, Hashtable images, String imageFile) {
              super(imageFile);
              this.images = images;
              this.applet = applet;
         public void run() {
              try {
                   System.out.println("Starting to load image ...");
                   String imageFile = getName();
                   InputStream is = applet.getClass().getResourceAsStream(imageFile);
                   int arraySize = is.available() * 2; // CH: create extra space just in case
                   System.out.println("Image Loader Thread: " + imageFile + "bytes available: " + arraySize);
                   BufferedInputStream bis = new BufferedInputStream(is);
                   byte[] byBuf = new byte[arraySize]; // a buffer large enough for our image
                   int byteRead = bis.read(byBuf, 0, arraySize);
                   Image buttonImage = Toolkit.getDefaultToolkit().createImage(byBuf);
                   images.put(imageFile, buttonImage);
              catch(Exception e) {
                   System.out.println("Exception while loading: " + getName());
                   e.printStackTrace();
    END CODE
    imageFile is the name of an image file stored in the JAR file. it's not stored on the server anywhere, so i know the image is getting created from the JAR file. despite this, the speed of image creation seems tied to the network. in other words, when i attempt to load the applet over a slow link, it takes longer to load than over a fast link.
    any ideas what i'm doing wrong? i'm seriously stumped and could use help. my goals are to minimize loading time of the applet while minimizing network hits for the server.
    thanks!
    p.s. if you want to play w/ the applet, click on the following link and click the "Customize" button: http://www.cengraving.com/s/z/Photo-plaques/PP024.jsp

    Why are you using a thread to load each image why not just load the images in the gui thread?
    Each thread you create takes a finite time to be started and stopped. This will surely have added to the load and startup time.
    There is also blocking going on since using the Java Console I can see that each thread reports in sequence:
    "Starting to load image ..."
    And then after all threads have reported they are starting they then report in squence:
    Image Loader Thread: " + imageFile + "bytes available: " + arraySize information.
    This shows that there is at least some blocking going on with the threads.
    I don't think using separate threads to do the loading is helping at all. Just load them one after another in the same thread (the thread all your threads are being started from).
    The putting of the images into the images Hashtable will also be blocking since Hashtable is synchronized.

  • Loading an image from an arbitrary URL without using an ImageIcon

    Can anybody maybe point me in the direction of other (as in harder-to-use, but more flexible) ways to load an image from a URL?

    Interesting results:
    When I run this test code (the names have been changed to protect the innocent):
    package graphicstest;
    import javax.swing.*;
    import java.net.*;
    import javax.imageio.*;
    import java.awt.image.*;
    * <p>Title: </p>
    * <p>Description: </p>
    * <p>Copyright: Copyright (c) 2007</p>
    * <p>Company: </p>
    * @author not attributable
    * @version 1.0
    public class Foo
        extends JFrame {
      static ImageIcon ii;
      public Foo() {
        setSize(200,200);
        try {
          System.out.println("2=aborted; 8=complete; 4=errored; 1=loading");
          ii = new ImageIcon(new URL("http://intranet/part?FOO.JPG"));
          System.out.println("image load status: " + ii.getImageLoadStatus());
          getContentPane().add(new JLabel(ii));
          System.out.println("image load status: " + ii.getImageLoadStatus());
        }catch(Throwable t) {t.printStackTrace();}
      public static void main(String args[]) {
          Foo foo = new Foo();
          foo.setVisible(true);
          if (ii.getImageLoadStatus() == 4) {
            try {
              BufferedImage bi = ImageIO.read(new URL(
                    "http://intranet/part?FOO.JPG"));
              ii.setImage(bi);
              foo.validate();
              foo.repaint();
            } catch(Throwable t) {t.printStackTrace();};
    }. . . from a box that's not on the VPN, it blows up at the ImageIO.read() call (not unexpectedly). But if I run it from a box that's on the VPN, and able to access the URL, then it returns just fine from the ImageIO.read(), and I get a null pointer exception at the call to setImage().
    Clearly, this is trying to tell me SOMETHING, but I don't quite know WHAT.
    JHHL

  • Load image using the loader class problem

    Hi, I'm trying to load an image in a movieclip using using the following:
    Load_image_btn.addEventListener(MouseEvent.CLICK,Load_image);
    function Load_image(event:MouseEvent):void
        var my_loader:Loader = new Loader();
        my_loader.load(new URLRequest("C:\Users\Amanda\Desktop\picture1"));
        addChild(my_loader);
    When I enter just "picture1" for the location it works, but like this it is giving me the following error: Error #2000: No active security context.  How can I go about this, as I want to have a picture which in a separate location from that of the flash file?
    I would also like to have the image located in a particular location (x,y) of the movieclip, is this possible? thanks in advance.

    I am using the following code:
    function AddViewDetails(event:ListEvent):void
    var mc:MovieClip=new Additional_Req_Info();  // where Additional_Req_Info is the class name
    addChild(mc);
    var clickedName:String = event.currentTarget.name;
    trace (clickedName);      /////prints Current_Req_List
    var instanceName:String = clickedName + (Current_Req_List.selectedIndex + 1);
    trace (instanceName);  /////prints Current_Req_List1,  Current_Req_List2, etc depending on list item selected
    if(!getChildByName(instanceName)){
    var classRef:Class=Class(getDefinitionByName(instanceName));
    trace (classRef);   ////not printed
    var mc:MovieClip=new classRef();
    mc.name=instanceName;
    trace (mc.name);   ////not printed
    And its giving me the following error:
    ReferenceError: Error #1065: Variable Current_Req_List1 is not defined.
    at global/flash.utils::getDefinitionByName()
    at Websiteversion4_Scene1_fla::MainTimeline/AddViewDetails()[Websiteversion4_Scene1_fla.Main Timeline::frame1:185]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at fl.controls::SelectableList/handleCellRendererDoubleClick()
    How can I define the list items if they are dynamically generated i.e. at runtime? thanks!!!

  • Some email images do not show while using the icloud web app.  I can see the images on my IOS devices and in gmail but I only see a small gray box in the icloud web mail app.  Load HTML images is checked in preferences.

    Some email images do not show while using the icloud web app.  I can see the images on my IOS devices and in gmail but I only see a small gray box in the icloud web mail app.  Load HTML images is checked in preferences.  Is there a solution to this issue?

    I've seen the opposite issue.  My wife recieved an email with jpg attachments.  She couldn't see or print them on her iPhone 4S but they showed up fine in iCloud or in the mail app.  I had her forward the email to herself and then they showed up.  I assume there is an issue with how Apple is processing the attachments and resending causes them to get reformatted in a way that makes them easier to handle.
    So yeah.  Seems like some bugs.  Hope Apple fixes them soon.

  • Load Multiple Images in Crystal Report using Paths

    Hi Guys,
    I am currently in need of developing a new requirement for our company's client. We have to load multiple images using just link in Crystal Report. Let's say that the images are stored in a folder (e.g., C:\Datafolder\Images\) and i have to fetch two images to show in crystal report (say, C:\Datafolder\Images\imageval1 and C:\Datafolder\Images\imageval2). These are actually dynamically created and therefore the number of images are not known and so i have to iterate through the list of image links.
    Is it possible using merely crystal report and how?. If not, can I do it using Crystal Report SDK?. Any help will be appreciated. Please take note that we're also using C# in developing our software applications.
    Thanks and best regards.
    ---CHITO--

    There are also a number of KBAs:
    1296803 - How to add an image to a report using the Crystal Reports .NET inproc RAS SDK
    1199408 - How to load an image from disk into a dataset using CSharp (C#) in Visual Studio .NET
    Other related KBAs:
    1216239 - How to access a Crystal Report "Preview Picture" using the CR .NET or RAS .NET SDK?
    1373770 - How can I add a picture to a Crystal Reports subreport using the RAS .NET SDK?
    1320507 - How to change images dynamically in Crystal Reports based on parameter selection?
    And more. Please do use the search box in the top right corner. Simple search terms are best. E.g: 'crystal image net' or 'crystal image format formula', etc.
    - Ludek
    Senior Support Engineer AGS Product Support, Global Support Center Canada
    Follow us on Twitter

  • I cannot seem to load raw images into LR 2.5.  I've been using this for years.  I always load from memory card, but it gives me an unknown error message.  I tried to load from camera, hard drive, & external drive and still will not work.  I checked import

    I cannot seem to load raw images into LR 2.5.  I've been using this for years.  I always load from memory card, but it gives me an unknown error message.  I tried to load from camera, hard drive, & external drive and still will not work.  I checked import menu and nothing has changed.  I loaded the photos onto my tablet and images are fine, so do not feel it is the memory card.  Any thoughts?

    The error message probably said "unsupported or damaged"
    The T3 requires Lightroom 3.4.1 or later. You can either upgrade to a more current version of Lightroom (version 5.6 is the most recent) or you can use the free Adobe DNG Converter to convert the RAWs to DNG, which should import into Lightroom properly.

  • Load Multiple Images using link in Crystal Report

    Hi Guys,
    I am currently in need of developing a new requirement for our company's client. We have to load multiple images using just link in Crystal Report. Let's say that the images are stored in a folder (e.g., C:\Datafolder\Images\) and i have to fetch two images to show in crystal report (say, C:\Datafolder\Images\imageval1 and C:\Datafolder\Images\imageval2). These are actually dynamically created and therefore the number of images are not known and so i have to iterate through the list of image links.
    Is it possible using merely crystal report and how?. Please take note that we're also using C# in developing our software applications.
    Thanks and best regards.
    ---CHITO--

    Hi Chito,
    You cannot load multiple images dynamically. Using the 'graphic location' formula for the OLE Object, you can only point to a location that can load one image.
    For the second image, you'll need to manually insert another OLE Object and point the formula to the next image's location.
    You can try posting to the SAP Crystal Reports, version for Visual Studio space to find out whether this can be done using CR SDK.
    -Abhilash

  • Exception when loading an image in ImageIcon component

    Hello,
    I want to load an image whose name or path contains special character such as accents (a french name). So that generates an exception. For exemple for an image named caf�.jpeg I obtain this message :
    java.io.FileNotFoundException: /media/disk/images/caf��.jpeg (No such file or directory)
    Can you please help me.
    Thanks in advance.

    Can you store multiple images in memory and be able
    to reference them all individually, or is it better
    to store them in a construct, such as an array and
    then loop through that when attempting to match?I'm sorry but I don't understand the question. And does it
    have anything to do with images per se? Can it be generalized
    without losing its meaning:
    Can you store multiple objects in memory and be able
    to reference them all individually, or is it better
    to store them in a construct, such as an array and
    then loop through that when attempting to match?It seems to me that multiple objects should be stored in
    an appropriate collection, if that is what is required.
    Perhaps you need to say more about what you are trying to
    do, what your goal is, to make your question meaningful.

  • Complete beginners help.using ImageIcon and cant assign images

    how do assign the ImageIcon for the front and back to this class.i have two gif files in the same directory. to test the card class i want to press the flip button to display the front and then the back. i am making simple card game but am very new to this and am stumbling at the basics.any help much appreciated. here is my attempt at the code.
    ( havent put in the paint() )
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class JCard extends JComponent
    private int value;
    private ImageIcon FrontImg;
    private ImageIcon BackImg;
    private int size;
    private boolean faceup;
         public JCard()
    this.value= value;
    public int getValue()
    return value;
    //returns the width of the card
    public int getWidth()
    return getSize().width;
    //returns the height of the card
    public int getHeight()
    return getSize().height;
    //returns true if the card is face up
    public boolean faceup()
    return faceup;
    //flips the card
    public void flip()
    if(faceup)
    faceup = false;
    else
    faceup = true;
    repaint();
    public void setBackImg(ImageIcon img)
    BackImg = img;
    public void setFrontImg(ImageIcon img)
    FrontImg = img;
    public void paint(Graphics g)
    //test JCard
    import javax.swing.*;
    import java.awt.event.*;
    public class TestJCard extends JFrame implements ActionListener
         private JCard card = new JCard();
         private JButton b1 = new JButton("flip");
    public TestJCard()
    super();
    JPanel p = (JPanel)getContentPane();
    p.add("Center",card);
    p.add("South",b1);
    b1.addActionListener(this);
    public void actionPerformed(ActionEvent ae)
    card.flip();
    //** To close window**//
    class WindowHandler extends WindowAdapter
    public void windowClosing(WindowEvent we)
    we.getWindow().hide();
    System.exit(0);
         public static void main(String args[])
    TestJCard fm = new TestJCard();
    fm.setSize(300,300);
    fm.setVisible(true);

    I'm not sure if I understand exactly what you're asking, but if you're wondering how to create/initialize and ImageIcon from an image file on a local disk, I believe it is as simple as:
    ImageIcon i = new ImageIcon("path/filename.ext");
    note: the path can be relative (i.e. "images/pict1.gif")
    or explicit ("c:/project1/images/pict1.gif").
    Hope this is what you're looking for.

  • Loading an image into an Applet from a JAR file

    Hello everyone, hopefully a simple question for someone to help me with!
    Im trying to load some images into an applet, currently it uses the JApplet.getImage(url) method just before registering with a media tracker, which works but for the sake of efficiency I would prefer the images all to be contained in the jar file as oppossed to being loaded individually from the server.
    Say I have a class in a package eg, 'com.mydomain.myapplet.class.bin' and an images contained in the file structure 'com.mydomain.myapplet.images.img.gif' how do I load it (and waiting for it to be loaded before preceeding?
    I've seen lots of info of the web for this but much of it is very old (pre 2000) and im sure things have changed a little since then.
    Thanks for any help!

    I don't touch applets, so I can't help you there, but here's some Friday Fun: tracking image loading.
    import java.awt.*;
    import java.awt.image.*;
    import java.beans.*;
    import java.io.*;
    import java.net.*;
    import javax.imageio.*;
    import javax.imageio.event.*;
    import javax.imageio.stream.*;
    import javax.swing.*;
    public class ImageLoader extends SwingWorker<BufferedImage, Void> {
        private URL url;
        private JLabel target;
        private IIOReadProgressAdapter listener = new IIOReadProgressAdapter() {
            @Override public void imageProgress(ImageReader source, float percentageDone) {
                setProgress((int)percentageDone);
            @Override public void imageComplete(ImageReader source) {
                setProgress(100);
        public ImageLoader(URL url, JLabel target) {
            this.url = url;
            this.target = target;
        @Override protected BufferedImage doInBackground() throws IOException {
            ImageInputStream input = ImageIO.createImageInputStream(url.openStream());
            try {
                ImageReader reader = ImageIO.getImageReaders(input).next();
                reader.addIIOReadProgressListener(listener);
                reader.setInput(input);
                return reader.read(0);
            } finally {
                input.close();
        @Override protected void done() {
            try {
                target.setIcon(new ImageIcon(get()));
            } catch(Exception e) {
                JOptionPane.showMessageDialog(null, e, "Error", JOptionPane.ERROR_MESSAGE);
        //demo
        public static void main(String[] args) throws IOException {
            final URL url = new URL("http://blogs.sun.com/jag/resource/JagHeadshot.jpg");
            EventQueue.invokeLater(new Runnable(){
                public void run() {
                    launch(url);
        static void launch(URL url) {
            JLabel imageLabel = new JLabel();
            final JProgressBar progress = new JProgressBar();
            progress.setBorderPainted(true);
            progress.setStringPainted(true);
            JScrollPane scroller = new JScrollPane(imageLabel);
            scroller.setPreferredSize(new Dimension(800,600));
            JPanel content = new JPanel(new BorderLayout());
            content.add(scroller, BorderLayout.CENTER);
            content.add(progress, BorderLayout.SOUTH);
            JFrame f = new JFrame("ImageLoader");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setContentPane(content);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
            ImageLoader loader = new ImageLoader(url, imageLabel);
            loader.addPropertyChangeListener( new PropertyChangeListener() {
                 public  void propertyChange(PropertyChangeEvent evt) {
                     if ("progress".equals(evt.getPropertyName())) {
                         progress.setValue((Integer)evt.getNewValue());
                         System.out.println(evt.getNewValue());
                     } else if ("state".equals(evt.getPropertyName())) {
                         if (SwingWorker.StateValue.DONE == evt.getNewValue()) {
                             progress.setIndeterminate(true);
            loader.execute();
    abstract class IIOReadProgressAdapter implements IIOReadProgressListener {
        @Override public void imageComplete(ImageReader source) {}
        @Override public void imageProgress(ImageReader source, float percentageDone) {}
        @Override public void imageStarted(ImageReader source, int imageIndex) {}
        @Override public void readAborted(ImageReader source) {}
        @Override public void sequenceComplete(ImageReader source) {}
        @Override public void sequenceStarted(ImageReader source, int minIndex) {}
        @Override public void thumbnailComplete(ImageReader source) {}
        @Override public void thumbnailProgress(ImageReader source, float percentageDone) {}
        @Override public void thumbnailStarted(ImageReader source, int imageIndex, int thumbnailIndex) {}
    }

  • Error when trying to use ImageIcon

    Hi,
    I am trying to use an ImageIcon to store an icon for plugins so that they can customize their menu and toolbar entries. I use a generic class, PaletteClass, to design all the plugins, and then extend PaletteClass to create individual plugins.
    PaletteClass:
    public class PaletteClass implements ItemListener{
          * PaletteClass
          * Superclass for the palettes in iKalk
          * @author Nathan Jarus
          * @version 0.1
         JFrame frame = new JFrame();//Window
         GridBagLayout layout = new GridBagLayout();
         GridBagConstraints constraints = new GridBagConstraints();
         JPanel main = new JPanel(layout);
         JToggleButton cmdTop = new JToggleButton("Stick to Top");
         //iKalk interface variables
         static String description = "Unnamed Plugin"; //Name of plugin
         ImageIcon icon = new ImageIcon();  //icon of plugin
         static boolean state = true; //is it visible?
         //static JToggleButton button = new JToggleButton(description, icon, state);
         static JToggleButton button;
         //static JToggleButton button = new JToggleButton(description, state);
         JCheckBoxMenuItem menu = new JCheckBoxMenuItem(description, icon, state);
         //boolean caret = false;//Used in determining when to clear the text box
         //boolean clear = false;
         //double tmp = 0;//Used in calculations
         //char op = ' ';//Used in calculations
         //Constructor
         PaletteClass(iKalk ikalk){
              setIcon("/images/generic.gif",ikalk,this);
              menu.addItemListener(this);
              //button.addItemListener(this);
              frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
              //frame.setLayout(new BorderLayout());
              try {
                   UIManager.setLookAndFeel(iKalk.getLF());
              } catch (UnsupportedLookAndFeelException e) {
                   JOptionPane.showMessageDialog(null,"How on earth did you get this message?  Check for a virus.  /n/nYour JRE has changed in the milliseconds that passed between the original loading of the program and this window loading!", "A message you should not be seeing", JOptionPane.ERROR_MESSAGE);
              constraints.fill = GridBagConstraints.BOTH;
              constraints.anchor = GridBagConstraints.CENTER;
              //Stick to Top button
              cmdTop.addItemListener(this);
              addComp(main, cmdTop, layout, constraints, 0, 0, 1, 1, 0, 100);
              //frame.add(main, BorderLayout.NORTH);
              //frame.setVisible(true);
              init();
              //updateGFX();
              //button = new JToggleButton(description, icon, state);
              //setIcon("/images/generic.gif",ikalk,this);
         public void init(){
              frame.setLayout(new BorderLayout());
              frame.add(main, BorderLayout.NORTH);
         //Item listener
         public void itemStateChanged(ItemEvent ie) {
              if(ie.getSource().equals(cmdTop)){
                   if (frame.isAlwaysOnTop()){
                        frame.setAlwaysOnTop(false);
                   else {
                        frame.setAlwaysOnTop(true);
              else if(ie.getSource().equals(button)){
                   if(button.isSelected()){
                        setVisible(true);
                   else{
                        setVisible(false);
              else if(ie.getSource().equals(menu)){
                   if(menu.isSelected()){
                        setVisible(true);
                   else{
                        setVisible(false);
         //Update the L&F
         public void updateGFX(){
              setVisible(false);
              SwingUtilities.updateComponentTreeUI(frame);
              SwingUtilities.updateComponentTreeUI(main);
              setVisible(true);
         //Decide whether or not the window is onscreen
         public boolean isShowing(){
              return frame.isVisible();
         public void setVisible(boolean v){
              frame.setVisible(v);
              state = isShowing();
         public void setVisible(){
              frame.setVisible(true);
              state = isShowing();
         /*Add a component to the gridbag layout
          *Args:
          *JPanel to                                   the JPanel to add the item to
          *Component what                         what to add
          *GridBagLayout layout                    the layout to add it to
          *GridBagConstraints constraints     the constraints to modify
          *int row                                   the row to add it to
          *int column                              the column to add it to
          *int numRows                              the number of rows the item crosses
          *int numCols                              the number of columns the item crosses
          *int weightX                              the x-weight of the item
          *int weightY                              the y-weight of the item
         public void addComp(JPanel to, Component what, GridBagLayout layout, GridBagConstraints constraints, int row, int column, int numRows, int numCols, int weightX, int weightY){
              //Set the constraint parameters
              constraints.gridx = column;
              constraints.gridy = row;
              constraints.gridwidth = numCols;
              constraints.gridheight = numRows;
              constraints.weightx = weightX;
              constraints.weighty = weightY;
              //Set these constraints in the layout
              layout.setConstraints(what, constraints);
              //Add the component
              to.add(what);
         public void setIcon(String path, iKalk ikalk, PaletteClass parent){
              parent.icon = new ImageIcon(ikalk.getClass().getResource(path));
    }This is one of the classes that I have trouble with:
    NumberPad:
    public class NumberPad extends PaletteClass implements ActionListener{
         //Set up the objects so that I can access them from another method
         public NumberPad(iKalk ikalk){
              super(ikalk);
    //Set the description
              description = "Number Pad";
              //setIcon("/images/NumberPad.gif", ikalk, this);
              button = new JToggleButton(description, icon, state);
    //Set up the frame
              try {
                   UIManager.setLookAndFeel(iKalk.getLF());
              } catch (UnsupportedLookAndFeelException e) {
                   //JOptionPane.showMessageDialog(null,"How on earth did you get this message?  Check for a virus.  /n/nYour JRE has changed in the milliseconds that passed between the original loading of the program and this window loading!", "A message you should not be seeing", JOptionPane.ERROR_MESSAGE);
              frame.setSize(155,160);
              frame.setLocation(500,500);
              frame.setTitle(description);
              updateGFX();
    //Set up the number entry pad
              JPanel panNumbers = new JPanel(new GridLayout(4,3));
              JButton cmd0 = new JButton("0");
              JButton cmd1 = new JButton("1");
              JButton cmd2 = new JButton("2");
              JButton cmd3 = new JButton("3");
              JButton cmd4 = new JButton("4");
              JButton cmd5 = new JButton("5");
              JButton cmd6 = new JButton("6");
              JButton cmd7 = new JButton("7");
              JButton cmd8 = new JButton("8");
              JButton cmd9 = new JButton("9");
              JButton cmdDec = new JButton(".");
              JButton cmdPM = new JButton("+/-");
              cmd0.addActionListener(this);
              cmd1.addActionListener(this);
              cmd2.addActionListener(this);
              cmd3.addActionListener(this);
              cmd4.addActionListener(this);
              cmd5.addActionListener(this);
              cmd6.addActionListener(this);
              cmd7.addActionListener(this);
              cmd8.addActionListener(this);
              cmd9.addActionListener(this);
              cmdDec.addActionListener(this);
              cmdPM.addActionListener(this);
              panNumbers.add(cmd7);
              panNumbers.add(cmd8);
              panNumbers.add(cmd9);
              panNumbers.add(cmd4);
              panNumbers.add(cmd5);
              panNumbers.add(cmd6);
              panNumbers.add(cmd1);
              panNumbers.add(cmd2);
              panNumbers.add(cmd3);
              panNumbers.add(cmd0);
              panNumbers.add(cmdDec);
              panNumbers.add(cmdPM);
              panNumbers.setVisible(true);
    //Final adding and init
              super.addComp(main, panNumbers, layout, constraints, 1, 0, 4, 1, 0, 0);
              //super.setVisible();
              setIcon("/images/NumberPad.gif", ikalk, this);
         public void actionPerformed(ActionEvent ae) {
              if(ae.getActionCommand().equals("1")){
                   Functions.addOne();
              else if(ae.getActionCommand().equals("2")){
                   Functions.addTwo();
              else if(ae.getActionCommand().equals("3")){
                   Functions.addThree();
              else if(ae.getActionCommand().equals("4")){
                   Functions.addFour();
              else if(ae.getActionCommand().equals("5")){
                   Functions.addFive();
              else if(ae.getActionCommand().equals("6")){
                   Functions.addSix();
              else if(ae.getActionCommand().equals("7")){
                   Functions.addSeven();
              else if(ae.getActionCommand().equals("8")){
                   Functions.addEight();
              else if(ae.getActionCommand().equals("9")){
                   Functions.addNine();
              else if(ae.getActionCommand().equals("0")){
                   Functions.addZero();
              else if(ae.getActionCommand().equals(".")){
                   Functions.addDec();
              else if(ae.getActionCommand().equals("+/-")){
                   Functions.PlusMins();
         /*public void init(){
         public void main(String [] args){
    }This is the code I use to load the plugins:
    void addPlugin(PaletteClass plugin){
              //pluginsVector.addElement(plugin);
              //plugin.setVisible();
              //toolMain.add(PaletteClass.button);
              pluginsVector.addElement(plugin);
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        toolMain.add(PaletteClass.button);
         }When I load this code, I get the following error (in Eclipse SDK):
    java.lang.reflect.InvocationTargetException
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
         at java.lang.reflect.Constructor.newInstance(Unknown Source)
         at iKalk.loadPlugin(iKalk.java:587)
         at iKalk.loadPlugins(iKalk.java:578)
         at iKalk.<init>(iKalk.java:466)
         at iKalk$4.run(iKalk.java:563)
         at java.awt.event.InvocationEvent.dispatch(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: java.lang.NullPointerException
         at javax.swing.ImageIcon.<init>(Unknown Source)
         at PaletteClass.setIcon(PaletteClass.java:172)
         at NumberPad.<init>(NumberPad.java:82)
         ... 15 more
    If anyone knows what I am doing wrong, I'd like to know. I've tried several ways to fix it (as you can probably tell from the commented out code), but none of them worked.
    Sorry if my code isn't the cleanest; it's still in development =]
    PS: is it just me or does the code button in the post dialog still not work correctly?
    Thanks,
    LinuxMercedes

    Sorry for all the code. Here's a truncated version:
    PaletteClass:
    public class PaletteClass implements ItemListener{
         JFrame frame = new JFrame();//Window
         GridBagLayout layout = new GridBagLayout();
         GridBagConstraints constraints = new GridBagConstraints();
         JPanel main = new JPanel(layout);
         JToggleButton cmdTop = new JToggleButton("Stick to Top");
         static String description = "Unnamed Plugin"; //Name of plugin
         ImageIcon icon = new ImageIcon();  //icon of plugin
         static boolean state = true; //is it visible?
         static JToggleButton button;
         JCheckBoxMenuItem menu = new JCheckBoxMenuItem(description, icon, state);
         PaletteClass(iKalk ikalk){
              setIcon("/images/generic.gif",ikalk,this);
              init();
         public void init(){
              frame.setLayout(new BorderLayout());
              frame.add(main, BorderLayout.NORTH);
         public void setIcon(String path, iKalk ikalk, PaletteClass parent){
              parent.icon = new ImageIcon(ikalk.getClass().getResource(path));
    }NumberPad:
    public class NumberPad extends PaletteClass implements ActionListener{
         public NumberPad(iKalk ikalk){
              super(ikalk);
    //Set the description
              description = "Number Pad";
              button = new JToggleButton(description, icon, state);
              setIcon("/images/NumberPad.gif", ikalk, this);
    }Code I use to load Plugins:
    void addPlugin(PaletteClass plugin){
              pluginsVector.addElement(plugin);
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        toolMain.add(PaletteClass.button);
    }Oh yeah, and please don't go using this code in your projects without asking =]
    Thanks (and my apologies again),
    LinuxMercedes

  • How  can I  load an  image  in a scene?

    I want to load an image in a scene and I have tried it using the
    steve morris example( HAVI example ) , I am using a STB and when I send my xlet I don�t see this imagen at the tv.
    Source code is available from
    http://www.interactivetvweb.org/resources/code/havi/HaviXlet.zip
    Somebody knows another way to do it ???

    I assume you mean a JLabel as an AWT Label cannot display an Image.
    // POINT THE IMAGE BACK TO THE SERVER FROM WHICH THE APPLET WAS DOWNLOADED
    // BY USING GETCODEBASE(). OMIT THAT AND YOU WILL SEE THAT YOU GET A SECURITY
    // EXCEPTION AS THE APPLET WILL TRY TO LOCTE THE IMAGE ON THE LOCAL MACHINE AND
    // APPLETS BY DEFAULT CANNOT ACCESS RESOURCES ON THE CLIENT
    // assumes .gif file exists in same directory as HTML running the Applet
    Image image = getImage(getCodeBase(), "ImageName.gif");
    ImageIcon icon = new ImageIcon(image);
    JLabel - new JLabel(icon);
    // check out the getScaledInstance() method of Image class to resize your image

  • (newbie) - Loading an image in JFrame

    Hi All,
    I have a problem with loading an image on JPanel. Can somebody explain the procedure? Should I use a canvas or something?
    Thanks,
    Deepak

    kanad wrote:
    Try this
    ImageIcon icon = new ImageIcon("backUp.gif");
    JPanel panel = new JPanel()
    protected void paintComponent(Graphics g)
    g.drawImage(img.getImage(), 0, 0, null);
    super.paintComponent(g);
    If you're going to go the "custom JPanel" route as above, don't create an ImageIcon just for its Image. Instead grab a BufferedImage from javax.imageio.ImageIO and draw that directly in your paintComponent() override.

Maybe you are looking for

  • How to get Description of parameter filed in Crystal report 2008

    Hi expert, I am creating a crystal report from Query ,which is created in BEX    Query designer 7. In query designer i have some selection variable. The requirement from clint is that they want to see what value is selected for all  variable. when i

  • HELP my ipod keeps going into restore mode

    hi i have a problem with my ipod touch 2nd generation firmware 3.1.2. it keeps going into restore mode randomly when i play with ir or use it. i upgraded and downgrade and nothing seems to work. i think there is a problem with the hardware! oh and wh

  • Payment run error

    Hi All, When i run payment run Vendor is always separated into few line items...Why they cannot be combined together?? Thanks Rafi

  • AP Journal Import Error

    Hi all, While running process to import journal error occured. Description of error are as below: 1) User run ACCOUNTS PAYABLE JOURNAL ENTRY EXCEPTION REPORT, run completed with no error. 2) The follow up auto run of JOURNAL IMPORT EXECUTION REPORT w

  • Is it possible to print a document exactly as it appears on the screen?

    Like the topic question asks, is it possible to print a document exactly as it appears on the screen? I'm fairly new to indesign and I designed my company's manual recently, taking us away from doing so in Word. I fear I may have made a very amateuri