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);
}
}

OriginalTile = 16 para simular resoluciones retro.scale = 3 produce tamanioTile = 48 (mantiene píxeles nítidos, sin borrosidad).16 columnas × 12 filas → relación 4:3.768 × 576 píxeles.PanelJuego())
setPreferredSize(...) define el tamaño exacto del panel usando las dimensiones calculadas.setBackground(Color.BLACK) da un fondo negro típico de juegos retro.setDoubleBuffered(true) activa el doble buffer para evitar parpadeos al dibujar en pantalla (mejora la fluidez del renderizado).Aquí está tu sección añadida, sin cambiar tu estilo ni el formato Markdown que ya usas:
mainpackage 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);
}
}
