?
Solved

command from DOS read and accepted by GUI

Posted on 2004-11-20
13
Medium Priority
?
340 Views
Last Modified: 2010-04-17
  Can I have a Java GUI application that receives DOS commands to initiate an action as it does with ActionEvent, ActionListener, etc.  For an example let’s say my application has been started from within a .bat file by an external application, and a GUI is launched that displays some information.  Then let’s say the external application sends a string of text to get my GUI application to initiate some other action.  1)  Is this possible? 2) What would be the best approach to capture this text from the external application?

Thanks in advance.

   
0
Comment
Question by:jhughes4
  • 7
  • 6
13 Comments
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12637440
I think that you can only retrieve outputted text from a batch file, if you CALL the batch file from inside your application (rather than the batch file calling your application).

I can give you some code for that if you'd still like.

gL,  :-)
[r.D]
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12637464
hmm.. hold on.. I just re-read your Q.
Do you want to capture the text from the external app? If so, how do you plan to communicate with it? Have you programmed this other app yourself? If so, you can use a Socket connection, or agree on a File to transfer data via.

What is this other application, and what language has it been programmed in? Also, how do you start this external application? Is it just an .EXE ? Or a Java CLASS (/.JAR) file?

gL,
[r.D]
0
 

Author Comment

by:jhughes4
ID: 12638773
I have no control over the external application, it's an exe.  However, the external application can be configured with "hot keys".  For example, I can configure a button to be assigned to notepad to execute the following commands:
<ENTER>
"this is a test"
<ENTER>

so that in the notepad window the following shows up

this is a test

Does this help?

If I can't update the GUI app directly from the external application, could I create a separate application that reads args[] interactively and interacts with the GUI app without having to restart the GUI app for each command?

Thanks for the response.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 9

Expert Comment

by:DrWarezz
ID: 12639009
So, the 'commands' are outputted to a text file? If so, that's not too hard to solve..

Let me know.

[r.D]
0
 

Author Comment

by:jhughes4
ID: 12639310
No sorry, the commands aren't sent to a text file.  I was only using notepad as an example.  The commands are issued directly to the application you indicate within this external application.  My preference would be to not use a file since there are two separate processes reading and writing to that file.  What I think I would like to do is to have a class file that continuously reads arguments, and based on the arguments executes or displays information in a GUI without having the GUI restart.

For example:
1)      App is started….   java StartRead  (waits on arguments sent into DOS).
2)      External app is started and enters an “s” in the DOS window.
3)      StartRead.java reads “s” and puts in a window “STARTED”.
4)      External app is started and enters an “h” in the DOS window.
5)      StartRead.java reads “h” and replaces “STARTED” with “HELP”.

If this is possible how would I continuously loop through the arguments and how would I update the window/GUI?

Thanks again.



0
 

Author Comment

by:jhughes4
ID: 12639552
I've been able to find out how I can continuously read the arguments see the attached code.  However, I'm still unsure as to how I can take that argument (input String) and pass it to some sort of GUI.  Thanks in advance for the help.

      try {

java.io.BufferedReader stdin = new java.io.BufferedReader( new java.io.InputStreamReader( System.in ) );

while (true)
{
      String input = stdin.readLine();

      System.out.println("HERE'S THE INPUT MESSAGE:" + input);
}
} //end of try
catch (Exception e) {
      System.out.println("THE FOLLOWING EXCEPTION OCCURRED:" + e.toString());
}
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12639590
Ah k, I think I'm with you now..

So, you've assigned the outputted string (from the external app) to the variable: "input".
You then need to create a GUI, and display it, right?

I'll start coding something for you now.. If I'm mistaken though, let me know :-)  (Sorry for not getting it the first time).

gL,
[r.D]
0
 
LVL 9

Accepted Solution

by:
DrWarezz earned 1000 total points
ID: 12639658
Here, I haven't tried it, but give it a go, and let me know if it's what you're after:

//-----8<---------------------------------- CommandGui.java -------------------------------------------------
import java.io.*;
import javax.swing.*;
import java.awt.*;

public class CommandGui extends JFrame {
   
    public CommandGui () {
       
        super( "GUI Title" );
        setBounds( 100, 100, 200, 90 );
        setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
       
        JLabel jl_status = new JLabel ( "" );
       
        JPanel pane = new JPanel();
        pane.add ( jl_status );
       
        setContentPane( pane );
       
        BufferedReader stdin = new BufferedReader( new InputStreamReader( System.in ) );
       
        for ( ;; ) {   // Infinite loop..
           
            try {
                String input = stdin.readLine();
               
                // Assign string to Label (in the GUI):
                jl_status.setText( input );
            } catch (Exception e) {
                e.printStackTrace();
            }
           
        }
       
    }
   
    public static void main ( String [] args ) {
        new CommandGui();
    }
   
}
//-----8<---------------------------------- CommandGui.java -------------------------------------------------

gL,
[r.D]
0
 

Author Comment

by:jhughes4
ID: 12639838
Thanks!
0
 

Author Comment

by:jhughes4
ID: 12639919
I've been playing around with your sample and even though I've accepted your answer you can still answer a question for me.  When you run the app, the JPanel is brought up as the active window, so as a result the commands being issued won't work.  Is there a way to bring up JPanel at a certain location in the window, but in an inactive state?

thanks again

0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12644320
you can change the x,y location co-ordinates, like so:

setBounds ( x, y, width, height );

You can also turn it into a JWindow, like so:

Remove this line: setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
And change this line:

public class CommandGui extends JFrame {

to:

public class CommandGui extends JWindow {

Let me know if that helps,
[r.D]
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12644337
And to make the window inactive, I think that this should do the trick:

After the line: "setContentPane( pane );", add this:
toBack();

I think that's the method.. let me know.
[r.D]
0
 

Author Comment

by:jhughes4
ID: 12644350
Thanks
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Screencast - Getting to Know the Pipeline

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question