Displaying a BufferdImage in an Applet

Hi all,
I am trying to display a BufferedImage, stored on a host computer, in an applet that will be viewed over the internet. The applet works fine when I run it in an appletviewer, but when I put it in an html file the image doesn't show up. Is there some other way to pre-load the image into the applet or something? I can do everything else fine once I have the image file buffered into the applet, using ImageIO. The image will not have to change or anything unusual, I just want it available to the applet. It will be stored in the same directory as the applet.
Thanks in advance.

Ottobonn wrote:
OK, here is the full description of my situation:
I have an applet, that will be stored on a server. In the same directory as the applet, I will also have a jpeg image, that the applet will end up using. However, I am having trouble getting the image into my program. I have tried ImageIO's read() method, and I have also tried getImage(URL location, String imgName)
I haven't been able to get the image with either of these successfully, and I am wondering if there is a quick way to simply create a BufferedImage object out of the image file in the local directory.
The applet runs fine in an appletviewer, or when instantiated and put in an application's frame. However, when the applet is put in an html file, it can't access the image it needs anymore. Here is an example of what I have tried, using ImageIO:
BufferedImage puzzleImage;
File imageFile = new File("image.jpg");
ImageIO imageGetter = new ImageIO();
Uh...That's not a URL, that's a File object. The File object looks on the user's own machine.
Also, you don't need to instantiate ImageIO. The methods you'll use are static.
try{
puzzleImage = imageGetter.read(imageFile);
}catch(Exception e){}And don't catch exceptions silently.
I think you want something more like this:
BufferedImage puzzleImage;
try {
   puzzleImage = ImageIO.read(this.getClass().getResource("image.jpg"));
} catch(Exception e) {
    e.printStackTrace();
}

