Git Product home page Git Product logo

Comments (5)

nkarasch avatar nkarasch commented on June 11, 2024

If you are referring to your JApplet version in the 'master' branch you are missing the call to setFocusable(true) for the JApplet. Add that to your init function and that problem will be solved.

I do have to warn you though, the way you are initializing and starting some pieces of the program is going to cause problems if you hope for the "start", "stop", and "restart" buttons in the menu to ever work properly. Here is a quick overview. JApplet's are almost extinct but the concept is worth understanding.

Good luck!

from snake_game.

ashish2199 avatar ashish2199 commented on June 11, 2024

Thanks for your suggestion. I will look into it and improve my code for the JApplet version.

But i was referring to JFrame version of the application in which I am facing this problem.
It would be nice if you could help me with the JFrame version of the application.

I am now working on JFrame as I heard Applets are a thing of past and that they require signing and other security certificates.

from snake_game.

nkarasch avatar nkarasch commented on June 11, 2024

Remove this from the prepareGame method

        drawpanel.setFocusable(true);
        keyboardinputlistener k = new keyboardinputlistener();
        screen.addKeyListener(k);
        drawpanel.addKeyListener(k);

Add this to init

        frame.addKeyListener(new keyboardinputlistener());
        frame.setFocusable(true);
        frame.requestFocus();

from snake_game.

ashish2199 avatar ashish2199 commented on June 11, 2024

Thanks a lot
You solved my problem 👍

Can you explain me whats the difference in applying KeyboardInputListener to JPanel than to applying to Frame ?

from snake_game.

nkarasch avatar nkarasch commented on June 11, 2024

I'm not completely sure, I think it is a focus issue.

from snake_game.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.