Results 1 to 3 of 3
  1. #1
    Rhez is offline Member
    Join Date
    Oct 2009
    Posts
    17
    Rep Power
    0

    Default Help: Displaying Images AND Adding Buttons

    At first I had no idea how to display images in a window displayer, so I browsed through the web to find some code, and ended up with:
    http://download.oracle.com/javase/tu...dImageApp.java

    OK, so the program runs to display an image, no problem there. I copied the code for my own class so then I can display my own image(s). The problem now is that I also want to add buttons in the same program; in this case, I need to get my class to extends EasyApp. The idea is to add 4 directional buttons (up, down, left, right) in which I can move the image a number amount of pixels (with a border limit); simple. However, because my class is already extending another class (Component or EasyApp), there can not be multiple inheritance using extends. Either I have no image(s), or I have no buttons, or the code doesn't compile, or the program doesn't work. I am not so sure about implements right now (I have barely any knowledge on it).

    Is there any alternative code to make this work? Or do I have to create separate classes? Or what should I do?
    Last edited by Rhez; 08-05-2010 at 05:28 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    If I want my GUI to have a background image, I usually extend JPanel and then draw the image in the JPanel's paintComponent method and then add this JPanel to the JFrame's contentPane. Then I can add whatever components I'd like to this JPanel, but taking sure that if I add other JPanels, I call setOpaque(false) on them first.

    You'll find plenty of example code for doing this here at other forum sites, and via google.

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,226
    Rep Power
    6

    Default

    Create an ImageIcon using the Image and add the Icon to a JLabel. Then you can add the label to a JPanel using a null layout. the label can be moved by invoking the setLocation() method of the label.

Similar Threads

  1. Displaying Radio Buttons in JSP
    By kishan in forum Advanced Java
    Replies: 4
    Last Post: 10-23-2009, 03:44 PM
  2. Changing images by clicking arrow buttons. help?
    By ashton in forum New To Java
    Replies: 3
    Last Post: 02-08-2009, 11:29 AM
  3. Displaying large images
    By pir8ped in forum AWT / Swing
    Replies: 2
    Last Post: 01-21-2009, 09:20 PM
  4. [SOLVED] Need help in displaying images
    By kirly in forum Advanced Java
    Replies: 3
    Last Post: 10-21-2008, 05:36 AM
  5. Images not displaying in JSP in IE7
    By chadscc in forum Advanced Java
    Replies: 0
    Last Post: 11-13-2007, 03:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •