Drawing JPEGs/GIFs directly on JFrames

Hey all,
Is it possible to draw an image DIRECTLY onto an instance of the JFrame class, rather than writing a subclass of a component? I suspect that a solution to my problem might have something to do with the getGraphics() method of JFrame.
Mike.

Have you looked into your own suggestion? Doesn't the Graphics object returned from getGraphics() provide a drawImage() method?

Similar Messages

  • Need help to create report with jpeg/gif image

    Hello,
    I need help with creating a form with a special jpeg/gif seal. I never done this Java. Until now, I created all forms with ansi C++ with HP escape characters to draw lines, boxs, and text. This form will contain boxes which is populated with database information read from a text file.
    Since this form contains a special seal on the upper right, I don't think it can be done with old fashion ansi C++. How can I create a form with Java and create it as a simple exe to just print the form to a specified printer.
    Thanks,
    John

    Hi,
    I am creating a form with boxes (lines and text). What is special about this form is that it has an image jpeg or gif at the top right corner. Is is a state department seal. Up to this form, I had used ansi C++ and print out escape HP character to print out the lines, boxes, and text. I have no idea how to print out the image. I am new to JAVA and only 1 class in it. Is there sample code out there to create this type of form with the image? I need a starting point.
    Thanks,
    John

  • Save Applet as a jpeg/gif image

    I wrote a small applet to draw some lines.
    it work fine.
    What i want to know is how can i save this applet to a jpeg/gif file.
    (Assume there is a Button in the Applet or Even in the HTML page; when click the button needs to save the applet as an image file)
    is it possible??
    import java.applet.*;
    import java.awt.*;
    public class Test extends Applet {
       int width, height;
       public void init() {
          width = getSize().width;
          height = getSize().height;
          setBackground( Color.black );
       public void paint( Graphics g ) {
          g.setColor( Color.green );
          for ( int i = 0; i < 10; ++i ) {
             g.drawLine( width, height, i * width / 10, 0 );
    <applet code="Test" width="300" height="300">
    </applet>
    Message was edited by:
    jugp

    After finding out some facts i tried to do like this;
    but still having some runtime exceptions....
    need help from anybody!!!
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.BufferedImage;
    import javax.imageio.ImageIO;
    import java.io.File;
    import java.io.IOException;
    public class Test extends Applet implements ActionListener{
       int width, height;
    Image backbuffer;
       Button save;
       public void init() {
          save = new Button("save");
          add(save);
          save.addActionListener(this);
               width = getSize().width;
          height = getSize().height;
          setBackground( Color.black );
       public void paint( Graphics g ) {
          g.setColor( Color.green );
          for ( int i = 0; i < 10; ++i ) {
             g.drawLine( width, height, i * width / 10, 0 );
       public void actionPerformed(ActionEvent e) {
         String cmd = e.getActionCommand();  
         if (cmd.equals("save")){
                 BufferedImage bufferedImage = new BufferedImage ( width, height,
                       BufferedImage.TYPE_INT_BGR  );
                        bufferedImage.createGraphics().drawImage( backbuffer, 0, 0, this);
                   try {
                        ImageIO.write( bufferedImage, "jpg", new File ( "image.jpg" ) );
                   } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
    <applet code="Test" width="300" height="300">
    </applet>
    */

  • Draw a circle on a jFrame

    Hi! How can i draw a circle over a jFrame?

    In general trying to draw directly on a JFrame is not a good idea and can be problematic. You should think about doing your drawing in a JPanel and adding that to the frame
    Here are a number of things to look at in drawing a circle
    Graphics.drawOval(...)
    Ellipse2D, Ellipse2D.Double
    Area - you can create an area from any Shape, and it offers a lot of advantages to dealing with Shape
    Graphics2D.draw/fill(Shape)

  • GIF images in JFrame

    hi all, i'm trying to put a gif image in JFrame. The problem is the gif images gets flickering(fluctuation) while it is placed in a frame. i had also placed some labels near the image and all of them gets disturbed becoz of this gif file in frame. plz tel me a solution.
    Thanks .
    //MY CODE
    //~~~~~~~~~~
    import java.awt.*;
    import java.awt.Color;
    import java.awt.event.*;
    import javax.swing.*;
    class Label_ON_G extends JFrame// implements MouseListener,MouseMotionListener
      private Image image;
      JLabel label1;
      JButton button1;
      Dimension dimension=Toolkit.getDefaultToolkit().getScreenSize();
      public Label_ON_G()
           super("Display image example");
           getContentPane().setBackground(Color.white);
           getContentPane().setSize(dimension);
        setResizable(true);
        getContentPane().setLayout(null);
         Toolkit tk = Toolkit.getDefaultToolkit ();
         image = tk.getImage ("singlearea.gif");
        label1= new JLabel("RADHA");
        label1.setBounds(120,110,80,30);
        label1.setEnabled(false);
        add(label1);
        button1= new JButton("VIEW LABEL");
        button1.addActionListener(new ActionListener(){
             public void actionPerformed(ActionEvent ae)
              label1.setEnabled(true);
             System.out.println("ActionPerformed");
        button1.setBounds(600,600,100,30);
        add(button1);
        setVisible(true);
        show();
    public void paint (Graphics g)
      g.drawImage(image, 100, 100, this);
      public static void main (String[] args)
      {     new Label_ON_G();     }
    }

    There is no need to do custom painting to display an image.
    [url http://java.sun.com/docs/books/tutorial/uiswing/components/label.html]How to Use Labels
    Unless you know what you are doing, never override the paint() method of the JFrame. There is no reason to do this.
    If you need to do custom painting then you override the paintComponent() method of a component that extends JComponent.

  • Drawing moving GIF images?

    Is it possible to draw moving gif images on a simple Frame applet?
    I made an image drawer class for my applet and i can draw simple 2d images.
    Here is the basis of my GameSprite class;
        public byte[] pixels;
        public int width;
        public int height;
        public GameSprite(String imageName, int requestIndex) {
         try {
                    // Removed code, it's zipInputStream, but it can be used just as ./image.jpg etc
         javax.swing.ImageIcon icon = new javax.swing.ImageIcon(fileBytes);
         width = icon.getIconWidth();
                     height = icon.getIconHeight();
                     pixels = fileBytes;
         } catch(Exception e) {
              e.printStackTrace();
        public void drawSprite(int x, int y) {
         try {
              Image image = Toolkit.getDefaultToolkit().createImage(pixels);
                                    //Removed code here
              graphics.drawImage(image, x, y + 7, width, height, observer);
         } catch(Exception e) {
              e.printStackTrace();
        }If i try to draw an animated gif image it dosn't move.
    Thanks for any help.

    In Java you need to override the paint method in AWT and paintComponenet method in SWING to do graphics/animation. If you go to an offscreen rendering, then you can paint to the graphics context of an image you use for a drawImage in your paint/paintComponent...
    If you where overriding a Panel in AWT you would override paint:
    public void paint(Graphics g){
      g.drawImage(im, 0, 0, this);
    }Then where you are maipulating your graphics you would do something like this:
    //code snippet
    Graphics g = im.getGraphics();
    //make what ever changes to im by manipulating the graphics context g
    repaint();

  • Can assets be images of type jpeg,gif,Tiff,etc... ?

    Hi,
    I am working  on ES2.
    I am able to take PDF file as form to the  my  process. Here  my  new requirement is   in addition to  pdf  I need to take all types  of  images
    say jpeg,gif, and Tiff  as  input to my  process.  But I am not able to do that bcas Workbench only  takes *.pdf as input.
    If you have other extensions  expect  pdf,  while   taking the asset into the  start activity, I  could  not  find that  file in the  application.
    Please help me in this regard how  workbench takes  all image files as inputs into  the  process.
    Thanks
    Praveen.

    Hi Scott,
    Thanks for your reply.
    Yes   I  have to use as image file as form  to the process.
    I am using  Adobe LC ES2.
    Let  me explian my  requirement :  I have  scanned image   and  need to use that image as input to the process i mean image as form  to the process.
    I will invoke the process then  scanned image should come as form  in the  workspace .
    Please help in this regard.
    Thanks
    Praveen.

  • Image (jpeg, gif) display in AWT layout manager

    Goodmorning All,
    I am looking for some help, a hint on my AWT Layout challenge i have.
    Example GUI_1:
    =========================
    Window border..................[_][x]..
    =========================
    [label]....|display_area|....[button].
    [label]....|display_area|....[button].
    ...............|display_area|....[button].
    ...............|display_area|....[button].
    ...............|display_area|..................
    =========================
    ...........................................[QUIT].....
    =========================
    I want to
    - display a picture in the "display area" of the this GUI
    - put labels left of it with some text
    - put a couple of buttons right of it, through which i am able to manipulate the image
    Questions:
    *1. Is it (even) possible to display an (jpeg,gif) image in the "display area" while using a layout manager?*
    Surfing over the internet...so far i only have found applet-examples that use the full gui surface of the applet to display an image via the g.drawImage (imagename, x,y); without any gui elements (labels, buttons) beside it.
    *2. What kind of AWT gui element do i need at the location of the "display area"?*
    Is is possible to use a CANVAS or do i need somethen else? (e.g. glue an image on a button)
    *3. Is is possible to display an ANIMATION (series of sequences jpeg, gifs) in the display area?*
    I already found out how to locate and load the images (via mediatracker).
    Now i need to find a way to "paint" the loaded images in the GUI.
    *4. Is this even possible with AWT layout or do i need to switch to SWING layout?*
    I have not used Swing yet, cause i'm working my way up through the oldest gui technologie first.
    *5. Do know any usefull websites, online tutorials (on awt and displaying images) that can help me tackle my challenge?*
    Thank you very much for your hints, tips and tricks

    A link as Gary pointed out is the best way to see what the problem may be.
    Did you save the image to your working folder and have you defined a site pointing to this folder.
    Defining a site helps Dreamweaver track and organize the files used in this site.
    http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_14028
    If you can't see the image, this means that the path to the image is incorrect.
    Nadia
    Adobe Community Expert : Dreamweaver
    Unique CSS Templates | Tutorials | SEO Articles
    http://www.DreamweaverResources.com
    Web Design & Development
    http://www.perrelink.com.au
    http://twitter.com/nadiap

  • Jpeg/gif attachments in GW2012 client on Windows7 slideshow

    Hi,
    We have noticed this on a few PCs so far.
    Gw2012 client on Windows 7 64-bit.
    Problem only noticed in jpeg/gif attachments.
    When the user right-clicks and OPENs a jpeg/gif attachment, the file opens in the Windows Photo Viewer. However, it defaults to a slide show and starts showing other jpeg/gifs which were opened in the previous emails. How can we stop the slideshow and have only the opened file displayed?
    Anyone has experienced this problem?
    Any help in this regard would be greatly appreciated.
    Regards,
    Yaser

    yasers wrote:
    > We have noticed this on a few PCs so far.
    >
    > Gw2012 client on Windows 7 64-bit.
    >
    > Problem only noticed in jpeg/gif attachments.
    >
    > When the user right-clicks and OPENs a jpeg/gif attachment, the file
    > opens in the Windows Photo Viewer. However, it defaults to a slide
    > show and starts showing other jpeg/gifs which were opened in the
    > previous emails. How can we stop the slideshow and have only the
    > opened file displayed?
    >
    > Anyone has experienced this problem?
    I've had this problem with Windows photo viewer on Windows 7 64-bit,
    but even outside of GroupWise. Just go to My Documents and
    double-click a JPG and the same thing happens, after about 3-4 seconds
    you'll suddenly be looking at another picture in the same directory.
    I've never found a solution other than to use something other than
    Windows Photo Viewer. But again based on my experience it has nothing
    to do with GW.
    We're your Novell--again. http://www.novell.com/promo/backtobasics.html
    BrainShare 2013 is coming! http://www.brainshare.com

  • JPEG/GIF image to BASE64

    Hi,
    I like to convert JPEG/GIF or any type of image into BASE64 format and Viceversa. Can somebody provide me the java code for doing this.
    Cheers,
    Siva Maranani.

    Rather than use an undocumented API, I would suggest a 3rd party library for Base64 encoding such as the one that I wrote:
    http://ostermiller.org/utils/Base64.html
    It even has several convenience methods for encoding files:
    static void      encode(File fIn)
    Encode this file in Base64.
    static void      encode(File fIn, boolean lineBreaks)
    Encode this file in Base64.
    static void      encode(File fIn, File fOut)
    Encode this file in Base64.
    static void      encode(File fIn, File fOut, boolean lineBreaks)
    Encode this file in Base64.

  • Dynamically convert swf to jpeg/gif format

    hello,
    I need a help to dynamically convert swf to jpeg/gif format
    using java/jsp
    this feature is implemented in php in the below URL
    http://www.sephiroth.it/tutorials/flashPHP/print_screen/index.php
    Thanks and regards
    Namratha

    You need to go here:
    Screen
    Cap Using Flash 8 and PHP
    It is exactly what you need.
    Walter
    And you can kiss the ground and thank God above that I was
    able to point you to this, it took me months to find!!!

  • How is add/insert jpeg/gif files on wiki (code gallery)

    Hi;
    I prepared new wiki-code gallery page. I must insert/add jpeg/gif files on my page. But I dont know  How is add/insert jpeg/gif files on wiki (code gallery).
    Please help me.
    Thanks.
    http://wiki.sdn.sap.com/wiki/display/Snippets/NewTimeDomainandConversionRoutineforTotalTime

    Hi;
    Mr Moshe Naveh helped me. He sended me new template page.
    I again prepared my wiki with new template.  ( http://wiki.sdn.sap.com/wiki/pages/createpage-entervariables.action?spaceKey=stage&templateId=113147905 ) I added jpeg files on new wiki page.
    Then He moved my new page.
    Thanks him.
    Best regards.

  • Convert jpeg, gif, etc. to DST format

    on a hunt for a program that will convert jpeg, gif, etc. to DST format.  Looking to do some embroidering, and not break the bank.

    Not possible. CAD files aren't simple graphics.
    Also, there doesn't appear be any Mac supported application which will open embroidery files.

  • BufferedImage doesn't draw every gif

    hi all,
    I create a buffered Image which should show 2 different gifs (not animated). my problem is that it draws only one of them. I don't think that it has to do with the gif itself because I tried the same drawing without buffering and everything could be seen.
    private BufferedImage bufferedBG;
    setBG();
    private void setBG() { 
    Image linieH = getToolkit().getImage(getClass().getResource("img/bg_linieH.gif"));
    Image linieV = getToolkit().getImage(getClass().getResource("img/bg_linieV.gif"));
    setBackground( Color.WHITE );
    bufferedBG = new BufferedImage( 676 + OFFSET_X, 578, BufferedImage.TYPE_INT_ARGB );
    Graphics2D g = bufferedBG.createGraphics();
    g.drawImage(linieH, 100,200, this);
    g.drawImage(linieV, 150,300, this);
    public void paint( Graphics g ) {
    Graphics2D g2 = (Graphics2D) g;
    g2.drawImage( bufferedBG, null, 0, 0 );
    any ideas?
    thanks
    gammloop

    I strongly suspect that what we have here may be confusion about user space and device space..
    The Graphics2D instance in your image class DOES NOT share coords with your paint(Graphics g)
    instance! Its x, y start is 0, 0 and bears no relation to the position on-screen of the component you are
    trying to paint...

  • All files in one group of folders (jpeg, gif, doc, ppt and pdf) do not open.

    I have a lot of files that I use as teaching material (gifs, jpegs, pdfs, web archives, Word files, PowerPoint presentations) that are in a number of different folders and which I store on an external drive, then copy every year to my hard drive when I teach that subject. I update these files and folders, then copy back to the external hard drive when I have finished teaching. These were all fine last year, but when I try to open any of the files, they all have problems. The image files in Photoshop have the error 'unknown or invalid JPEG marker', in Preview the error is 'it may be damaged or use a file format that Preview doesn't recognise', the PDFs return 'not a supported file type or the file has been damaged', the Word files as to be converted when opened and return nonsense, and the Powerpoint presentations return 'PowerPoint found a problem with content in the file' and after attempting to repair returns 'the file may be damaged'. Any idea what is going on here and how I can fix this? There are 1400 items, which have taken years to compile for my teaching. I have tried opening the files on my external hard drive and on my backup disc, but the same happens.
    I've never posted on a forum before, so I hope this is the right place to ask! Any help is most welcome!

    The backup files are more recent than when I used them a year ago - I have tried them and I still get the same problem.

Maybe you are looking for

  • JSXBIN

    Hi i have a problem  with javascript file encoding binary. If i run a javascript file it function but if i transform it in binary indesign return me a problem. And Why the targetengine not function with javascript binary? Thank

  • Psd file got corrupted in redraw and is still corrupted, even though i didn't save the file.

    sorry for the long headline, but can't figure out how to shorten... i'm using photoshop CS 5.5. the image below is the result of making a change, zooming in and the redraw created this: as i zoomed out, the image progressively filled into normal by t

  • Installing adobe acrobat X

    I recently had my hard drive replaced and went to install ADOBE ACROBAT X and it is not working.  When I goto SCAN, PDF, from SCANNER BLACK AND WHITE DOUMENT, THE selection is whited out and can not select it.  As a result I can scan only one item at

  • Scientic characters not inserting correctly

    Hi, I work with Oracle Clinical 4.0.3 and occasionally have to use 'special' characters such as beta ß. Usually just use a ascii character map and type alt+225 etc. However, this morning this does not appear to be working. Rather than ß I get SS. Any

  • Photo resolution on new computer

    I have noticed that the photo resolution on my new system is much smaller than on my old G4 iBook. The original size of the photos was in 1-2 meg size with great resolution. Now they are 40-50K. When I export them to a digital photo frame they are re