• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running a program in Jframe

 
Kevin Corre
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Stephan van Hulst
Bartender
Pie
Posts: 5888
63
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Kevin Corre
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Stephan van Hulst
Bartender
Pie
Posts: 5888
63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".

 
Kevin Corre
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool thanks guys, I will start looking through the info and post if I have any other questions.

Thanks,
Kevin
 
Kevin Corre
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic