Results 1 to 4 of 4
  1. #1
    Castles is offline Member
    Join Date
    Jan 2013
    Rep Power

    Default New to Java, Starting a Project

    Hi everyone, I'm quite new to Java and I am trying to make an app that can take an image from a source and relocate it to the app for display. So far, I have made a frame of " slots " for where the picture should go to, but I can't seem to put anything on top of my slot icons, not even a checkbox, let alone get another image to sit on top of it. I'm using Netbeans to try to create my app.

    If anybody could give me some tips of how to " layer " functions over each other, or any other advice at all, that would be just super !

    Thanks a bunch

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: New to Java, Starting a Project

    Please go through the Forum Rules, particularly the third paragraph.

    As your question stands, we have no idea which GUI toolkit you are using, what kind of "source" the image is obtained from, or where exactly you're stuck. To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.

    Note: if you happen to be trying out the NetBeans visual designer, drop it. It's categorically not a beginners' tool. Whatever some tutorials would have you believe, coding a simple GUI manually is far, far easier.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    kaydell2 is offline Senior Member
    Join Date
    Dec 2012
    Rep Power

    Default Re: New to Java, Starting a Project

    I worked on making an image program like you said, with images that could sit on top of images.

    I came up with the following class to display an image:

    Java Code:
    import java.awt.Graphics;
    import javax.swing.ImageIcon;
    import javax.swing.JPanel;
    public class ImagePanel extends JPanel {
    	private ImageIcon imageIcon;
    	public ImagePanel(int x, int y, ImageIcon imageIcon) {
    		this.imageIcon = imageIcon;
    		int width = imageIcon.getIconWidth();
    		int height = imageIcon.getIconHeight();
    		setBounds(x, y, width, height);
    	public void paint(Graphics g) {
    		if (imageIcon != null) {
    			imageIcon.paintIcon(this, g, getX(), getY());
    And, I came up with the following class to test it with. It partly works, but it is a work in progress. What makes the images able to sit on top of each other is setting the layout manger to null so that a layout manager isn't used.

    Java Code:
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.SwingUtilities;
    public class ImagePanelTest extends JFrame {
    	public ImagePanelTest(String fileName1, String fileName2) {
    		// by using null as the layout manager, images can be on top of each other
    		// create two image pannel objects
    		ImagePanel image1 = new ImagePanel(0,0,new ImageIcon(fileName1));
    		ImagePanel image2 = new ImagePanel(0,0,new ImageIcon(fileName2));
    		/// add each image to this frame
    		// setup other attributes of this  frame to make is ready to display images
    		setLocationRelativeTo(null); // center this frame on the screen
    	public static void main(String[] args) {
    		SwingUtilities.invokeLater(new Runnable() {
    			public void run() {
    				new ImagePanelTest("picture1.jpg", "picture2.jpg");
    If anybody has a better solution, please let me know.

  4. #4
    Castles is offline Member
    Join Date
    Jan 2013
    Rep Power

    Default Re: New to Java, Starting a Project

    Wow thank you so much ! I'll give this a go and it should really help!!

Similar Threads

  1. Just starting out...Project Idea
    By seguhi in forum Forum Lobby
    Replies: 1
    Last Post: 06-08-2012, 11:20 AM
  2. Starting Java GUI
    By nhrnjic in forum New To Java
    Replies: 3
    Last Post: 04-27-2012, 04:40 PM
  3. starting java
    By ashwin kumar in forum New To Java
    Replies: 11
    Last Post: 06-08-2011, 10:47 AM
  4. im starting a project soon but want some tips/help
    By ychen42 in forum New To Java
    Replies: 1
    Last Post: 11-12-2010, 02:17 AM
  5. Help, starting with java
    By mathias in forum New To Java
    Replies: 2
    Last Post: 08-15-2007, 08:15 AM

Posting Permissions

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