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

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,

Your' better off looking in the java 2d forum.
package images;
import java.awt.*;
import java.awt.image.*;
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) {
     public void setImage(BufferedImage im) {
          image = im;
          if (im != null) {
                    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) {
          //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 =;
               logoImage =
                    new LogoImage(
                         new Dimension(image.getWidth(), image.getHeight()));
          } catch (Exception 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);
}Now you can use this class anywhere in your pgram to add a JPanel

Similar Messages

  • 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
    //Create a label to display the background image.
    bgLabel = new JLabel(bgIcon);
    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();
    new Dimension(bgWidth, bgHeight));
    layeredPane.addMouseListener(new MouseAdapter() {
    public void mousePressed(MouseEvent e) {
    if (frozen) {
    frozen = false;
    } else {
    frozen = true;
    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() {
    //Invoked by the applet browser only.
    public void stop() {
    public synchronized void startAnimation() {
    if (frozen) {
    //Do nothing. The user has requested that we
    //stop changing the image.
    } else {
    //Start animating!
    if (!timer.isRunning()) {
    public synchronized void stopAnimation() {
    //Stop the animating thread.
    if (timer.isRunning()) {
    public void actionPerformed(ActionEvent e) {
    //Advance animation frame.
    //Display it.
    % (fgWidth + bgWidth))
    - fgWidth,
    (bgHeight - fgHeight)/2);
    //Invoked only when run as an application.
    public static void main(String[] args) {
    Image bgImage = Toolkit.getDefaultToolkit().getImage(
    Image fgImage = Toolkit.getDefaultToolkit().getImage(
    final MovingLabels movingLabels = new MovingLabels();
    JFrame f = new JFrame("MovingLabels");
    f.addWindowListener(new WindowAdapter() {
    public void windowIconified(WindowEvent e) {
    public void windowDeiconified(WindowEvent e) {
    public void windowClosing(WindowEvent e) {
    movingLabels.buildUI(f.getContentPane(), bgImage, fgImage);
    f.setSize(500, 125);

  • How to: add images into an Interactive PDF

    I was wondering if it was possible to add images into an interactive PDF once it has been sent to someone. The PDFs are forms that need to be filled by a client via their iPads using Adobe Expert, and they may need to occasionally attach images to the document and be able to edit these images (i.e. circle parts of the image to highlight them) then send these PDF's back to myself.
    Is there a way this can be done?

    There is no program on the iPad called Adobe Expert. I think you mean Adobe Reader.
    Adobe Reader lets you fill in forms but not to attach images. If you wish to make a request of the Adobe Reader product manager, you can post on the Adobe Reader for iOS forum here:

  • How [Insert|Add] Image into Opening PDF file with Acrobat SDK.

    Hi Guys,
    I'm trying to insert|add image file into opening PDF file with specified location (X|Y) and scale (Width|Hight) but got many of troubles
    If use third party like iTextSharp or something else thing become simple but i want to use Acrobat SDK to do this
    Any suggestion or idea?
    Any help appreciated.

    Thank for your interested.
    I use VB.NET and Acrobat
    Here is some my code:
       If File.Exists(T(0)) Then
       Dim AcroAVDoc As AcroAVDoc = Ap.GetActiveDoc
       Dim AcroPDDoc As AcroPDDoc = AcroAVDoc.GetPDDoc
       Dim AcroPDPage As Acrobat.AcroPDPage = AcroPDDoc.AcquirePage(Integer.Parse(T(3)))
       Dim data() As String = T(1).Split("^")
       Dim imgX = data(0)
       Dim imgY = data(1)
       Dim imgWidth = data(3)
       Dim imgHight = data(4)
       'TODO: insert into opening PDF file
       Return 1
       End If
       Catch ex As Exception
       End Try
    I don not know what to do next to insert an image (JPEG, PNG, ..) into PDF file.
    Can you show me or suggest some solution, idea?
    Thank in advance.

  • How to Add Image to Web Dynpor Application

    I want to develop new view with two elements
       1. Label
       2. image
    lable properties are
         text property: Welcome to My Page
         design property: header1
    image properties are
            source:  img1.jpeg
    i created view and in the view i creatge label with out any error.
    comming to image  i inserted child to view root element and to select SOURCE for the image element its showing context window.
    i am not able to see here any image fine
    one thing to tel u that i already placed IMAGE.JPEG under /MIME/MYCOMPONENT/IMAGE.JPEG
    So please let me know how to get the image  in the form..

    1. Add an another UI element like Caption along with a label
    2. Create a Value Attribute for the image and make its Calculated property to true. This automatically creates the setter and getter methods to retrieve the image.
    Bind the image source property to this created value attribute.
    3.  In the get<value attribute> method, return the image.(image file name and extension are case sensitive - for ex: Image.jpeg)
    Thanks and Regards,
    Amar Bhagat Challa

  • How to save image into blob:java.sql.SQLException: ORA-01465:nvalid hex

    hi all,
    I am trying to save an image (blob) into oracle. When i try this i am getting following error.
                      java.sql.SQLException: ORA-01465: invalid hex number
                             BLOB blob = BLOB.createTemporary(con , false, BLOB.DURATION_SESSION);
                       String dir = "C:\\opt\\temp";
                       File binaryFile = new File(dir+"/"+filename);
                                FileInputStream instream = new FileInputStream(binaryFile);
                          OutputStream outstream = blob.setBinaryStream(1L);
                          int size = blob.getBufferSize();
                          byte[] buffer = new byte[size];
                          int length = -1;
                          while ((length = != -1)
                            outstream.write(buffer, 0, length);
                    String sqlText =
                              "INSERT INTO test_fileupload (filename, blobfile) " +
                              "   VALUES('" + filename + "','" + outstream  + "')";
                          con.commit();In the above Insert statement i tried with "blob" insted of "outstream" still same but when i try with the string "3s34se"
    it is inserting into database..
    I am new to blob can any one explain me why is like that.
    Thanq in adv.
    Edited by: Ajayuppalapati on Nov 21, 2008 4:40 PM

    ORA-01465: invalid hex number

  • How To Add Flash Movie In Java Application

    Hello Every One
    I am facing a problem.
    I want to add a flash movie
    Plz Help Me

    Flash Player Java Edition is available - but only for old Flash V.2 :(

  • How to change heap memory size for general java applications (not applets)

    Hi. I made a java class which manipulates images and I sometimes get an out of memory error when the files are large. In these cases I can run it successfully from the command line using:
    java -Xms32m -Xmx128m myappbut as I run this class from a firefox extension, I can't use this technique.
    Could some one tell me how to set this globally? I've found a lot of info on setting it for applets in the control panel but that's it. I also tried editing my file by adding:
    deployment.javapi.jre.1.6.0_11-b03.args=-Xmx128mbut none of these options seem to work.
    Thanks for any help.

    Also you can use use [JAVA_TOOL_OPTIONS|], with more documentation here. JAVA_TOOLS_OPTIONS is available since 1.5. There is no direct documentation on [_JAVA_OPTIONS|] but was made available since at least 1.3.
    The recent existing forum thread [Java Programming - How to change the default memory limits for java.|] has a long discussion on the issue.
    You specified you are not using applets, but if you do, I would also suggest you use the next Generation Plug-in (since 1.6.0_10) that allows you specify the max memory in the applet without having to instruct the user how to make the change. See [JAVA_ARGUMENTS|] for applets. Java Webstart uses resources.

  • Repaint in Java application (not Applet)

    I have server application with GUI containing TextArea. On any connection request from client, the application creates a thread which deals with the client request. Once the client request finishes, I want to show the detail of the client which connected to the server in the TextArea. Now I have extended the main server class for the thread class, which deals with the client, and have a method in the main server class which appends string on the textarea. BUT, when thread call that function nothing appears in the TextArea. I have checked that the thread is calling the method correctly, I think I need to repaint the TextArea. How? I am looking for your help. I have tried repaint, it does not work. Appreciate any help in this regard,
    Here is the code.
    Server side.......
    public synchronized void displayMessage( String thismessage) {
         System.out.println("-----> " + thismessage);
         editPan.append(thismessage + "\n");
    public void run() {
    while(true) {
    try {
    server = new ServerSocket( 5000, 100 );
    while(listening) {
    connection = server.accept();
    if(connection != null) {
    alertDialog cThread = new alertDialog(connection, errorNumber);
    (new Thread(cThread)).start();
    connection = null;
    catch( IOException e ) {
    System.out.println("Exception : " + e.toString() );
    Client Attender Thread class (alertDialog) which extends server class......
    public void run() {
    try {
    BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    String inputLine = in.readLine();
    System.out.println(" " + dateString + " " + inputLine );
    // super.editPan.append(" Test from alert.. \n");
         super.displayMessage(" " + dateString + " " + inputLine);
    JOptionPane.showMessageDialog(null, inputLine, "Alert....", JOptionPane.ERROR_MESSAGE);
    } catch (IOException e) {

    Be careful when calling Swing methods from outside the EventDispatch thread. If you call a swing method from a thread, you should use SwingUtilities.invokeAndWait() or SwingUtilities.invokeLater().
    See for more details.

  • How to assign the Thems into Webdynpro Java Application

    HI All,
                   I Downloaded the plugin for them editor and i add those plugins and i created the Them. Please any one can help me how to add that Them into Webdynpro java application.

    Hi ep bhargav,
    You can check this link.....
    Re: webdynpro theme editor

  • How to import the image by using java application to import the image by using java APPLICATION and display it on the textarea that you have been created. 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.
    regards fenny

    follow the link:

  • 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

  • How to add image to webdynpro screen . ?

    How to add image to webdynpro screen . ?

    right click ur application and then click on create mime object.
    with Mime Objects u cn upload doc , jpeg, or giff files from our local system into the webdypnpro system .
    You can even try creating the MIME objects in webdynrpo abap .
    Right click on ur component->mime object->import
    after importing you can see that image into your component as MIME object .Now insert a UI element image into your view layout .
    Go to the source property of IMAGE element and select F4 option , u will find a window is opening with some tabs
    Select tab COMPONENT IMAGES and component name select your component .
    You will find the image which you have imported into this section just select the image and save it.
    In the transaction sicf/bc/webdynpro , u cn check your component name there you can view the mime objects created by you .
    also refer the SAP online help :
    to knw more abt mime repositories.

  • How to use OLE Components in Java Application?

    I try to make program that is able to include OLE components( Excel sheet, MS Word document, and so on ), and that can control these components.
    I want to know that Java Application or Applet can control and show OLE components like JavaBeans components. If that, How to ?

    Try this to generate a Word file.....
    import com.jacob.activeX.*;
    public class ExportDOC {
    public ExportDOC () {
    //Application type
    ActiveXComponent doc = new ActiveXComponent("Word.Application");
    //Application visible
    doc.setProperty("Visible", new Variant(true));
    Object documents = doc.getProperty("Documents").toDispatch();
    //Open a file already exits
    //Object document =, "Open", "c:/nameFile.doc").toDispatch();
    //Open a new file empty
    Object document =, "Add", "").toDispatch();
    Object selection = Dispatch.get(doc,"Selection").toDispatch();
    //Text Format
    Object font = Dispatch.get(selection, "Font").toDispatch();
    Object alignment = Dispatch.get(selection, "ParagraphFormat").toDispatch();
    Object image = Dispatch.get(selection, "InLineShapes").toDispatch();
    //I put the selection at the end of the file for if I want to add text
    //, "EndKey", "6");
    //Text format (bold & italic)
    Dispatch.put(font, "Bold", "1");
    Dispatch.put(font, "Italic", "1");
    //To jump line, "TypeParagraph");
    //Align center (0= left, 1=center, 2=right, 3=justify)
    Dispatch.put(alignment, "Alignment", "1");
    //Insert image, "AddPicture", "c:/graf.jpg");, "TypeParagraph");
    Dispatch.put(alignment, "Alignment", "3");
    //Insert Text, "TypeText", "Text ....... ");
    //Original values, "TypeParagraph");
    Dispatch.put(alignment, "Alignment", "0");
    Dispatch.put(font, "Bold", "0");
    Dispatch.put(font, "Italic", "0");
    //To jump page
    //, "InsertBreak");
    //Save the document
    //, "SaveAs", "c:/test.doc");
    //Quit the application
    //dc.invoke("Quit", new Variant[] {});
    public static void main(String[] args) {
    ExportDOC e = new ExportDOC();
    but you must download 'jacob.jar' in....
    is a FREEWARE!!!

  • How to import image for display in APPLICATION to import the image by using java APPLICATION and display it on the textarea that you have been created. 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.
    regards fenny

    You can use Graphics package for importing images in Java applications. But I am afraid you cannot display it on Text area, you can display it on JPanel, or JLabel or some container like this.
    Check this example.

Maybe you are looking for

  • How to retrieve the data from SAP-BAPI by using VB Code

    Hi , I am new to BAPI. V have created an application in Visual Basic with the following fields EmpNo , EmpName, Addr1, Addr2, City and Phone (Only for Test) We have written the code for SAVING the data into SAP. Already we have constructed a table wi

  • I bought my iphone from australia and i cant use it here in philippines

    My husband bought a 2nd hand iphone from Australia for a present. but doesnt work here in philippines. I try to connect to itunes but looks like is lock. we already call the telstra as what my husband say its working properly there, but until now, do

  • JTable Cell Renderer

    New to Swing ... I have a JTable that I fill with data from a database. Some of the pieces of data have a flag associated with it to say whether that data is a cause for a problem. I would like the background of the specific piece of data (i.e., the

  • Bitmap Fill is not working as thought

    I am working on a simple target game. I have a class created that inherits from Sprite called TargetSprite. TargetSprite creates a resize matrix, sets beginBitmapFill, sets the line type, then draws a circle, then ends the fill. The problem is that i

  • Multiple airporter setups

    I have an airporter extreme that's working fine. I want to set up a newly purchased one for my daughter (in another city) who has a PC (win7) and iPad. Can I do the setup on my iMac with the new utility disc then take airporter to her? She's going to