Comments (5)
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.
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.
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.
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.
I'm not completely sure, I think it is a focus issue.
from snake_game.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from snake_game.