So I'm trying to add the functionality to use 'wasd' to select a tile and number keys to change the tiles color. But I have no idea how to read the input so you don't have to type in the command line and hit Enter for every move. I'm only allowed to use StdIn, StdOut and StdDraw. If anyone could shed any light on this that would be helpful and much appreciated.
Asked
Active
Viewed 35 times
0
-
1In short: Java doesn’t have such a feature. You’d need a 3rd party library or some native extension for that. – Holger May 13 '22 at 13:54
-
1Really?? I thought there was a way to do it cause its in our project specification – Jaya May 13 '22 at 13:58
-
Normally, you would use an `ActionListener` to do that. But, if my understanding is correct, you aren't allowed to use that for this assignment. – Old Dog Programmer May 13 '22 at 14:01
-
1Looks like [StdDraw](https://introcs.cs.princeton.edu/java/stdlib/javadoc/StdDraw.html) has action listeners; look for e.g. `keyTyped`. – Robert May 13 '22 at 14:25
-
2@Robert So this is not what is normally meant with *stdin* and *stdout*? It would, of course, be important to mention in the requirements, if such a non-standard library should be used… – Holger May 13 '22 at 16:44
-
@Holger no idea... this was the first hit I got when I searched for stddraw :-) – Robert May 13 '22 at 17:28
-
I think @Robert has it. @Jaya's professor told the students how to download / install `StdDraw` package. Professor expects the students to use listeners in `StdDraw`. – Old Dog Programmer May 13 '22 at 17:34
-
@Jaya , Please tell us why you are restricted to using only `StdIn`, `StdOut`, and `StdDraw`. – Old Dog Programmer May 14 '22 at 16:22
-
@James It's so that we can learn in depth problem solving and learn how to figure something out without shortcuts like JFrame and ActionListener. It's a Computer Science degree so we are learning the foundations of Java – Jaya May 15 '22 at 12:21
-
1@Jaya, I think the decision to close the question was a mistake. The answer referenced in the reason for closing is one you can't use. However, it seems to be moot: Judging from your subsequent question, you did find out how to use `StdDraw` to detect key presses. Perhaps you could delete this question. – Old Dog Programmer May 15 '22 at 22:34