1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
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 ");

    add(ok);
    }
    }

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

    demo frm = new demo();

    frm.setup();
    frm.setBackground(Color.gray);
    frm.setTitle("Logon Message");
    frm.setSize(width, height);
    frm.setVisible(true);
    }
    }

    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!
    -Jon
     
  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

    chroot

    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
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Importing Images to a Java frame
  1. Java's Scanner (Replies: 6)

  2. Java Help (Replies: 7)

  3. Java help (Replies: 15)

  4. Java q (Replies: 3)

  5. Java problem. (Replies: 4)

Loading...