Ask your own question, for FREE!
Computer Science 20 Online
OpenStudy (anonymous):

In java, how could you display any output in a text editor like notepad?

OpenStudy (anonymous):

You mean have notepad open and the output of the java program being streamed to the notepad window?

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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?

OpenStudy (anonymous):

Oh, do the integer inputs come from values written in the text editor?

OpenStudy (anonymous):

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.

OpenStudy (anonymous):

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?

OpenStudy (anonymous):

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?

OpenStudy (anonymous):

between step 3 and 4, does the user save the file?

OpenStudy (anonymous):

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

OpenStudy (anonymous):

Am I making sense?

OpenStudy (anonymous):

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

OpenStudy (anonymous):

for number 2. i meant 2. the user finishes typing a few integers and saves the file, and then the program responds

OpenStudy (anonymous):

the first one

OpenStudy (anonymous):

As far as I know, this is very difficult to do with notepad

OpenStudy (anonymous):

But is it possible?

OpenStudy (anonymous):

My Prof gave me this as a challenge

OpenStudy (anonymous):

I can think of a few hacky ways, for example... if you had the java program capture keystrokes while the notepad window was focused

OpenStudy (anonymous):

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

OpenStudy (anonymous):

how?

OpenStudy (anonymous):

are you on windows?

OpenStudy (anonymous):

yes

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

May you write a sample code?

OpenStudy (anonymous):

this is not something that will fit in this response

OpenStudy (anonymous):

might be a few hundred lines

OpenStudy (anonymous):

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

OpenStudy (anonymous):

why?

OpenStudy (anonymous):

I don't know how to do any of it. I need help

OpenStudy (anonymous):

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

OpenStudy (anonymous):

In any case, I don't really have knowledge of windows APIs so i can' help with specifics :/

OpenStudy (anonymous):

can't*

OpenStudy (anonymous):

just curious, what kind of course is this for? It might give some hints on how your prof wants you to approach the problem

OpenStudy (anonymous):

The course is Information Technology, Object oriented programming, it also has to do with looping

OpenStudy (anonymous):

is this an introductory course?

OpenStudy (anonymous):

yes, I can say that

OpenStudy (anonymous):

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?

OpenStudy (anonymous):

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)

OpenStudy (anonymous):

on what cue should the program tell the user if its odd or even?

OpenStudy (anonymous):

no, the program will tell if the value entered by the user is odd or even

OpenStudy (anonymous):

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?

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!