Display an Image in a Java application !

Hi all !
Really i want to display an image in a java application , i know how to do it in applets but this method does not work in applications so please help me to do that in an application ,thanks .

it is the same way as in applets.
1. Open a frame with awt
2. Define an Image (like: Image a=null;)
3. Load this Image with the Toolkit....(just look which method to use)
4. draw this image to screen with g.drawImage(...)
Note the class drawing the image must implement ImageObserver.
regards

Similar Messages

  • How to import the image by using java application

    1.how to import the image by using java APPLICATION and display it on the textarea that you have been created.
    2.how to store the image into the file.
    3. what class should i used?
    4. how to create an object to keep track the image in java application.
    * important : not java applet.
    plzzzzzzz.
    regards fenny

    follow the link:
    http://java.sun.com/docs/books/tutorial/2d/images/index.html

  • How can I put an image/s in Java Application?

    Hi to all.
    How can I put an image/s in Java Application?
    I can put some images in Java applet but when i try to put it in Java application there was an error.

    hey u can easily do it with JLabels...i found a Code Snippet for u
    public class MyPanel extends JPanel
    {private JLabel imageLabel; public MyPanel() {     Image image = Toolkit.getDefaultToolkit().getImage("myimage.gif"); // Could be jpg or png too     imageLabel = new JLabel(new ImageIcon(image));     this.add(imageLabel);  }}
    hope it helps
    Cheers,
    Manja

  • How to add images into a java application (not applet)

    Hello,
    I am new in java programming. I would like to know how to add images into a java application (not an applet). If i could get an standard example about how to add a image to a java application, I would apreciated it. Any help will be greatly apreciated.
    Thank you,
    Oscar

    Your' better off looking in the java 2d forum.
    package images;
    import java.awt.*;
    import java.awt.image.*;
    import java.io.FileInputStream;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    /** * LogoImage is a class that is used to load images into the program */
    public class LogoImage extends JPanel {
         private BufferedImage image;
         private int factor = 1; /** Creates a new instance of ImagePanel */
         public LogoImage() {
              this(new Dimension(600, 50));
         public LogoImage(Dimension sz) {
              //setBackground(Color.green);      
              setPreferredSize(sz);
         public void setImage(BufferedImage im) {
              image = im;
              if (im != null) {
                   setPreferredSize(
                        new Dimension(image.getWidth(), image.getHeight()));
              } else {
                   setPreferredSize(new Dimension(200, 200));
         public void setImageSizeFactor(int factor) {
              this.factor = factor;
         public void paintComponent(Graphics g) {
              super.paintComponent(g);
              //paint background 
              Graphics2D g2D = (Graphics2D) g;
              //Draw image at its natural size first. 
              if (image != null) {
                   g2D.drawImage(image, null, 0, 0);
         public static LogoImage createImage(String filename) { /* Stream the logo gif file into an image object */
              LogoImage logoImage = new LogoImage();
              BufferedImage image;
              try {
                   FileInputStream fileInput =
                        new FileInputStream("images/" + filename);
                   image = ImageIO.read(fileInput);
                   logoImage =
                        new LogoImage(
                             new Dimension(image.getWidth(), image.getHeight()));
                   fileInput.close();
                   logoImage.setImage(image);
              } catch (Exception e) {
                   System.err.println(e);
              return logoImage;
         public static void main(String[] args) {
              JFrame jf = new JFrame("testImage");
              Container cp = jf.getContentPane();
              cp.add(LogoImage.createImage("logo.gif"), BorderLayout.CENTER);
              jf.setVisible(true);
              jf.pack();
    }Now you can use this class anywhere in your pgram to add a JPanel

  • Help on moving of image across screen(java application,not applet)

    I've searched the entire internet and everything I've found is on java applets and I'm an alien to the differences between an applet and an application.
    This is actually for a java game I'm creating using Eclipse's visual editor and I'm failing miserably.
    What I'm trying to do is to find some java source code that enables me to start an image automatically moving across the screen that only stops when I click on it. I did find some applet codes but when I tried converting it to application code a load of errors popped out.
    Thanks for the help if there's any! I'm getting desperate here because the game's due this friday and I'm stuck at this stage for who knows how long.

    Here is one of the codes I found ,it's not mine but I'm trying to edit it into a java application instead of an applet...Sort of like: ' public class MovingLabels extends JFrame ' or some code that I can copy and paste into another java program.
    * Swing version.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class MovingLabels extends JApplet
    implements ActionListener {
    int frameNumber = -1;
    Timer timer;
    boolean frozen = false;
    JLayeredPane layeredPane;
    JLabel bgLabel, fgLabel;
    int fgHeight, fgWidth;
    int bgHeight, bgWidth;
    static String fgFile = "wow.gif";
    static String bgFile = "Spring.jpg";
    //Invoked only when run as an applet.
    public void init() {
    Image bgImage = getImage(getCodeBase(), bgFile);
    Image fgImage = getImage(getCodeBase(), fgFile);
    buildUI(getContentPane(), bgImage, fgImage);
    void buildUI(Container container, Image bgImage, Image fgImage) {
    final ImageIcon bgIcon = new ImageIcon(bgImage);
    final ImageIcon fgIcon = new ImageIcon(fgImage);
    bgWidth = bgIcon.getIconWidth();
    bgHeight = bgIcon.getIconHeight();
    fgWidth = fgIcon.getIconWidth();
    fgHeight = fgIcon.getIconHeight();
    //Set up a timer that calls this object's action handler
    timer = new Timer(100, this); //delay = 100 ms
    timer.setInitialDelay(0);
    timer.setCoalesce(true);
    //Create a label to display the background image.
    bgLabel = new JLabel(bgIcon);
    bgLabel.setOpaque(true);
    bgLabel.setBounds(0, 0, bgWidth, bgHeight);
    //Create a label to display the foreground image.
    fgLabel = new JLabel(fgIcon);
    fgLabel.setBounds(-fgWidth, -fgHeight, fgWidth, fgHeight);
    //Create the layered pane to hold the labels.
    layeredPane = new JLayeredPane();
    layeredPane.setPreferredSize(
    new Dimension(bgWidth, bgHeight));
    layeredPane.addMouseListener(new MouseAdapter() {
    public void mousePressed(MouseEvent e) {
    if (frozen) {
    frozen = false;
    startAnimation();
    } else {
    frozen = true;
    stopAnimation();
    layeredPane.add(bgLabel, new Integer(0)); //low layer
    layeredPane.add(fgLabel, new Integer(1)); //high layer
    container.add(layeredPane, BorderLayout.CENTER);
    //Invoked by the applet browser only.
    public void start() {
    startAnimation();
    //Invoked by the applet browser only.
    public void stop() {
    stopAnimation();
    public synchronized void startAnimation() {
    if (frozen) {
    //Do nothing. The user has requested that we
    //stop changing the image.
    } else {
    //Start animating!
    if (!timer.isRunning()) {
    timer.start();
    public synchronized void stopAnimation() {
    //Stop the animating thread.
    if (timer.isRunning()) {
    timer.stop();
    public void actionPerformed(ActionEvent e) {
    //Advance animation frame.
    frameNumber++;
    //Display it.
    fgLabel.setLocation(
    ((frameNumber*5)
    % (fgWidth + bgWidth))
    - fgWidth,
    (bgHeight - fgHeight)/2);
    //Invoked only when run as an application.
    public static void main(String[] args) {
    Image bgImage = Toolkit.getDefaultToolkit().getImage(
    MovingLabels.bgFile);
    Image fgImage = Toolkit.getDefaultToolkit().getImage(
    MovingLabels.fgFile);
    final MovingLabels movingLabels = new MovingLabels();
    JFrame f = new JFrame("MovingLabels");
    f.addWindowListener(new WindowAdapter() {
    public void windowIconified(WindowEvent e) {
    movingLabels.stopAnimation();
    public void windowDeiconified(WindowEvent e) {
    movingLabels.startAnimation();
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    movingLabels.buildUI(f.getContentPane(), bgImage, fgImage);
    f.setSize(500, 125);
    f.setVisible(true);
    movingLabels.startAnimation();
    }

  • How to display BLOB image column with WEB application, JSF, ADF BC

    I looking for a way to display the content from a blob column on a WEB application, JSF, ADF BC
    The blob column contains a JPEG image.
    About the application
    The model contains a viewobject where the blob column attribute (photoimg) type is of type : BlobDomain
    Now I have to create the view to display the content of photoimg inside a JSF-JSP page.
    Any advice ?

    Search is your friend
    How to display the content of a BLOB column in a ADF/BC pages ?
    John

  • Displaying UWL tasks in Webdynpro java application

    Dear Experts,
    I am developing a WebDynpro Java application to access uwl tasks,
    Have added the following code in try catch block with external jars
    1. prtapi.jar
    2. bc.uwl.service.api.jar
    IUWLService uwlService = null;
    IWDClientUser user1 = WDClientUser.getLoggedInClientUser();
    IUser epUser =user1.getSAPUser();
    IPortalRuntimeResources runtimeResources = PortalRuntime.getRuntimeResources();
    if( runtimeResources == null)
       wdComponentAPI.getMessageManager().reportSuccess("Portal Runtime NULL");
    else
       uwlService = (IUWLService)runtimeResources.getService( IUWLService.ALIAS_KEY);
    UWLContext uwlContext = new UWLContext();
    IUser user = user1.getSAPUser();
    uwlContext.setUser(user);
    uwlService.beginSession(uwlContext, 20);
    IUWLItemManager itemManager = uwlService.getItemManager(uwlContext);
    QueryResult result = itemManager.getItems(uwlContext,null,null);
    int size = result.getTotalNumberOfItems();
    ItemCollection collection = result.getItems();
    java.util.List list = collection.list();
    Item item = null;
    Date date = null;
    String subject = null;
    for(int i = 0; i < 5; i++)
      if(!(i > (size -1)))
          item = collection.get(i);     
          date = item.getDueDate();     
          subject = item.getSubject();
         wdComponentAPI.getMessageManager().reportSuccess("item "+item);
         wdComponentAPI.getMessageManager().reportSuccess("date "+date);
         wdComponentAPI.getMessageManager().reportSuccess("subject "+subject);
      }//if
    }//for
    I have created this webdypro application with Authentication mode set as True.
    After deploying this application, i'm getting this error...
    "java.lang.NoClassDefFoundError: com/sap/netweaver/bc/uwl/IUWLService "
    can anybody tell me what is the problem???

    Hi
    see the following link it will be helpful for u.
    [UWL Tasks|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/49f2ea90-0201-0010-ce8e-de18b94aee2d#12]
    Regards
    Hazrath
    Edited by: Hazrath on Mar 25, 2008 8:01 AM

  • Displaying a URL from a Java application

    Hi,
    I recently implemented a test Java application based on Steven Spencer's Java Tip 66: "Control browsers from your Java application" (http://www.javaworld.com/javaworld/javatips/jw-javatip66.html). Spencer's example tests for the current operating system, sets some constants based on the OS that it finds, and then calls the Runtime.getRuntime( ).exec( ) method. During the call, you can pass either a file:// or http:// URL. I can get the example to work perfectly given a file:// URL but have limited success supplying the http:// URL. When I supply a specific http:// URL such as "http://someserver/somedir/testfile.htm" the browser returns a "Cannot open URL" error. However, if I supply a URL that does not resolve to a specific HTML file, such as "http://someserver/somedir", and the directory has either a "index.htm" or "index.html" file, the application works fine. I would like to be able to pass an http:// URL that resolves to a specific HTML file. I am trying to implement context-sensitive help from within a Java application. I am testing this on a machine running Windows 2000 and using Microsoft's IE 5.x browser. Any help would be appreciated.
    Thanks,
    Scott Rifenbark

    The browser doesn't know that it was started by this Java code, you know. So you are asking why your browser (Internet Explorer) doesn't let you get at specific files. The answer is, that isn't how the Internet works. A URL is a "Uniform Resource Locator" (or something a lot like that). It locates a resource on the Internet. This resource may or may not be a file, but as the client you have no way of knowing whether what you get in response to that is a file on the server or whether it has been generated by some CGI program there.
    When you send an http:// URL to a web server, it looks at what you have sent and goes through its configuration files. Using this it translates that URL into either a file on the server (which it returns to you) or a program which it calls to return data to you. If it was a file, its local name on the server doesn't have to be related in any way to the contents of the URL.
    It sounds like you are planning to be the one setting up those files on the server, though. If that's the case, you have to configure the server appropriately for your needs.

  • Image in Webdynpro Java Application

    Hi All,
    I have created a webdynpro application
    i kept imaage Lotus.jpg in src/mimes/components/component
    created a value node image attached this node to image ui source property
    in implementation
    weContext.currentcontextelment.setImage("Lotus.jpg");
    i am not abel to see image
    where am i going wrong
    Regards,
    Murali

    Hi Murali,
    I hope the above mentioned answers have solved ur problem. If yes then please close this thread else in webdynpro to show an image is very easy. As you mentioned you need to copy the image and paste it at Project>src>components>application copmponent>paste it. now you just need to got to the properties of the particular UI element in which you want to show the image. Then go to the imagesource property give the name exaclty similar to that of your pasted file for example if it's Lotus.jpg then give Lotus.jpg or if its Lotus then need not to add .jpg only add Lotus. This will definately work.
    Warm regards,
    Gaurav

  • Interfacing java application with digital camera

    Dear all,
    I've a question and I need your help.
    I've my swing/javafx application and I need to interface it with a digital camera.
    How should I proceed? How can I understand which digital camera offers support for java integration?
    Do you have some model for me?
    Thanks

    I don't know anything about using Java directly with digital cameras. However I have a few observations. When you say you want to interface Java with a digital camera, do you mean you just want to display the image in a Java application? If so, you can use the software that came with the digital camera to download the images as *.jpeg (or whatever) to the hard disk. Then you can use Java to easily read the files from the hard disk and display them or move them to some other location. For instance, when you display them in Java, then you can then ask the user to fill out various textfields to go along with the image such as giving a title to the image or a description.
    If instead you want to write Java to grab the images from the camera directly, I think that's a bad idea. I imagine different digital cameras have uniquely written custom software to communicate between the digital camera and say, Windows 7 (I'm guessing). I doubt all the manufacturers have agreed upon a common way to communicate. Therefore if you take this route, you will end up creating a large set of Java programs to communicate with each model of camera. A maintenance nightmare.
    However, I have seen applications such as taking passport photos that appear to communicate directly with a digital camera wired to the computer which I imagine the vendor supplied with the application.

  • Java Application [Java Bundler]: how I can use an image? Which path?

    Hi,
    how I can use an image in my Java Application when I create the jar bundle with Jar Bundler? Which is the path of the file? I don't know if I got it across...

    By image, do you mean an icon for your program?
    If so, then you need to create the image you want using any graphical drawing program, then use a utility such as Img2icns to put the image into the correct format (.icns). Once you have this, you can drag it into Jar Bundler and IIRC it just works.
    Bob

  • Displaying an image created at runtime.

    I am creating an image at run time (a bar code). How do I display this?
    To test a static image I placed the bar code image in the src/mimes/components/packages directory, then compiled that application and it worked perfectly.
    I then created the bar code image at run time and wrote it to the same src/mimes/components/packages directory as above. The file was succesfully placed there, but the application does not display the image. If the application is then recompiled with a a hard coded value of the previous bar code in the getImageImageSource method it works.
    I'm guessing that the run time repository for images is different to the design time one; is this is the case where should I be writing the image file and what should I return from the getImageImageSource method?
    Nigel

    Hallo Nigel,
    you can apply the Web Dynpro Binary Cache. Just store URL of the cached resource within a context attribute and bind the image url to this attribute.
    Implement the following coding:
    //@@begin javadoc:wdDoInit()
      /** Hook method called to initialize controller. */
      //@@end
      public void wdDoInit()
        //@@begin wdDoInit()
        wdContext.currentContextElement().setImgVisibility(WDVisibility.NONE);
        // Modify datatype, propare datatype for modifications done by the runtime
        wdContext.getNodeInfo().getAttribute("File").getModifiableSimpleType();
        //@@end
      //@@begin javadoc:onActionUpload(ServerEvent)
      /** Declared validating event handler. */
      //@@end
      public void onActionUpload(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
        //@@begin onActionUpload(ServerEvent)
        IWDCachedWebResource cachedResource = null;
        String imgUrl = null;
        WDWebResourceType type =
          ((IWDModifiableBinaryType) wdContext.getNodeInfo().getAttribute("File").getModifiableSimpleType())
            .getMimeType();
        byte[] file = wdContext.currentContextElement().getFile();
        if (file != null) {
          cachedResource = WDWebResource.getWebResource(file, type);
          try {
            imgUrl = cachedResource.getURL();
            wdContext.currentContextElement().setUrl(imgUrl);
            wdContext.currentContextElement().setImgVisibility(WDVisibility.VISIBLE);
          } catch (WDURLException e) {
            wdComponentAPI.getMessageManager().reportException(e.getLocalizedMessage(), true);
        //@@end
    Regards, Bertram

  • How do you display an image on a frame or panel?

    Can anyone tell me or point me towards a resource that explains how to display an image on a java fram or panel?
    Thanks,
    Eric

    You can create a JLabel with the image and then add the JLabel to the frame/panel.

  • Displaying Picture in a Java APPLICATION please help!!

    I have been trying to write a method that Displays a .jpg file when called. However I have not gotten far, every book I have tell you how to display pictures in an applet but not an application. I did find some code that is supposed to be for an application, but It does not compile right. Any help would be apprecidated!
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class PictureIt{
    public void makeImage() {
    //***Image Output Stream
    String imgFile
    = "d:\\temp\\TestImage.jpeg";
    out = new FileOutputStream(imgFile);
    BufferedImage image = null;
    image = (BufferedImage)createImage
    (panelJpeg.size.width, panelJpeg.size.height);
    Graphics g = image.getGraphics();
    panelJpeg.paintAll(g);
    }

    Displaying Picture in a Java APPLICATION please help!!
    Hope this helps.There is going to be two classes compile seperatly first class is what does the drawing
    here it is
    import javax.swing.*;
    import java.awt.*;
    public class draww extends JPanel {
    Image ball;
    int width1 = 100;
    int height1 = 100;
    public draww() {
    super();
    Toolkit kit = Toolkit.getDefaultToolkit();
    ball = kit.getImage("pic1.gif");
    public void paintComponent(Graphics comp) {
    Graphics2D comp2D = (Graphics2D) comp;
    comp2D.drawImage(ball, 20, 20, width1, height1, this);
    sound class is the container JFrame here it is
    import javax.swing.*;
    import java.awt.*;
    public class drawing extends JFrame {
    public drawing() {
    super("draw");
    setSize(400,400);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container pane = getContentPane();
    draww d = new draww();
    pane.add(d);
    setContentPane(pane);
    setVisible(true);
    public static void main(String[] args) {
    drawing drawing1 = new drawing();
    PS Hope this helps and see you around

  • Displaying image on the swings application

    Hi All,
    I want to display images onto my swing application. I was using ImageIcon and Class to getResource(filename). It can only provide me images that i have placed in my package not outside my package.
    Please help me, how to to do?
    Thanks in advance.

    [url http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html]How to Use Icons

Maybe you are looking for