Similar Messages

  • Signature Pad not displayed in IP14 (Signature Render Applet)

    After completing the setup detailed by Oracle to implement digital signature for non-pharma application (DOC ID 1980192.1 and DOC ID 1911649.1) we are able to paint the signature and save it in Singature Applet but it's not displayed in the Signature Render Applet.
    Application Setup: IP14 + (Firefox or Chrome)

    Hi,
    I have found information below in Doc ID 1911649.1 which seems to be similar with the problem you are facing:
    - While displaying back the signature (rendering), signature doesn't display by itself. There is a refresh issue which is handled by bug 18836527- SIGNATURE APPLET DOES NOT REFRESH WHEN ITERATING THROUGH RECORDS IN OPENUI (Implemented in 8.1.1.15_8.2.2.15). The current workaround is to reload the browser manually. After reloading the browser, signature is visible on the UI. The refresh issue has been requested to be fixed through the child Bug 19248616 which has been fixed in Patchset 16.
    Installation instruction for Patchset 5 in Doc ID 1614310.1 has information below:
    IN THE OPEN UI APPLICATION, THE SIGNATURE APPLET DOES NOT REFRESH AS USERS SCROLL THROUGH RECORDS
    20204194
    Please confirm if you have applied Patchset 5 in your environment.
    Thank you,
    WSiebel

  • Displaying an image in an applet

    hi there - can anyone tell me why the following code only displays the image through the applet viewer but when i load it in a browser it just displays a grey square the same size as the image i'm trying to load?! many thanks.
    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(), "map.jpg"));
              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;

    Rat fans!

  • How can I display some OrdImages using a Applet in html or Jsp?

    hi
    I want to use a applet to display some images retrieved from intermedia OrdImage Object.
    Now ,I know that a applet can display some image objects or some images with their own filepaths. But we can get ordimag objects from Oracle database.And we can image data or image properties by ordimage java mathod. It is in html/Jsp environment. So how can I transform from ordimage to applet?? I appreciate someone who can help me!
    Bill

    Do you mean applet or Servlet?
    An Applet is java code that is downloaded over the web and runs in a web browser environment. Is this what you are doing?
    I suspect you are really talking about servlet/JSP environments, and the ability to include images from the database in a web page.
    In either case (applet or servlet), you want to be able to access images via a URL. For a Servlet/JSP/web page, this URL will be specified in a HTML <IMG> tag with a key as a parameter to the image you wish to view. Images are not in-line downloaded in a web page. They are access after the HTML is loaded, and are accessed with URLs, sometimes relative URLs rather than fully specified URLs.
    To deliver images to the web from the database using the PL/SQL gateway and iAS, where the procedures are generated by a wizard, see:
    http://otn.oracle.com/software/products/intermedia/htdocs/descriptions/imedia_code_wizard.html
    You can create a simple servlet (JSPs can not deliver binary data) that delivers database images using java classes. See:
    http://otn.oracle.com/software/products/intermedia/htdocs/descriptions/servlets_jsp.html
    http://otn.oracle.com/sample_code/products/intermedia/htdocs/intermedia_servlet_jsp_samples/imedia_servlet_jsp_readme.htm
    for a sample.

  • How can I modify this code to display an image in an applet?

    Sorry, I'm almost positive this is absolutely incorrect, but here is what I have so far:
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.io.*;
    import javax.imageio.*;
    import javax.swing.*;
    public class Blackberry extends JApplet implements ActionListener
         Image image;
        public void init()
            //image = getImage(getDocumentBase(), "bluespace.png");
            try { image = ImageIO.read(new File("bluespace.png")); }
              catch (IOException e) { }
        public void paint(Graphics g)
            g.drawImage(image, 0, 0, this);
    }There are no errors given when run as an applet in Eclipse, it just displays a blank window.

    Here's a small example of a JPanel that draws an image:
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Image;
    import javax.swing.JPanel;
    public class ShowImageJPanel extends JPanel
      private Image image;
      public ShowImageJPanel(Image image)
        this.image = image;
        Dimension size = new Dimension(
            image.getWidth(this),
            image.getHeight(this));
        setPreferredSize(size);
      @Override
      protected void paintComponent(Graphics g)
        super.paintComponent(g);
        if (image != null)
          g.drawImage(image, 0, 0, this);
    }and a JApplet that adds this JPanel into its contentPane:
    import java.awt.Image;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import javax.swing.JApplet;
    public class ShowImageApplet extends JApplet
      private static final String IMAGE_PATH = "images/SunSteinSmall.png";
      public void init()
        try
          javax.swing.SwingUtilities.invokeAndWait(new Runnable()
            public void run()
              createGUI();
        catch (Exception e)
          System.err.println("createGUI didn't successfully complete");
      private void createGUI()
        try
          Image image = ImageIO.read(getClass().getResourceAsStream(IMAGE_PATH));
          getContentPane().add(new ShowImageJPanel(image));
        catch (IOException e)
          e.printStackTrace();
    }Here I have a subpackage off of the applet's package called image, and it's filled with Duke images which you can download from here:
    [https://duke.dev.java.net/images/index.html]

  • How can display svg file by using applet

    Hi ,
    my problem is ..
    1. I have one servlet which is generating svg file by using batik package.
    2.There is one Applet which receives SVG file from Servlet ..
    From here i dont have dont doubts.. then my doubt is
    3. How can display that svg file on the browser..
    please help me if u know any ,
    thanks regards,
    Balu

    Maybe this page can help you?
    http://www.w3c.org/Graphics/SVG/

  • A Components not displayed in JDialog opened from Applet.

    Hi. I have an Applet from which I am opening a JDialog, that contains a JPanel with some JTextFields. Sometimes half of textfields are not displayed. Does anybody know something about such problem?

    When you say sometimes do you mean sometimes or do
    you mean all the time?sometimes.
    In general when you have a condition that only
    sometimes occurs this is the result of a race
    condition. Assuming that this is something you see
    only sometimes, my guess is that you are displaying
    the dialog (calling setVisible(true)) before you have
    finished adding all the componentsYep. you are 100% right. found it. it was not synchronized lazy initialization called from some callbacks in different threads. ;)

  • Any "free" classes out there to display an HTML page within Applet?

    I'm not using Swing - so I'd prefer a basic HTML parser and renderer. I just want to make a simple help system for my applet -
    Any ideas?

    Yes JLabel supports HTML, e.g.
    public static void showHelp()
       JFrame frame = new JFrame();
       JLabel helpLabel = new JLabel();
       JLabel.setText("<HTML>This is a <b>help</b> file.</HTML>");
       frame.getContentPane().add(helpLabel);
       frame.setBounds(0,0,200,200);
       frame.setVisible(true);
    }

  • Display splash screen while downloading applet jar file

    I've tried to search the forums, but most results I get are how to display a splash screen while the classes are loading. Unfortunately, the classes do not begin loading until after the jar file has been downloaded. How does one go about showing as splash screen as the jar file containing the classes is downloaded?
    Thanks for the help!

    "Java 5 provides a capability in this area"- Unfortunately, due to circumstances out of our control we are stuck on java 1.4.x.
    "How you do that is your problem."- I'm so glad I can count on the helpful java community. Thanks.
    Since it appears that "warnerja" is discusted by my question (mabye had a bad day) and is leaving me out in the cold, does anyone have any ideas on how I can implement her/his suggestion. I can break my jar file into multiple seperate jars and as each one loads I can update a progress bar. Unfortunately, I do not know where to begin with this code wise nor do I know if this is the best solution to this problem. I would think this to be a common problem.
    Thanks for your help!

  • Displaying images...without Applet

    Could someone please put me out of my misery.
    I would like to add a gif file to a canvas, using just plain awt.
    Let us say, the file on your hdd is 'icon_b.gif', how would you add this image to your canvas?
    Much thanks, in advance

    Hi
    Look at this
    public class MyCan extends Canvas
         Image im;
    public MyCan()
         super();
         setBounds(10,10,90,90);
         setBackground(Color.blue);
         im = getToolkit().getImage("ball.gif");
         MediaTracker tracker = new MediaTracker(this);
         tracker.addImage(im,0);
         try   {tracker.waitForID(0);}
         catch (InterruptedException e){}
    public void paint(Graphics g)
             g.drawImage(im,10,10,null);
    }Noah

  • How to display a directory on server like JTree in applet?

    I want to display a directory on server like jtree.
    I use File("\\\\server\\directory") to present the root directory and use File.list() to display all file under root directory.Then I create Jtree object using files as treenode.
    at last i want to display the tree in my applet,but in browser an exception occured,it said " can not find Class TreeNode ".
    what can i do now ?
    thanks very much

    If you want to use JTree in an applet, there are two things you need to do.
    1. Use Swing components for the applet. i.e. extend JApplet instead of Applet. See the Swing tutorial if this is new to you.
    2. Find a way for the browser to access the Swing classes. The JVM that comes with the browser will not do this, so either distribute the classes with your applet or specify that the Sun Java plug-in be used. This will require a one-time download of a large file for each user.
    These deployment issues are the reason why most applets stay with straight AWT and JDK 1.1.8 which are supported by the browser's "built-in" JVM. You should consider these issues before deciding to use Swing in an applet.

  • How to display HTML content in Siebel form applet

    Hi All
    I have a requirement where I send data from external webservice to be displayed in a siebel form applet. The control which displays this data is a textarea but the problem is my data is with HTML tags in it like
    <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><META
    I need siebel to not show these tags but to show normal data after encoding the tags. I selected HTML Display Mode as 'EncodeData' but it is not removing the HTML tags.
    Please Help!
    Thanks
    Shweta

    Hello Shweta,
    From what I have observed, TextArea do not allow HTML formatting. This is because they are dependant on the Siebel ActiveX component unlike the Textbox.
    So in case you want to try to remove the HTML tags:
    1. Try with a text box instead of a text area.
    2. In the form applet map the control and try with HTML Display Mode as DontEncodeData if not successful.
    3. Also set the HTML Type to Field.
    Warm Regards,
    Tanmay Jain

  • Java applet manifest - having Trusted-Library=true attribute still shows display warning in JRE 1.7 u45

    As mentioned in link http://download.oracle.com/javase/6/docs/technotes/guides/jweb/mixed_code.html For applications and applets that are designed to allow unsigned components, the Trusted-Library attribute should be used. No warning dialog will be displayed and an application or applet may load jar files containing untrusted classes or resources.
    But with the the latest jre 1.7 u45 we are getting security warning prompts. It is recommednded that newer Caller-Allowable-Codebase attribute should be used to handle the warning prompt. However, if I used newer one it will break the in updated 40 , and if I am using both display prompt will continue to come in jre 1.7 u45
    Is there any solution to above problem? How can we support backward compatibility? In what sequence can we use the attribute such that both jre 1.7 u40 and 45 should stop display warning message?

    Thank you for the quick reply.
    However, I don't get the point. Do you say, a trusted library cannot call an untrusted (= unsigned) library other than by reflection?
    Then how do I use the unsigned library from my applet? The problem is mixed code (= signed and unsigned jars), there should be a way to use the unsigned jars of 3rd party contributions. For example, I would have an applet and would like to create a PDF using itext. The itext jar is unsigned, how can I use it? The same is true for the apache libraries like commons etc.
    From http://download.oracle.com/javase/6/docs/technotes/guides/jweb/mixed_code.html, I understood, that the applet jar (= the jar, that contains the class inheriting from Applet and referred to in the "code" attribute of the applet tag), should be signed and have a manifest with attribute "Trusted-Library: true" set. Then it could use classes from unsigned jars. There may be some difficulties when using reflection (Class.forName, Resource.getBundle etc.), but in general it could use the untrusted libraries without change. The explanation of the new classloader hierarchy in that document did not match (the unsigned jars have been described there as being loaded by the applet classloader, which would be the child of the new trusted library class loader. So the classes of the trusted library would not see the untrusted classes as to my understanding) but the rest of the description pointed to that.
    Did I understand this incorrectly? Then how can I use the unsigned libraries? What I need is a simple, but complete example that is working, including the applet tag, two jars, one unsigned and one signed and the code of the source and the manifests of these jars. Can you scetch such an example or do you know of some?
    Anyway, thank you again for the response.
    Edited by: 883189 on Sep 5, 2011 2:17 AM

  • Flash Player linux, grey box issue (youtube vids and some applets do not display)

    I posted this question on my distro-specific forum as well as linuxquestions.org, however it appears to  be a unique problem, so here it is:
    When viewing videos on youtube.com, most other websites, and when trying  to run certain flash games, the flash applet will not display (though  the audio will play). Instead of displaying the flash applet, there  will be a grey box where the flash video or applet would normally be.
    This problem occurs on Firefox and Chromium, but not on Opera.
    My Specs are as follows:
    Distro: PCLinuxOS 2010 (32-bit)
    flash-player-plugin: 10.1-2pclos2010
    firefox: 3.6.6-1pclos2010
    swfdec has never been installed (to my knowledge)
    I did a lot of investigating about the problem but have turned up no  solutions thus far. Here are my results.
    Flash videos and applets which allow  access to the settings menu (like youtube played from their website) do  not display, however flash videos and applets which do NOT allow access  to the settings menu (including youtube videos embedded in other  websites) WILL display.
    Reinstalling flash-player-plugin and firefox through synaptic does  not solve the problem (though note that PCLOS works with rpm files, not  deb files. apt4rpm does not support the remove --purge operation,  however reinstalls are said to overwrite custom configs with stock  ones.)
    Creating a new firefox profile and/or starting FFox in safe-mode  does not solve the problem
    Creating another user and running FFox from that user will  properly display flash videos
    Comparing default plugins between my main user and new user shows  that there is no difference. So this likely rules out a defective  extension or plugin binary.
    Deleting ~/tmp/plugtmp* folders when FFox is closed does not solve  the problem.
    Removing the ~/.macromedia and ~/.adobe folders does not solve the  problem. (have checked permissions between the new test user and main  user, and they are equivalent)
    Downloading libflashplayer.so from the Adobe website and copying it  to /usr/lib/mozilla/plugins has no effect on the problem.
    I'm thinking that there might be somewhere else that flash stores  configurations for my user, and that maybe the settings there are  corrupted and would need to be purged. However frantic googling has  turned up nothing useful so far.
    Does anyone have any suggestions for me?

    The problem, at least in my case, was QtCurve's opacity. If I have opacity set to less than 100%, flash would not display for sites like Youtube and Vimeo, but worked elsewhere.
    The solution for me was to go into qtcurve's settings, and put npviewer.bin in the application exceptions section for window and menu opacity. Doing that, I was able to keep my transparent menus, and also use flash everywhere.
    You can find out what the application name is by launching your browser of choice in a terminal with qtcurve debug turned on, like so:
    QTCURVE_DEBUG=1 firefox
    If you watch through the lines that start with "QtCurve" you'll see "Application name". Look for the one that shows up when you try to load a video. In my case it was npviewer.bin. In yours, it might be nspluginviewer or something else. If you add an exception for that specific application, you'll fix your problem without having to compromise on your theme.

  • Displaying a Timestamp on a Java Applet

    Hi, I am working on a java applet in Jbuilder. I would like to display a timestamp on my applet. Where can I find the code for this. I have searched the forums and can't find anything I need. I just wanted it to current time.
    thanks

    Here is a little of my code.. I imported the 2 packages and the I placed it at the bottom of this portion of code. The error I am getting is
    illegal start of expression at 141 (141:1)
    ';' expected at line 141 (141:8)
    import java.sql.Time;
    import java.sql.Timestamp;
    public class JavaProject extends Applet implements ItemListener, ActionListener, MouseListener
    Connection conjavafinal;
    Statement cmdjavafinal;
    ResultSet rsjavafinal;
    private String dbURL =
    "jdbc:mysql://web6.duc.auburn.edu/?user=hansokl&password=tiger21";
    boolean blnSuccessfulOpen = false;
    Choice lstNames = new Choice();
    TextField txtLastName = new TextField(15);
    TextField txtFirstName = new TextField(15);
    TextField txtid_number = new TextField(15);
    TextField txtemployee = new TextField(15);
    TextField txthoursbilled = new TextField(15);
    TextField txtbillingrate = new TextField(15);
    TextField txttotalcharged = new TextField(15);
    TextField txtAddress = new TextField(15);
    TextField txtCity = new TextField(15);
    TextField txtState = new TextField(2);
    TextField txtZip = new TextField(4);
    TextField txtPhone = new TextField(15);
    TextField txtemail = new TextField(15);
    Label lblLastName = new Label("Last Name");
    Label lblFirstName = new Label("First Name");
    Label lblid_number = new Label("Id Number");
    Label lblemployee = new Label("Employee");
    Label lblhoursbilled = new Label("Hours Billed");
    Label lblbillingrate = new Label("Billing Rate");
    Label lblAddress = new Label("Address");
    Label lblCity = new Label("City");
    Label lblState = new Label("State");
    Label lblZip = new Label("Zip");
    Label lblPhone = new Label("Phone");
    Label lblemail = new Label("Email");
    Button btntotalcharged = new Button("Calculate");
    Button btnAdd = new Button("Add");
    Button btnEdit = new Button("Save");
    Button btnCancel = new Button("Cancel");
    Button btnDelete = new Button("Delete");
    Button btnNext = new Button("Next");
    Button btnLast = new Button("Last");
    Button btnPrevious = new Button("Previous");
    Button btnFirst = new Button( "First");
    TextArea txaResults = new TextArea(10, 30);
    String strid_number;
    String stremployee;
    String strhoursbilled;
    String strbillingrate;
    String strtotalcharged;
    String strLastName;
    String strFirstName;
    String strAddress;
    String strCity;
    String strState;
    String strZip;
    String strPhone;
    String stremail;
    public void init() {
    public void mouseClicked(MouseEvent e)
    float flttotalcharged;
    float fltbillingrate;
    float flthoursbilled;
    fltbillingrate = Float.valueOf(txtbillingrate.getText()).floatValue();
    flthoursbilled = Float.valueOf(txthoursbilled.getText()).floatValue();
    flttotalcharged = fltbillingrate * flthoursbilled;
    txttotalcharged.setText("" + flttotalcharged);
    public void mousePressed(MouseEvent e)
    public void mouseReleased(MouseEvent e)
    btnAdd.setForeground(Color.cyan);
    btnAdd.setBackground(Color.white);
    public void mouseEntered(MouseEvent e)
    showStatus("Calculate Total Charge");
    public void mouseExited(MouseEvent e)
    showStatus("Ready");
    setBackground(Color.ORANGE);
    setForeground(Color.BLUE);
    LoadDatabase();
    if (blnSuccessfulOpen) {
    add(new Label("Client Billing System"));
    this is line 141 in my code ------> public class Main
    public static void main(String[] args)
    Timestamp ts = new Timestamp(System.currentTimeMillis());
    Time time = new Time(ts.getTime());
    System.out.println(time);
    }

Maybe you are looking for

  • Why do I have 2 Quicktime 7.6.4 plug ins?

    When I looked up which internet plug-ins I had, I noticed that there were 2 Quicktime plug-ins. One was labeled Quicktimeplugin.webplugin and the other Quicktimeplugin.plugin. In the Mac HD library folder they are both in the internet lug-in folder.

  • #Error when missing values

    I know I have seen this before but cant remember the fix. We have columns A and B, then a variance column. Users dont want to suppress so sometimes there is #missing in both columns so the variance column is returning a #Error. I can change the suppr

  • Getting response from Servlet in WDPJ

    Hello, I have been provided with an Servlet URL to get some details to be populated in an WebDynpro Application. How should i invoke the servlet url inside the webdynpro application? Regards Bobu

  • How to disable autoplay of converted videos and...

    I have recently switched to an iMac with the latest version of iTunes. Now when I convert a video file using videora it automatically starts playing in iTunes. I have searched and found that others have this issue too. Is there anything that can be d

  • WHAT IS JDK 1.4 NON BETA RELEASE DATE

    Hello, Does anyone know when JDK 1.4 is going to be released in non beta form? I truely do not want to have my clients pull beta plug ins and then real plug ins. Thanks in advance. Jay