How can I draw image in a vbean?

How can I draw image in a vbean?
this is my code :
import java.awt.BorderLayout;
import java.awt.Image;
import java.awt.Graphics;
import java.net.MalformedURLException;
import java.net.URL;
import com.sun.jimi.core.Jimi;
import oracle.forms.handler.IHandler;
import oracle.forms.properties.ID;
import oracle.forms.ui.VBean;
public class PrintEmailLogo extends VBean {
     URL url;
     Image img;
     boolean ImageLoaded = false;
     public void paint(Graphics g) {
          if (ImageLoaded) {
               System.out.println("yes~~~");
               g.drawImage(img, 0, 0, null);
          } else
               System.out.println("no~~~");
     public boolean imageUpdate(Image img, int infoflags, int x, int y, int w,
               int h) {
          if (infoflags == ALLBITS) {
               System.out.println("yes");
               ImageLoaded = true;
               repaint();
               return false;
          } else
               return true;
     public void init(IHandler arg0) {
          super.init(arg0);
          try {
               url = new URL("file:print/77G.gif");
               img = Jimi.getImage(url);
               Image offScreenImage = createImage(size().width, size().height);
               Graphics offScreenGC = offScreenImage.getGraphics();
               System.out.println(offScreenGC.drawImage(img, 0, 0, this));
          } catch (MalformedURLException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
but when I run it in forms
when it run Graphics offScreenGC = offScreenImage.getGraphics();
It throw a exception:
java.lang.NullPointerException     at com.avicit.aepcs.calendar.PrintEmailLogo.init(PrintEmailLogo.java:72)     at oracle.forms.handler.UICommon.instantiate(Unknown Source)     at oracle.forms.handler.UICommon.onCreate(Unknown Source)     at oracle.forms.handler.JavaContainer.onCreate(Unknown Source)     at oracle.forms.engine.Runform.onCreateHandler(Unknown Source)     at oracle.forms.engine.Runform.processMessage(Unknown Source)     at oracle.forms.engine.Runform.processSet(Unknown Source)     at oracle.forms.engine.Runform.onMessageReal(Unknown Source)     at oracle.forms.engine.Runform.onMessage(Unknown Source)     at oracle.forms.engine.Runform.processEventEnd(Unknown Source)     at oracle.ewt.lwAWT.LWComponent.redispatchEvent(Unknown Source)     at oracle.ewt.lwAWT.LWComponent.processEvent(Unknown Source)     at java.awt.Component.dispatchEventImpl(Unknown Source)     at java.awt.Container.dispatchEventImpl(Unknown Source)     at java.awt.Component.dispatchEvent(Unknown Source)     at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)     at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)     at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)     at java.awt.Container.dispatchEventImpl(Unknown Source)     at java.awt.Component.dispatchEvent(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.run(Unknown Source)
I change it to:
import java.awt.BorderLayout;
import java.awt.Image;
import java.awt.Graphics;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JFrame;
import com.sun.jimi.core.Jimi;
import oracle.forms.handler.IHandler;
import oracle.forms.properties.ID;
import oracle.forms.ui.VBean;
public class PrintEmailLogo extends VBean {
     URL url;
     Image img;
     public void paint(Graphics g) {
          try {
               url = new URL("file:print/77G.gif");
               img = Jimi.getImage(url);
               g.drawImage(img, 0, 0, this));
          } catch (MalformedURLException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
     public void init(IHandler arg0) {
          super.init(arg0);
But it display nothing.
It isn't paint continuous.
what's wrong in my vbean?
please help me.

The following code works fine for me:
package oracle.forms.fd;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import oracle.forms.handler.IHandler;
import oracle.forms.properties.ID;
import oracle.forms.ui.CustomEvent;
import oracle.forms.ui.VBean;
public class test extends VBean {
  private URL url;
  private URL m_codeBase; 
  private Image img;
public void paint(Graphics g) {
  // draw the image
  g.drawImage(img, 0, 0, this);
public void init(IHandler arg0) {
   super.init(arg0);
   // load image file
   img = loadImage("file:///c:/coyote.jpg");   
public test()
    super();
   *  Load an image from JAR file, Client machine or Internet URL  *
  private Image loadImage(String imageName)
    URL imageURL = null;
    boolean loadSuccess = false;
    Image img = null ;
    //JAR
    imageURL = getClass().getResource(imageName);
    if (imageURL != null)
      try
        img = Toolkit.getDefaultToolkit().getImage(imageURL);
        loadSuccess = true;
        return img ;
      catch (Exception ilex)
        System.out.println("Error loading image from JAR: " + ilex.toString());
    else
      System.out.println("Unable to find " + imageName + " in JAR");
    //DOCBASE
    if (loadSuccess == false)
      System.out.println("Searching docbase for " + imageName);
      try
        if (imageName.toLowerCase().startsWith("http://")||imageName.toLowerCase().startsWith("https://"))
          imageURL = new URL(imageName);
        else if(imageName.toLowerCase().startsWith("file:"))
          imageURL = new URL(imageName);
        else
          imageURL = new URL(m_codeBase.getProtocol() + "://" + m_codeBase.getHost() + ":" + m_codeBase.getPort() + imageName);
        System.out.println("Constructed URL: " + imageURL.toString());
        try
          img = createImage((java.awt.image.ImageProducer) imageURL.getContent());
          loadSuccess = true;
          System.out.println("Image found: " + imageURL.toString());
          return img ;
        catch (Exception ilex)
          System.out.println("Error reading image - " + ilex.toString());
      catch (java.net.MalformedURLException urlex)
        System.out.println("Error creating URL - " + urlex.toString());
    //CODEBASE
    if (loadSuccess == false)
      System.out.println("Searching codebase for " + imageName);
      try
        imageURL = new URL(m_codeBase, imageName);
        System.out.println("Constructed URL: " + imageURL.toString());
        try
          img = createImage((java.awt.image.ImageProducer) imageURL.getContent());
          loadSuccess = true;
          System.out.println("Image found: " + imageURL.toString());
          return img ;
        catch (Exception ilex)
                System.out.println("Error reading image - " + ilex.toString());
      catch (java.net.MalformedURLException urlex)
        System.out.println("Error creating URL - " + urlex.toString());
    if (loadSuccess == false)
      System.out.println("Error image " + imageName + " could not be located");
    return img ;
}Francois

Similar Messages

  • Help!How can i draw an image that do not need to be displayed?

    I want to draw an image and save it as an jpeg file.
    first I have to draw all the elements in an image object.I write a class inherit from Class Component,I want to use the method CreateImage,but I get null everytime.And i cannot use the method getGraphics of this object.Thus i can not draw the image.
    when i use an applet,it runs ok.I use panel and frame,and it fails.
    How can i draw an image without using applet,because my programme will be used on the server.
    Thank you.

    you could try this to create the hidden image
    try
              GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
              GraphicsDevice gs = ge.getDefaultScreenDevice();
              GraphicsConfiguration gc = gs.getDefaultConfiguration();
              offImage = gc.createCompatibleImage(100, 100);
              offG = offImage.getGraphics();
          catch(Exception e)
              System.out.println(e.getMessage());
          }

  • How can I assign image file name from Main() class

    I am trying to create library class which will be accessed and used by different applications (with different image files to be assigned). So, what image file to call should be determined by and in the Main class.
    Here is the Main class
    import org.me.lib.MyJNIWindowClass;
    public class Main {
    public Main() {
    public static void main(String[] args) {
    MyJNIWindowClass mw = new MyJNIWindowClass();
    mw.s = "clock.gif";
    And here is the library class
    package org.me.lib;
    public class MyJNIWindowClass {
    public String s;
    ImageIcon image = new ImageIcon("C:/Documents and Settings/Administrator/Desktop/" + s);
    public MyJNIWindowClass() {
    JLabel jl = new JLabel(image);
    JFrame jf = new JFrame();
    jf.add(jl);
    jf.setVisible(true);
    jf.pack();
    I do understand that when I am making reference from main() method to MyJNIWindowClass() s first initialized to null and that is why clock could not be seen but how can I assign image file name from Main() class for library class without creating reference to Main() from MyJNIWindowClass()? As I said, I want this library class being accessed from different applications (means different Main() classes).
    Thank you.

    Your problem is one of timing. Consider this simple example.
    public class Example {
        public String s;
        private String message = "Hello, " + s;
        public String toString() {
            return message;
        public static void main(String[] args) {
            Example ex = new Example();
            ex.s = "world";
            System.out.println(ex.toString());
    }When this code is executed, the following happens in order:
    1. new Example() is executed, causing an object to constructed. In particular:
    2. field s is given value null (since no value is explicitly assigned.
    3. field message is given value "Hello, null"
    4. Back in method main, field s is now given value "world", but that
    doesn't change message.
    5. Finally, "Hello, null" is output.
    The following fixes the above example:
    public class Example {
        private String message;
        public Example(String name) {
            message = "Hello, " + name;
        public String toString() {
            return message;
        public static void main(String[] args) {
            Example ex = new Example("world");
            System.out.println(ex.toString());
    }

  • How can I display images that are not included in any collection?

    How can I display images that are not included in any collection (some filter or smart collection)? A smart collection with parameters "Collection - contains - empty field" does not work. Lightroom 5.

    Thank you! Good idea! I ordered letters of the alphabet (space separated), and it works.

  • How can I display images in drop down.

    Hi All,
    How can I display images in drop down.
    <select><option>image here</option></select>
    please reply soon.
    anser please
    Thanks

    I have not found html forum..That's just incredible.
    where can i find it ?Sorry, I'm still recovering from that remark.
    please reply soonEvery time you end a post with this, or "urgent" or other such keywords, the forum automatically introduces a 5 minute delay so that will actually make the whole process slower (not faster).

  • How can i display image in RTF template when Oracle Apps running in Windows

    Can any body help how can i display image in RTF template when oracle apps running in Windows Server.
    Thanks
    Ravi

    Hi Ravi,
    You can add images into your rtf template using MS Word Insert Picture feature.
    Did you try this method?
    Thanks
    Ravi
    [email protected]

  • How can I access images from IPhoto on my Mac to Photoshop CS6

    How can I access images from IPhoto library on my Mac to Photoshop CS6?  I enable jpg with format "Photoshop" and this is what comes up -  "Could not complete your request because Photoshop does not recognize this type of file" 

    MountainArtist wrote:
    …I enable jpg with format "Photoshop" and this is what comes up -  "Could not complete your request because Photoshop does not recognize this type of file" 
    Photoshop is not a format.  It's an application.
    What you are looking at are not true JPEGs, just iPhoto's "tease" representations of the hidden images it swallowed, as explained above.

  • In iPhoto, how can I export images with the metadata - including the title and caption information - intact as part of the image?

    In iPhoto, how can I export images with the metadata — including the title and caption information — intact as part of the image?

    Check those boxes in the export dialogue - Exporting From iPhoto
    LN

  • How can I add image files to a executable jar file ?

    Could you tell me how can I add image files to executable jar file ?
    package structure:
    ../com/Main.class
    ../images/..

    Please don't cross post, and read this
    http://forum.java.sun.com/thread.jsp?forum=31&thread=271751
    I've answered the question in the New To Java thread.

  • How can I import images from iphoto with the albums and folders?

    How can I import images from iphoto without losing the albums and folders I already created?

    In Organizer, you can choose File>get Photos and Videos>From iPhoto.
    Importing from iPhoto'09: If in iPhoto, you organize your media using photo references, that is, the media actually does not reside inside iPhoto library package, and are referenced through original locations, Organizer does not create new copies of those media and just refer to the original location. but if your iPhoto media reside inside iPhoto library, Organizer creates a copy all media in your pictures folder, also imports albums and tags and other metadata.
    Importing from iPhoto'011: In this case, Organizer always creates a copy of your photos in your pictures folder which resides inside iPohto package. It does not import the albums and other metadata like star rating, caption etc.
    Hope this information helps!
    regards,
    vaishali

  • How can I download images from my iphone to adobe bridge cs5

    How can I download images from my iphone to adobe bridge cs5?  I don't want to use iPhoto.

    "How can I download photos from my iphone to mac?"
    Same way as with any other digital camera.
    "Do I need to use Iphoto? "
    Yes.
    "Why doesn't my Mac come with Iphoto application? "
    It does. All macs come with iphoto.
    Copying personal photos and videos from iOS devices to your computer

  • How can i add image on my mail siganature on iphone

    hi,
           how can i add image on my mail siganature on iphone.

    I do not know if this will work but you can try. Place the image you want on a storage site like Imageshack or Photobucket. Then make a link to it in your signature using (img_src="put the url of your image here"). This may work at least when you have an active data connection - wifi or cellular

  • How can I download images taken with my iPad onto my MBP please?

    How can I download images taken with my iPad onto my MBP please?

    Your other option if you have icloud and a mac is to use iCloud and sync them across through photo stream. The other option as jhappahc said is to use a usb and import the photos through iPhoto.

  • How can I extract image from complex (multycoloured0 background?

    How can I extract image from complex (multycoloured) shot?

    I would say either using the pen tool or the quick mask tool but without seeing how complex the image/background is I can't give you a complete answer...?
    Can you post the image?

  • How can I import image sequences into Fireworks???

    How can I import image sequences into Fireworks???

    I quote:
    Not specifically "import" but you can open a series of images as an animation. This will place each image in its own state, suitable for creating an animation.
    Choose File > Open
    Select the images
    Enable Open as animation.
    Import image sequence (CS4)

Maybe you are looking for

  • Installing Adobe Photoshop 2.0

    My old Adobe Photoshop 2.0 will not install on OSX 10.5.2. It keeps telling me I do not have Administrative privileges, when I am logged in on an administrative account. The installation doc on the Photoshop says to go to System Preferences and selec

  • My nokia ovisuite wont let me update my phones sof...

    hello im trying to update my nokia n8 phone software it wont let me update it via the the phone it keeps telling me i need to update it via the pc so i downloaded the nokia ovisuite on my pc that im currently running on windows7 and it wont let me up

  • Can I highlight items in a scanned document

    I scanned documents into a PDF file.  Now I would like to go into that document and highlight some things but can't figure out how to do it or don't know if is possible.  Please help.

  • ID CC 9.2.1: Interactive PDF, text boxes use wrong font

    When filling out text boxes of an interactive PDF (created with InDesign CC 9.2.1) in Adobe Reader X, the font used is always Times Roman or such. Whatever I've tried so far, I fail to make the interactive text boxes use a specific font. Should be th

  • Make click box feedback stay on screen

    How do I make the feedback for a clickbox stay on screen till the learner moves on? I see where I can designate a specific number of seconds for it to stay on screen, but I just want it to stay on the screen indefinitely till the learner moves on...s