1

I create a frame with an image with this code:

    JFrame f = new JFrame();
    try {
            f.setContentPane(new JLabel(new ImageIcon(ImageIO.read(new File("image.jpg")))));
    } 
    catch (IOException e) {
            e.printStackTrace();
    }
    f.pack();
    f.setVisible(true);

That works fine, but now I want to paint something in that opened frame (on top of the image).

I'm quite new in Java, and I've allready tried to make a class that extends JFrame, with a paint(Graphics g) method in it, but it wouldn't work, I only see the image...

David Kroukamp
  • 36,155
  • 13
  • 81
  • 138
francisMi
  • 925
  • 3
  • 15
  • 31
  • You might be interested in [this](http://docs.oracle.com/javase/tutorial/uiswing/layout/box.html). Unless by above you mean on top of, then that link won't help you at all. – Jeffrey Jun 18 '12 at 01:49
  • I mean on top of it, so the paints are the upper layer... – francisMi Jun 18 '12 at 01:59
  • 2
    Search for 'glasspane' and you should find what you need. – dann.dev Jun 18 '12 at 02:01
  • What is the purpose of the image? It sounds like a splash screen. – Andrew Thompson Jun 18 '12 at 02:44
  • 1
    Here try this wonderful [example](http://stackoverflow.com/questions/10055005/how-to-draw-an-image-over-an-another-image/10055021#10055021) by @AndrewThompson – nIcE cOw Jun 18 '12 at 04:05
  • 2
    @nIcEcOw Actually mine was the answer below the one you linked to. ;) They were both good. :) – Andrew Thompson Jun 18 '12 at 04:37
  • @AndrewThompson : Too true, I was reading both the answers, though I reached that thingy from your search, they both are no doubt good :-) – nIcE cOw Jun 18 '12 at 04:57
  • I misread the question. See [this answer](http://stackoverflow.com/a/10930920/418556) for a **background image.** I put the image in a panel. The panel can then be put into a frame, applet, dialog etc. as needed. In [this thread](http://stackoverflow.com/q/10836832/418556) I find one way, and was offered another way, to load an *animated* image as BG. – Andrew Thompson Jun 18 '12 at 05:56

1 Answers1

2

Hmm well there are so many tutorials and without any code to go on its hard to say what you don't know or have done wrong, look at: Java Updating Small Circles , http://www.roseindia.net/java/example/java/awt/how-to-create-circle-in-java.shtml and http://oreilly.com/catalog/java2d/chapter/ch04.html remember to not draw in the same colour as your image background or else you wont see anything no matter how hard you try ;)

Community
  • 1
  • 1
David Kroukamp
  • 36,155
  • 13
  • 81
  • 138