In java, how could you display any output in a text editor like notepad?
You mean have notepad open and the output of the java program being streamed to the notepad window?
To write anything to a text file, PrintWriter writer = new PrintWriter("somefile.txt"); writer.println("blah blah blah"); writer.close(); then open the file in the text editor. If you want the text editor to constantly update as the java program writes, it will depend on which text editor you are using. I don't think its possible with notepad
I should accept integer values from the user and display something that uses those values. But instead of doing it in the terminal window, I should do it in a text editor. Any suggestions?
Oh, do the integer inputs come from values written in the text editor?
Ahm, the user, instead of inputting values in the terminal window, he will input it in the text editor that should automatically run when he runs the program.
Ok, so 1. user opens text editor, save a file with numbers in it 2. user runs program 3. program outputs to terminal is this what you want?
Here: 1.user runs the program 2.text editor will automatically run 3.there would be a statement in the text editor asking the user to enter values 4.displays output in the terminal window something like that is it possible?
between step 3 and 4, does the user save the file?
ahm, if he enters the output will be displayed. Is it possible that the output would also be display in the text editor? The operation is the same as in the terminal window, the only difference is that instead in the terminal window, it would happen in the text editor
Am I making sense?
I need more information on how the user input to the text editor is given to the program, is it like 1. as soon as the user finishes typing an integer, the program responds or 2. the user finishes typing a few integers, and then the program responds
for number 2. i meant 2. the user finishes typing a few integers and saves the file, and then the program responds
the first one
As far as I know, this is very difficult to do with notepad
But is it possible?
My Prof gave me this as a challenge
I can think of a few hacky ways, for example... if you had the java program capture keystrokes while the notepad window was focused
maybe its possible to setup notepad in a way such that it saves repeatedly, every half second for example and then to read the file it saves to and respond to changes
how?
are you on windows?
yes
Ultimately, you need notepad and your java program to communicate in some way, you probably have to use Java Native Interface to do this and the Windows APIs
One way of communicating without the Windows APIs is to save and poll the file you are saving to, which might be possible in editors other than notepad
May you write a sample code?
this is not something that will fit in this response
might be a few hundred lines
Another way might be to create your own notepad clone from scratch in java, then you can capture the strokes to that without using JNI
why?
I don't know how to do any of it. I need help
I'll take the keystroke capturing as an example, the psuedocode might be something like this: start a notepad instance set up a state machine to parse when integers are completed setup a callback to keystrokes in windows using JNI give keystrokes to state machine on integer completion: do something with the integer
In any case, I don't really have knowledge of windows APIs so i can' help with specifics :/
can't*
just curious, what kind of course is this for? It might give some hints on how your prof wants you to approach the problem
The course is Information Technology, Object oriented programming, it also has to do with looping
is this an introductory course?
yes, I can say that
ok, it think its unlikely for the assignment to actually require the notepad input to be captured in real time. Can you summarize the requirements again, as specific as possible?
Okay, A text editor will appear as the user runs the program: 1.Ask the user to enter an integer 2.Display if it is odd or even the operation should happen in the text editor, not in the terminal window(Scanner) or in a dialog box(JOptionPane)
on what cue should the program tell the user if its odd or even?
no, the program will tell if the value entered by the user is odd or even
but for example, if I wanted to type 513342, would the program tell me odd, odd, odd, odd, even, even. Each time I pressed a key?
Join our real-time social learning platform and learn together with your friends!