I have put an image on my button and with setBounds I have positioned it on the screen but for some reason sometimes it goes well and sometimes the button occupies the whole screen Images link link
Why does this happen?
public class Ventana extends JFrame {
public Ventana(){
super("El laberinto");//Establece el nombre de la ventana
setSize(700, 700);//Establece el tamaño
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//Establece una operacion por deafaul al cerrar
setLocationRelativeTo(null);//Hace que la pantalla no pueda manipularse de tamaño
setVisible(true);
setResizable(false);
Fondo f = new Fondo();
add(f);
setContentPane(f);
setLayout(null);
Botones b = new Botones();
setContentPane(b.b1v1);
/* b.b1v1.setBounds(300,600,50,50);
setContentPane(b.b1v1);*/
}
public class Juego extends JFrame{
public static void main(String[] args) throws MalformedURLException {
Ventana v = new Ventana();
}
}
public class Botones extends JFrame implements ActionListener{
ImageIcon ib1v1;
JButton b1v1;
public Botones(){
ib1v1 = new ImageIcon(getClass().getResource("/Imagenes/siguiente.png"));
b1v1 = new JButton(ib1v1);
b1v1.setIcon(ib1v1);
b1v1.setLayout(null);
b1v1.addActionListener(this);
add(b1v1);
b1v1.setLayout(null);
b1v1.setBounds(300,600,50,50);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource()==b1v1) {
try{
Ventana v;
Ventana2 v2 = new Ventana2();
v2.setVisible(true);
v2.setSize(700,700); //Le damos tamaño al frame
v2.setLocationRelativeTo(null);
} catch(Exception excep) {
System.exit(0);
}
}
}
}