-2

My class Window is the following

package com.tutorial.main;

import java.awt.Canvas;

public class Window extends Canavas {

    public Window(int width, int height, String title, Game game){

        JFrame frame = new JFrame(title);

        frame.setPrefferedSize(new Dimension(width, height));
        frame.setMaximumSize(new Dimension(width, height));
        frame.setMinimumSize(new Dimension(width, height));

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(false);
        frame.setLocationRelativeTo(null);
        frame.add(game);
        frame.setVisible(true);
        game.start();
    }
}

I've imported the abstract window toolkit's Canvass class, so I can't understand why I receive the following errors:

cannot find symbol Canvas

cannot find symbol JFrame

Note that I am not using an IDE, I am using a text editor.

Community
  • 1
  • 1
the_prole
  • 8,275
  • 16
  • 78
  • 163

1 Answers1

0

Your problem is related to class importing.
You need to import all the classes that you use. There are just two exceptions to this:

  • classes in the java.lang package
  • classes in the same package as the current class

In your snippet the following classes are not imported:

  • Game and Dimension (presumably these are in the same com.tutorial.main package)
  • Canvas and JFrame. You misspelled Canvas as Canavas (this is where an IDE, or just a spellchecker, comes in), and did not import JFrame.

So the solution for your problem is:
Fix typo: extends Canvas
Add: import javax.swing.JFrame;

RobCo
  • 6,240
  • 2
  • 19
  • 26