Código:
public class MiPanel extends JPanel implements MouseListener,MouseMotionListener{ private ImageIcon fondo; private JLabel barras[]; //private Container container; int x,y; public MiPanel() { //Container container = getContentPane(); setLayout(null); barras = new JLabel[12]; int i; for(i = 0;i<6;i++) barras[i] = new JLabel(new ImageIcon("BarraUP")); for(;i<12;i++) barras[i] = new JLabel(new ImageIcon("BarraDOWN")); barras[6].setBounds(343,452,38,5); barras[7].setBounds(403,452,38,5); barras[8].setBounds(343,279,38,5); barras[9].setBounds(780,345,38,5); barras[10].setBounds(355,94,38,5); barras[11].setBounds(417,95,38,5); add(barras[6]); add(barras[7]); add(barras[8]); add(barras[9]); add(barras[10]); add(barras[11]); addMouseListener(this); addMouseMotionListener(this); fondo = new ImageIcon("Estacionamiento.PNG"); setSize(821,642); //[821,642] } public void paintPaint(Graphics g){ System.out.println("["+this.getWidth()+","+this.getHeight()+"]"); fondo.paintIcon(this,g,0,0); super.paint(g); setOpaque(false); //g.drawImage(fondo.getImage(),0,0,this.getWidth(),this.getHeight(),this); g.setColor(Color.RED); g.drawString("("+x+","+y+")",x+20,y); g.drawRect(x,y,38,5); } public void mouseExited(MouseEvent me) { } public void mouseMoved(MouseEvent me) { x = me.getX()-10; y = me.getY()-10; repaint(); } public void mouseDragged(MouseEvent me) { } public void mouseEntered(MouseEvent me) { } public void mouseReleased(MouseEvent me) { } public void mousePressed(MouseEvent me) { } public void mouseClicked(MouseEvent me) { } }