user3176943
user3176943

Reputation: 35

Java Frame - Game

Getting an error at frame.add(game);: Multiple markers at this line - Debug Current Instruction Pointer - The method add(Component) in the type Container is not applicable for the arguments (Display)

My code:

import java.awt.Canvas;
import java.awt.Component;
import javax.swing.JFrame;

public class Display {

    public static final int WIDTH = 800;
    public static final int HEIGHT = 600;

    public static void main(String[] args){

        Display game = new Display();
        JFrame frame = new JFrame();
        frame.add(game);
        frame.setSize(WIDTH, HEIGHT);
        frame.setResizable(false);
        frame.setVisible(true); 
    }
}

Upvotes: 1

Views: 156

Answers (2)

donkon
donkon

Reputation: 919

Your Display should extend JPanel or some other Component as mentioned by the other answer.

For your purpose you should also override the paintComponent(Graphics g) method when you are ready to draw something on the Displayand have a constructor if your going to use it as a Component.

Upvotes: 1

Christian Tapia
Christian Tapia

Reputation: 34146

Your class Display should extend a Component (Container, Button, Canvas, Label ...). I think you would like to extend JPanel which is the most common, but it really depends on what Display class is intended to do:

public class Display extends JPanel {
}

Upvotes: 4

Related Questions