Hi, help, please, with the code) I would like to implement such a standard output structure of pictures in JFrame (I want to make a small toy)

Here are my two classes: Game.java

package Game; import java.awt.Canvas; import javax.swing.JFrame; public class Game extends Canvas { private static final long serialVersionUID = 1L; public static final int WIDTH = 560; public static final int HEIGHT = 520; public static final String NAME = "Title Game"; public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(WIDTH, HEIGHT); frame.setTitle(NAME); frame.add(new Map()); frame.setVisible(true); frame.setLocationRelativeTo(null); } } 

Second class: Map.java package Game;

 import java.awt.*; import javax.swing.*; public class Map extends JPanel { private static final long serialVersionUID = 1L; public Image gras; public Map() { gras = Toolkit.getDefaultToolkit().getImage("Image/gr.png"); } public void paint(Graphics g) { g.drawImage(gras, 10, 10, null); } } 

The code does not display a picture (I can fix it, if I use this standard structure of two classes correctly. Maybe someone has that. And when I click on the window itself and click on the arrows it moves) So it should be?) what to write panel or what public class Map extends JPanel {

In general, at least a picture to bring) Thanks in advance.

  • uh ... well, for starters, if you override the method, put an override, + you need to call the parent method ... who knows what secrets it keeps ;-) but in general, here's your question: - JEcho

0