Forums Register Login

Running a program in Jframe

+Pie Number of slices to send: Send
I have a Jframe with a menu bar, when one of the items is clicked the programs are run in a console. Is there a way to have it run in the Jframe instead of the console. Here is the code I have.



Thanks in advance,
Kevin
1
+Pie Number of slices to send: Send
Well, what do you mean by "run in a JFrame"? Do you want to show the output of the execution in a text area or something? You need to capture the output and display it in the text area yourself.

Also, take a look at this article: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
+Pie Number of slices to send: Send
Yes I wanted to be able to to have the output in the Jframe and be able to do the input also if that is possible. Not real familiar with the GUI so not sure what is possible. Was just trying not to have the external console pop up and have it run in it.

Thanks,
Kevin
+Pie Number of slices to send: Send
Well, you can get the output and input streams from the Process you're working with. I'm not sure if that'll prevent the console from popping up, but it still means you should be able to manipulate the process through your own GUI. Read through the article I linked to, and experiment a bit with it.
+Pie Number of slices to send: Send
Yeah, the Gobbler described in the above linked article will give the details about how to consume the output. A similar principle can be used to provide input. The popping up of the command window comes from your use of the "start" command. See the microsoft documentation: here. "start" is specifically used to open a new command window. You should try to run the batch file without the start command. If you can't (I am not sure if start is necessary for running batch files) then you should use one of the command options to change window's behavior, such as using "start /b TheBatch.bat" or "start /min TheBatch.bat".

+Pie Number of slices to send: Send
Cool thanks guys, I will start looking through the info and post if I have any other questions.

Thanks,
Kevin
+Pie Number of slices to send: Send
Ok guys so after looking through all that info, I would use the Gobbler to redirect the input and output to a text area in the Jframe right? I have never used it before so just want to make sure I am looking at it right and not missing anything. Also will I be using the BufferedReader with this?

Thanks,
Kevin
1
+Pie Number of slices to send: Send
The Gobbler will be used to consume the Process' output and error streams. You would have to modify it to append the data into your text area. A BufferedReader could definitely be used here. A couple things to point out:
- You should have two separate gobblers, one for the output and one for the error streams.
- The gobblers should each run in their own thread. They should push the text field update into the swing event thread, maybe using SwingUtilities

The input doesn't really need a gobbler or its own thread. You would have an input source on your GUI and an event listener for when the input is made. Then you would pipe the text the user entered into the Process' input stream.
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 7844 times.
Similar Threads
Global Editor project
JMenuItem enable
JDesktopPane creates inner frame menuItem actionPerformed does not.
JMenu – exit application problem!
Menus and replacing the prompts fr JFrame
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:38:32.