Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Importing Images to a Java frame

  1. Jan 13, 2005 #1
    [SOLVED] Importing Images to a Java frame

    Hey guys,

    I have a very simple java program. I opens a frame, and I want to be able to put a picture in the frame. How do I import a picture and set it as the background to the frame?

    Here is my simple program:

    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;

    class demo extends Frame
    void setup()
    setLayout(new FlowLayout());

    Button ok = new Button(" OK ");


    public class window
    public static void main (String[] args)
    int width = 700, height = 134;

    demo frm = new demo();

    frm.setTitle("Logon Message");
    frm.setSize(width, height);

    so as you can see it is an extremely basic window, and I would like to import a graphic as the background to the window within the setup() method.

    Any help much appreciated, thanks!
  2. jcsd
  3. Jan 15, 2005 #2
    somebody must know this
  4. Jan 15, 2005 #3
    Create a Panel and call the drawImage method in its Graphics object.
  5. Jan 15, 2005 #4


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Use a Canvas with an overridden paint() method, or an ImageIcon.

    - Warren
  6. Jan 16, 2005 #5
    :thumbsup: thanks guys
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook