我一直试图覆盖并使用paint组件方法而不是paint方法,因为我已经看到它在这里的多个问题中被提出.
我已经看了很多问题,但我似乎仍然无法让这个工作.我发布了用于渲染屏幕的原始代码.我认为扩展JFrame不是正确的方法,而是我需要扩展JPanel,并从那里使用paint组件.我有另一个对象,我实际上扩展了JPanel,并添加了JFrame(用于渲染).
这是我用来渲染的对象,通过这种方式可以完美地覆盖paint方法.
package render;
import java.util.Arrays;
import javax.swing.*;
import java.awt.*; //Graphics, Graphics2D, Image
import sprites.Picture;
public class Window extends JFrame{
private static final long serialVersionUID = 1L;
public static Picture[] image_list = new Picture[0]; // All the images I want to render
private static String win_title = "Window"; // The name of the window
private static CustomComponents cc = new CustomComponents();
public Window(){
setTitle(win_title); // set my title
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // close when you hit x button
setUndecorated(true); // window …Run Code Online (Sandbox Code Playgroud)