简体   繁体   中英

Why do I keep getting an "<identifier> expected" error in my Window method?

I tried compiling my game after I debugged it, now it will not work throwing:

Window.java:15: error: <identifier> expected
public Window(Wwidth, Wheight, Game game) {
                    ^

and

Window.java:15: error: <identifier> expected
public Window(Wwidth, Wheight, Game game) {
                             ^

at me

I tried using static/non-static variables, I looked up the matter to find something here and none of them matched this.

Window

method from the window class:

public Window(Wwidth, Wheight, Game game) {
        JFrame Window = new Jframe();
        setPreferredSize(new Dimension(Wwidth, Wheight));
        setMinimumSize(new Dimension(800, 600));
        Window.add(game);
        Window.pack();
        Window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Window.setTitle("HypoPixel");
        Window.setLocationRelativeTo(null);
        Window.setVisible(true);
        game.start();
    }
}

and

Window

method being called from Game.java:

import java.awt.*;

import javax.swing.*;

import java.applet.*;

public class Game extends Canvas implements Runnable {

    public static final long serialVersionUID = 1L;

    public Game() {
        new Window(800, 600, this);
    }

    public synchronized void start() {
    }

    public void run() {
    }

    public static void main(String[] args) {
        new Game();
    }
}

I expected it to compile yet failed. How can I fix this? (I will include you guys in the credits!)

Wwidth and Wheight are types. You must insert a variable after each type, like in the Game game part.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM