Drawing Images. Making them Durable?

Im trying to create an application that draws images to the screen. So for example, it draws an image (call it image x) where the user left clicks the mouse. It draws fine. Then when the user clicks at a new spot, the first image x is erased when the next is placed on the screen. This isn't what I want, I want all previous images from clicking to say. From searching, it seems my problem is that drawn images are not durable. Other forum posts didn't help me understand the solution to the problem so any help would be wonderful.
Edited by: goyanks135 on May 12, 2009 6:13 PM

Thanks for the quick reply, that seems to work best for this application. Another thing, is there any way to generate a BufferedImage that represents the panel? Currently I am using:
<BufferedImage> = robot.createScreenCapture(<Rectangle>);
to do so, but would not depending on where the window is on the screen. I couldn't figure out how to determine the windows location. Is there a method to create the BufferedImage or obtain the window's coordinates?
edit: I was looking at the getLocation() and getSize() methods of the component class. Seems like they should work if I use
<BufferedImage> = robot.createScreenCapture(new Rectangle (getLocation(), getSize());
I'm going to bed right now and didn't get it to work. Seems like it should.
Edited by: goyanks135 on May 12, 2009 7:01 PM

Similar Messages

  • Draw image over Swing to mask.

    I have a window and I've overridden it make it draw all of it's components and then draw images over them (on a back buffer and then flip so the swing shouldn't ever be seen).
    It works perfectly and the swing components (JButtons and the like) catch the clicks when I click on the images masking them. The problem is when I click them for a very brief moment I see the Swing component come through. How is Swing doing this? Since I blt in a specific order and then flip. Somehow it is using the Graphics for the window directly - I overrode invalidate in a few ways but that just broke the components altogether.
    Anyone masked Swing components with images using a BufferStrategy? I would love some advice.

    AbstractButton (which JButton extends) calls JComponent.paintImmediately upon a click, so I don't think you can stop it without overriding AbstractButton and JButton (not recommended).
    Either override the paint method for your components to look like your overlaid image or remove your Swing components and test the mouse click location in the MouseListener.
    --Jon

  • Looking for an app where i can draw images then text them?

    Looking for an app where I can draw images then text them?

    Just write Draw into the MAS searchbox in the upper right corner and you will be presented with a plethora of drawing/sketching apps of varying abilities and pricing.

  • When making my imovie i put images in them and they all show. when i put the export onto a usb and onto a tv the images go. Anyone know why?

    When making my imovie i put images in them and they all show. when i put the export onto a usb and onto a tv the images go. Anyone know why?

    Wrong forum; we don't do Elements here.
    You want:  Photoshop Elements

  • Problems drawing images form another class

    Ok as the title says I'm having trouble drawing images from a different class. I have a class that represents a plane and it has a draw' method that draws its .gif image.
    public void draw (Graphics g)
    g.drawImage(planepic , xPos, yPos, null)
    then in my main class in the paint method i have
    plane.draw(g);
    I think my problem is the null for my image observer. I tried using null as my image observer and i got a error saying i can't make a static reference to a non static method.
    I've done some research because i never really understood static but i still don't quite get it.
    Also when I use this as my image observer i get a error in my plane object.
    I also just tried passing and making a object for my main class and i still got the static error.
    Any help is appreciated and thanks in advance

    Ok as the title says I'm having trouble drawing
    images from a different class. I have a class that
    represents a plane and it has a draw' method that
    draws its .gif image.
    public void draw (Graphics g)
    g.drawImage(planepic , xPos, yPos, null)
    in my main class in the paint method i have
    plane.draw(g);
    I think my problem is the null for my image observer.
    I tried using null as my image observer and i got a
    error saying i can't make a static reference to a non
    static method. Use a minimal implementation of the ImageObserver to be sure.
    public class Plane implements ImageObserver
    public boolean imageUpdate(
    Image img,int infoFlags,int x,int y,int width,int height)
       switch(infoFlags)
          case ALLBITS:
                    return false;
          case SOMEBITS:
                    return true;
          default:
                return true;
    I've done some research because i never really
    understood static but i still don't quite get it.
    Also when I use this as my image observer i get a
    error in my plane object.
    I also just tried passing and making a object for my
    main class and i still got the static error.
    Any help is appreciated and thanks in advanceWhen you call draw(g) from your other class you hand it a Graphics context that you instantiated somewhere else ie: in another class. Without a more complete example it is really impossible to determine your issue for sure,
    but if I was to guess I would say you need to make sure that the Graphics context handed to the draw(Graphics) method was instantiated from a Component that was already visible. ie: Do a f
    Frame.createImage() from your parent frame after iyou have already called setVisible(true); In other words I suspect you are making and Image from some other Component that is not yet visible. That however is a guess so if not the issue post the rest of the code or at least a minimal implementation that demonstrates this.
    About static:
    static means the class/variable is the same throughout ALL classes of that type and if changed in one instance it will change and thus be the same for all instances.
    You CAN call static by referencing the base class Object without having to instantiate.
    ie:given
    public class SomeClass
    static String name;
    static String getName
       if(name == null)
          name = "DefaultName";
       return name;
    }Thus you could call..
      String name = SomeClass.getName();As opposed to
    SomeClass myClass = new SomeClass();
          myClass.getName();This can get you in trouble if you try to make a method that is static
    that then tries to reference non static variables.
    ie:
    public class SomeClass
    int x;
    static String name;
    SomeClass()
       x=0;
    static String getName
       if(name == null)
          name = "DefaultName";
       x++;
       return name;
    }In this case SomeClass.getName(); will throw and exception because it is trying to access[b] x  from a static context .
    Hope that clears that up for you; if not post a more complete example.
    Good Luck!
    (T)

  • Problems drawing image

    Im sorry for even askign this but i'm having problems drawing an image, no idea why its not working!!! I know that my Image object actually is the image because i can get it to display on a button, but i need to get it to display in the JPanel through the paintComponent() method, for some reason it wont do it. Thanks for the help.
    Here's my code
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class StatWindow extends JDialog{
        private StatPanel panel;
        public StatWindow(JFrame parent) {
            this(parent, null);
        public StatWindow(JFrame parent, String data){
            super(parent, "Stat", false);
            getContentPane().setLayout(null);
            panel = new StatPanel();
            getContentPane().add(panel);
            panel.setBounds(0, 0, 220, 220);
            setSize(300, 300);
            setVisible(true);
        class StatPanel extends JPanel{
            private Image diagram1;
            private Image diagram2;
            private Image diagram3;
            private Image diagram4;
            private Image diagram5;
            private Image diagram6;
            private Image diagram7;
            private Image diagram8;
            private Image diagram9;
            private Image diagram10;
            private Image diagram11;
            private Image diagram12;
            private Image diagram13;
            private Image diagram14;
            private Image diagram15;
            private Image diagram16;
            private Image diagram17;
            private Image diagram18;
            private Image diagram19;
            private Image diagram20;
            private Image diagram21;
            private Image diagram22;
            private Image diagram23;
            private Image diagram24;
            private Image diagram25;
            private Image diagram26;
            private Image diagram27;
            public StatPanel(){
                super();
                Image diagram1 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_01.jpg"));
                Image diagram2 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_02.jpg"));
                Image diagram3 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_03.gif"));
                Image diagram4 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_04.jpg"));
                Image diagram5 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_05.jpg"));
                Image diagram6 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_06.jpg"));
                Image diagram7 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_07.gif"));
                Image diagram8 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_08.jpg"));
                Image diagram9 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_09.jpg"));
                Image diagram10 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_10.jpg"));
                Image diagram11 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_11.gif"));
                Image diagram12 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_12.jpg"));
                Image diagram13 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_13.jpg"));
                Image diagram14 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_14.gif"));
                Image diagram15 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_15.gif"));
                Image diagram16 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_16.jpg"));
                Image diagram17 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_17.jpg"));
                Image diagram18 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_18.gif"));
                Image diagram19 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_19.jpg"));
                Image diagram20 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_20.jpg"));
                Image diagram21 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_21.jpg"));
                Image diagram22 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_22.gif"));
                Image diagram23 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_23.jpg"));
                Image diagram24 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_24.gif"));
                Image diagram25 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_25.jpg"));
                Image diagram26 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_26.jpg"));
                Image diagram27 = getToolkit().getImage(getClass().getResource("xpbn/media/stat/Diagram_27.jpg"));
                addMouseMotionListener(new MouseMotionHandler());
                addMouseListener(new MouseHandler());
                JButton b = new JButton(new ImageIcon(diagram1));
                getContentPane().add(b);
                b.setBounds(0, 0, 40, 40);
            class MouseMotionHandler extends MouseMotionAdapter{
                public void mouseMoved(MouseEvent e){
            class MouseHandler extends MouseAdapter{
                public void mousePressed(MouseEvent e){
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                Graphics2D g2d = (Graphics2D)g.create();
                g2d.drawImage(diagram1, 0, 0, this);
                g2d.dispose();
    }

    you have these declarations
    private Image diagram1;
    private Image diagram2;
    and in your constructor you have these
    Image diagram1 = getToolkit().getImage...
    Image diagram2 = getToolkit().getImage...
    the inclusion of the 'type' Image makes them local to the constructor

  • Why is iMessage taking my incoming emails and then not making them available for my PC to get?  Why can I not send a text msg with photos when iMessage is turned off (but MMS is still on).

    Apple is great!
    Why is iMessage taking my incoming emails and then not making them available for my PC to get?  Why can I not send a text msg with photos when iMessage is turned off (but MMS is still on).
    I compose an iMessage with the destination as my email address and I attach 2 photos I want on my PC.  I send them several times from my iPhone 5C but they never arrive. I look at my ipad later and realize that it's iMessage app is getting ( and swallowing) these emails. I then turn the ipad off.  Still can't get the photos through because iphone is now getting them on it's iMessage.  I turn off the iMessage feature and try to send photos from text msging.  Phone tells me it can't send photos unless iMessage it turned on.  What happened to regular MMS text messaging?  I go and try to send photos as an email attachment and see that there is no option to attach from the stupid email program.  I look up online to learn about the brave new world of apple attachments and send them.
    Why is iMessage taking my incoming emails and then not making them available for my PC to get?
    The email program on my iphone is not configured to remove messages from the server.
    If iMessage is turned off I don't have the issue.
    Why can I not send a text msg with photos when iMessage is turned off (but MMS is still on).

    Did not work. I've selected iMessage to ON and left it. After a few hours I recieved a message "activation unsuccessful. Turn on iMessage to try again". This has been going on for the past 3 days.

  • 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

  • Can one add more than one photo layer to a draw image?

    I cannot seem to find a way to add more than one photo or photo layer to a Draw image, but the Draw page on Adobe seems to imply multiple photos can be added. How might I accomplish this? Thanks for your time.

    Unfortunately, Draw is currently limited to one photo layer, and only one photo within that layer.
    Hope that helps,
    Frank
    Draw Engineering

  • Specification to Draw image on a page

    Can any one tell me exact Specification to draw image on a page.

    What don't you understand from the PDF Reference?
    You need an Image XObject and the Do operator in the content stream.
    Leonard

  • Using image as theme on top of base map

    I have a table which contains JPEG image stored as BLOB. I want to display this image as theme on top of my base map. I also want to display point on this theme.
    Is it possible to do this?
    Please provide me useful pointers for achieving this scenario.
    Thanks in advance.

    To setup image themes, besides the BLOB column you need a geometry column to specify the bounds of the image (MBR). Take a look at MapViewer's Users Guide section about Image themes (section 2.3.5).
    About the points, you can setup another theme to render the points.
    Once you have the themes you can add them to your base map, or render them on top of your base map. Notice that in Oracle Maps, currently image themes must be part of the base map, and you can not render it alone on top of the base map.

  • How to upload background image in Theme Editor

    Hi
    I want upload an image to theme
    I try by the theme edit i'ts not work
    I try by Edit "Right to Left" Theme Images
    I don't find the button "Upload"
    please Help!!!!
    How to upload background image in Theme Editor without to entry to the server
    Regards
    Yossi

    Hi
    Thank you for response
    I want upload to TransparentContainer Image in background
    I change the design to Plain
    I Try Upload by the browse in the theme
    but The image is not upload
    even if i delete the chace  serever
    i'ts not working

  • 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

  • I have made flash cards on my ipad.  I am trying to put images on them.  How do I do this?

    My daughter is working on a project for school.  She has made flash cards and is trying to put images onto them... She has taken the pictures using her camera.  Now what does she have to do to put the pictures onto the flash cards?
    Thanks!!

    She says she used Ifree Flash Cards???  I don't know anything about the IPad.  I did however try to copy and paste but I guess it doesn't work the same as on a computer??? 
    Everytime we tried to copy the photo all it will do is make an extra copy?
    Thanks for your answer and any help.

  • Blast from the past: How do I draw image maps in Dreamweaver CC 2014?

    Need to update some old stuff, and can´t find where to draw image-maps on images.

    First, you need to be in Design View to get the image map tools to appear.
    Once there, the image map icons should show when you select an image. If they don't, you may have your Properties panel collapsed. In the bottom right corner of the Properties panel, there's a tiny triangle, click that to expand the panel to include the image map tools.

Maybe you are looking for

  • KM Task Scheduler: How to create custom/editable properties?

    Dear All, I created a KM Scheduler Task using the NDWS Wizard. The application was successfully deployed and the task runs fine. However, I would like to define some custom properties that could be edited by using the portal, like the standard ones s

  • How do I reset and start another game.

    Hello Please can someone help, I have spent several days on this and still can't get it to work. The code below is ok, I am playing a bowling game using the keyboard and timer with a text readout of the elapsed time, the bowl moves a set number of pi

  • Real Time Application of  Void class

    Dear Friends, we know that there is class called Void with one field named TYPE. where can we apply this class?

  • LifeCycle of an Corba Object

    The activation of the Corba Object on Server side is made after an client request by the BOA service. After that, how long is the instance kept in the memory by the Oracle JServer / Visigenic ORB ? How does it work ? In the Oracle application server

  • How to generate an Interupt for DMA transfer from Counter on NI-PCI-6602

    dear guys:       how to generate an Interupt for DMA transfer from Counter on NI-PCI-6602,and I have set the DMA and DMA_INT, and also the global interrupt register. but there is no Interupt generated in the Interupt callback function.And when I have