aspose file tools*
The moose likes Java in General and the fly likes Running a program in Jframe Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Running a program in Jframe" Watch "Running a program in Jframe" New topic
Author

Running a program in Jframe

Kevin Corre
Greenhorn

Joined: Oct 26, 2011
Posts: 18
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

Joined: Sep 20, 2010
Posts: 3647
    
  17

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

Joined: Oct 26, 2011
Posts: 18
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

Joined: Sep 20, 2010
Posts: 3647
    
  17

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

Joined: Jan 28, 2003
Posts: 4181
    
  21

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".


Steve
Kevin Corre
Greenhorn

Joined: Oct 26, 2011
Posts: 18
Cool thanks guys, I will start looking through the info and post if I have any other questions.

Thanks,
Kevin
Kevin Corre
Greenhorn

Joined: Oct 26, 2011
Posts: 18
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

Joined: Jan 28, 2003
Posts: 4181
    
  21

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running a program in Jframe