Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/01/2013, 11:29
Elfede171
 
Fecha de Ingreso: agosto-2011
Ubicación: Montevideo
Mensajes: 44
Antigüedad: 12 años, 8 meses
Puntos: 5
Pregunta Imagen dentro de JPanel

Estoy intentando meter una imagen dentro de un JPanel, para después solo tener que mover el JPanel sin tener que mover la imagen tambien.

Tengo este código, pero no se qué es lo que estoy haciendo mal:

Código:
import java.awt.Color;
import java.awt.Container;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


public class mainClass extends JFrame {
	
	private static final long serialVersionUID = 1L;
	
	Container cont = new Container();
	JPanel fondo = new JPanel();
	ImageIcon Imagen = new ImageIcon("imagen.png");
	JLabel Img = new JLabel();
	
	public mainClass(){
		
		this.setBounds(100,100,640,480);
		this.setVisible(true);
		this.add(cont);
		cont.add(fondo);

		Img.setVisible(true);
		Img.setLocation(200,200);
		Img.setSize(100,100);
		Img.setIcon(Imagen);
		Img.setOpaque(true);
		
		fondo.setBounds(0,0,500,300);
		fondo.setVisible(true);
		fondo.setLocation(100,100);
		fondo.setBackground(Color.blue);
		fondo.add(Img);
		
	}
	
	public static void main(String[] args){
		mainClass window = new mainClass();
		window.setTitle("Mi título");
	}

}