Clase PanelJuego (extiende JPanel)

Extendemos la ventana agregando un panel personalizado para el juego (PanelJuego), donde definiremos las dimensiones basadas en tiles.

<aside> 💡

Recuerda importar: import javax.swing.JPanel;

</aside>

public class PanelJuego extends JPanel{
	
	final int OriginalTile = 16; //juego 16x16
	final int scale = 3;
	
	final int tamanioTile = OriginalTile*scale; //48 *48
	//relacion 4*3 clasica 
	final int maxPantallaColumnas = 16;
	final int maxPantallaFilas = 12;
	//tamaño de la panatalla 
	final int anchoPantalla = tamanioTile*maxPantallaColumnas; //768 px
	final int altoPantalla = tamanioTile*maxPantallaFilas; //576 px
	
	public PanelJuego() {
		this.setPreferredSize(new Dimension(anchoPantalla,altoPantalla));
		this.setBackground(Color.BLACK);
		this.setDoubleBuffered(true);
		
	}
	
}

image.png

Explicación paso a paso

Aquí está tu sección añadida, sin cambiar tu estilo ni el formato Markdown que ya usas:


Implementación en el main

package main;

import javax.swing.JFrame;

public class Main {

	public static void main(String[] args) {

		JFrame ventana = new JFrame();
		ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        ventana.setResizable(false);

		//************************************
		PanelJuego paneljuego = new PanelJuego();
		ventana.add(paneljuego);

		ventana.pack(); // empaquetamos para verlo
		//************************************

		ventana.setTitle("Primer Juego 2D");
		ventana.setLocationRelativeTo(null);
		ventana.setVisible(true);
	}

}


image.png