Adding image to JDialog in Applet

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

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

Similar Messages

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

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

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

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

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

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

  • Adding Images to the List component

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

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

  • Create Image from Stream in Applet via Servlet

    First of all, I apologize if this isn't posted to the proper forum, as I am dealing with several topics here. I think this is more of an Image and I/O problem than Applet/Servlet problem, so I thought this forum would be most appropriate. It's funny...I've been developing Java for over 4 years and this is my first post to the forums! :D
    The problem is I need to retrieve a map image (JPEG, GIF, etc) from an Open GIS Consortium (OGC) Web Map Server (WMS) and display that image in an OpenMap Applet as a layer. Due to the security constraints on Applets (e.g., can't connect to a server other than that from which it originated), I obviously just can't have the Applet create an ImageIcon from a URL. The OpenMap applet will need to connect to many remote WMS compliant servers.
    The first solution I devised is for the applet to pass the String URL to a servlet as a parameter, the servlet will then instantiate the URL and also create the ImageIcon. Then, I pass the ImageIcon back to the Applet as a serialized object. That works fine...no problems there.
    The second solution that I wanted to try was to come up with a more generic and reusable approach, in which I could pass a URL to a servlet, and simply return a stream, and allow the applet to process that stream as it needs, assuming it would know what it was getting from that URL. This would be more usable than the specific approach of only allowing ImageIcon retrieval. I suppose this is actually more of a proxy. The problem is that the first few "lines" of the image are fine (the first array of buffered bytes, it seems) but the rest is garbled and pixelated, and I don't know why. Moreover, the corruption of the image differs every time I query the server.
    Here are the relevant code snippets:
    =====================Servlet====================
        /* Get the URL String from the request parameters; This is a WMS
         * HTTP request such as follows:
         * http://www.geographynetwork.com/servlet/com.esri.wms.Esrimap?
         *      VERSION=1.1.0&REQUEST=GetMap&SRS=EPSG:4326&
         *      BBOX=-111.11361,3.5885315,-48.345818,71.141304&
         *      HEIGHT=480&...more params...
         * It returns an image (JPEG, JPG, GIF, etc.)
        String urlString =
            URLDecoder.decode(request.getParameter("wmsServer"),
                              "UTF-8");
        URL url = new URL(urlString);
        log("Request parameter: wmsServer = " + urlString);
        //Open and instantiate the streams
        InputStream urlInputStream = url.openStream();
        BufferedInputStream bis = new
            BufferedInputStream(urlInputStream);
        BufferedOutputStream bos = new
            BufferedOutputStream(response.getOutputStream());
        //Read the bytes from the in-stream, and immediately write them
        //out to the out-stream
        int read = 0;
        byte[] buffer = new byte[1024];
        while((read = bis.read(buffer, 0, buffer.length)) != -1) {
            bos.write(buffer, 0, buffer.length);
        //Flush and close
        bos.flush();
        urlInputStream.close();
        bis.close();
        bos.close();
        .=====================Applet=====================
        //Connect to the Servlet
        URLConnection conn = url.openConnection();
        conn.setUseCaches(false);
        conn.setRequestProperty("header", "value");
        conn.setDoOutput(true);
        //Write the encoded WMS HTTP request
        BufferedWriter out =
            new BufferedWriter( new OutputStreamWriter(
                conn.getOutputStream() ) );
        out.write("wmsServer=" + URLEncoder.encode(urlString, "UTF-8"));
        out.flush();
        out.close();
        //Setup the streams to process the servlet response
        BufferedInputStream bis = new
            BufferedInputStream(conn.getInputStream());
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        //Read the bytes and immediately write to the out-stream
        int read = 0;
        byte[] buffer = new byte[1024];
        while((read = bis.read(buffer, 0, buffer.length)) != -1) {
            bos.write(buffer, 0, buffer.length);
        //Flush and close
        bis.close();</code>
        bos.flush();</code>
        byte[] imageBytes = bos.toByteArray();
        //Create the Image/ImageIcon
        Toolkit tk = Toolkit.getDefaultToolkit();
        Image image = tk.createImage(imageBytes);
        imageIcon = new ImageIcon(image);
        Could this be an offset problem in my buffers? Is there some sort of encoding/decoding I am missing somewhere?
    Thanks!
    Ben

    Without having a probing look, I was wondering why you do the following...
    while((read = bis.read(buffer, 0, buffer.length)) != -1) {
    bos.write(buffer, 0, buffer.length);
    while((read = bis.read(buffer, 0, buffer.length)) != -1) {
    bos.write(buffer, 0, buffer.length);
    }Your int 'read' holds the number of bytes read in but you then specify buffer.length in your write methods?!? why not use read? otherwise you will be writing the end of the buffer to your stream which contains random memory addresses. I think thats right anyway...
    Rob.

  • Adding images and buttons without a frame appearing

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

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

  • How draw image into frame in applet

    How draw image into frame in applet.Please give my simple example code.

    http://search.java.sun.com/search/java/index.jsp?qt=%2Bdraw+%2Bimage+%2Bpanel+%2Bhow&nh=10&qp=&rf=1&since=&country=&language=&charset=&variant=&col=javaforums

  • Background layer seizes added images.

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

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

  • Adding Image to Search Results

    Hi
    I am dire need of adding images to search results, particularly the thumb of the resulting product(s). The tags TAG_NAME and TAG_DESCRIPTION work, but TAG_SMALLIMAGE doesn't. Any help would be much appreciated.
    Thanks, Teejay

    The CSS in http://dandeliongiftshop.businesscatalyst.com/StyleSheets/ModuleStyleSheets.css is causing that overlap.
    Search for the below style rule in the above CSS file and make suggested modifications:
    .cataloguetitle {
        color: #732772;    font-family: Arial,Helvetica,sans-serif;
        font-size: 14px;
        font-style: normal;
        font-weight: normal;
        position: fixed;          --remove this
        display: block;          --add this
        text-align: center;     --remove this
        text-align: left;          --add this
    Should look better.

  • Adding Image problems

    Having some problems adding images.
    I was able to add the Ubuntu server image mentioned in the install guide and it is working 
    It appears on the nodes palette and I can create a topology with it and boot it.
    I was also able to add CSR image csr1000v-universalk9.03.13.00a.S.154-3.S0a-ext.qcow2 to the server.  
    However the CSR icon isn't available on the node palette.  How do I fix this?
    How to add other vmdk or ovf style images?  
    I have a network emulator that runs as a VM and comes as a vmdk.   I tried installing it and I get the following message ...  -Cannot create image "server-DummyCloud": Failed to convert image to QCOW2: Command '['qemu-img', 'convert', '-O', 'qcow2', '/tmp/tmpnfp_m_', '/tmp/tmpWk3al7']' returned non-zero exit status 1
    Where can I find compatible NXos images?  

    No change.
    Still get the message ..
    Cannot create image "server-DummyCloud": Failed to convert image to QCOW2: Command '['qemu-img', 'convert', '-O', 'qcow2', '/home/virl/dc.vmdk', '/tmp/tmpmgCkzK']' returned non-zero exit status 1
    I"ll open a tac case.

  • Adding images to a slide show

    I'm sure this has been asked a bazillion times here but I'm
    so new to Flash (we're talking a couple of days) that I wouldn't
    know what to search on much less what question(s) to ask. That
    having been said I'm tasked with adding images to an existing Flash
    site that has 4 slide shows (it's for a photographer). I have all
    of the .fla files and I can successfully change an image but when
    it plays it's taller than the other existing images (even though
    they are the same height in pixels) and I'm sure fixing that is
    just a couple of clicks.
    He said with false self-confidence...
    I have other, more specific, questions but it's better to ask
    them in
    this
    image to be more clear about what I'm referring to (without
    knowing the correct terminology).
    I know Photoshop, ImageReady, Illustrator and GoLive (so I'm
    no knucklehead) but Flash is a whole new ball game so I apologize
    for my ignorance. Once I get up to speed with Flash I won't be
    asking dumb stuff like this.
    As a sidebar question what's the best way to get up to speed
    with Flash? Is Lynda.com any good?
    TIA

      I had to restart and opened the file. It asked me if I wanted to try to recover the operations in process before. I said yes. Then it gave me this error which was similar to one of the first two errors I got but did not write down.
    [SQLC/interOpen] SQLError: ‘Error #3125: Unable to open the database file.’, details: ‘Connection closed.’,operation: ‘open’, detailID:’1001’

  • Adding images files to DVD-ROM

    By adding image files to the dvd-rom when burning my slideshow and movie. Can the photos be put on a desktop for printing after burn is done?

    There's a nice option to add whatever files you choose to the DVD-ROM area using the command to Edit DVD-ROM. Here are instructions:
    http://docs.info.apple.com/article.html?path=iDVD/7.0/en/6693.html
    and a related thread:
    http://discussions.apple.com/thread.jspa?threadID=2136021
    John

  • How can I upload a (image) file through an applet ?

    How can I upload a (image) file through an applet ?

    have a look at http://www.haller-systemservice.net/jupload/
    i'm using Apache Jakarta HTTPClient to create a new HTTP connection to the webserver and sending a new POST request, which holds the image file. (So it's RFC1867 conform)
    there is also an open source implementation of such an applet on sourceforge. it's also called JUpload, but i think it's not maintained any more.

  • Adding images to a ListBox in Applet

    Hi,
    I wanted to add images to an Listbox as that of an Yahoo IM or AOL (IM) has. Do any one have any idea? Here is my code for Java, Please tell me where should I have to correct my code so that I can achieve such a thing. or if you do have time, please help me by giving that code..
    Thanks in advance.
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    public class AddImage extends Applet
         Image im,im1,im2 =null;
         Panel p;
         List l;
         Choice choice;
         Button b,b1,b2;
         public void init()
              l = new List();
              p = new Panel();
              choice = new Choice();
              im = getImage(getCodeBase(),"yahoosad.jpg");
              im1 = getImage(getCodeBase(),"yahoobye.jpg");
              im2 = getImage(getCodeBase(),"yahoodevil.jpg");
              MediaTracker mt = new MediaTracker(this);
              mt.addImage(im,0);
              mt.addImage(im,1);
              mt.addImage(im,2);
              try
                   mt.waitForID(0);
              catch(Exception e)
                   e.printStackTrace();
         public void paint(Graphics g)
              if(im != null)
                   g.drawImage(im,0,0,this);
                   g.drawImage(im1,20,20,this);
                   g.drawImage(im2,40,40,this);
    Regards
    Uma

    here is a snippet of a program that I used to add a .gif image to my applet screen. Hope this helps
    public void paint(Graphics g){
         Toolkit kit = Toolkit.getDefaultToolkit();
         Image imageA = kit.getImage("d:\\\\javaproj\\javalab\\abbott.gif");
         g.drawImage(imageA, 555, 5, 50, 50, this);
    [email protected]

  • Adding an image in a java applet

    Hey everyone... I am using Jbuilder and trying to add an image or background image in my applet. The image is in the folder the java file runs out of. I would really appreciate it if anyone could help me..

    I use this to add an image that I have saved in the applet folder
    Image image;
    public void init() {
    image = getImage(getDocumentBase(), "auburn.jpg");
    and I get this error when I try to run it in Jbuilder:
    java.lang.NullPointerException
         at java.applet.Applet.getDocumentBase(Applet.java:125)
         at JavaProject.<init>(JavaProject.java:103)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
         at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
         at java.lang.Class.newInstance0(Class.java:308)
         at java.lang.Class.newInstance(Class.java:261)
         at sun.applet.AppletPanel.createApplet(AppletPanel.java:617)
         at sun.applet.AppletPanel.runLoader(AppletPanel.java:546)
         at sun.applet.AppletPanel.run(AppletPanel.java:298)
         at java.lang.Thread.run(Thread.java:534)
    What could be the problem?

Maybe you are looking for

  • How do I merge my iTunes libraries and make them accessible from multiple Systems?

    Our family has several Macs using several versions of OSX. My Music collection, mostly converted from my large collection of CDs, is scattered across all the Macs and several hard drives with Systems running OSX 10.6.8, 10.8.5 and 10.9.4. The older M

  • Manual backup problem to Mac with iPhone 5

    Hello, I've been trying to do a manual backup of my iPhone 5 to my Mac, but I keep getting an error message. I had even erased the phone and started over (to clear memory as well) but even that didn't help. I have the latest iOS installed (6.1.4). Ca

  • JavaMail NoClassDefFoundError

    The following code complies OK but won't run. I get a ava.lang.NoClassDefFoundError: . What's my problem? import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; public class SendMail { public static void main (String[] args)

  • CVI aborts with no warning when compiling

    When I compile a simple instrument driver with the CTRL-K shortcut in CVI 2009 (9.1) it aborts CVI without warning No popup, no nothing. All I had done was delete a typedef in the driver file for a structure containing GPIB configuration info. After

  • Realtek Audio v 6.0.1.7040 - 5.10.0.7040 - gga109ww

    Hi friends, I m T430 and Win8.1 x64 and after installed this update "Realtek Audio v 6.0.1.7040 - 5.10.0.7040 - gga109ww" I do not see the Dolby Advanced Audio v2 anymore.! I tried to installed Dolby Advanced Audio v2 manually but it seems not to be