Results 1 to 9 of 9
  1. #1
    jcdubs is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Talking Command line in Swing

    Hi all, i am new to java forums and java, i am building a program for my final year project. It is going to be a GUI for a command line program. I am having problems trying to find out if i can display the command line in swing. is it possible to display the CLI in a jpanel or jtextarea?

    Also, i am going to open the external program (cmd) in the swing app using runtime exec, is there a way to do this with out the user seeing the cmd interface?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by jcdubs View Post
    Hi all, i am new to java forums and java, i am building a program for my final year project. It is going to be a GUI for a command line program. I am having problems trying to find out if i can display the command line in swing. is it possible to display the CLI in a jpanel or jtextarea?

    Also, i am going to open the external program (cmd) in the swing app using runtime exec, is there a way to do this with out the user seeing the cmd interface?
    Hello and welcome to the forum!

    Perhaps it would be best for you to describe what you're trying to achieve from a user's perspective rather from a code perspective as there may be other, perhaps even better, avenues of attack for solving your current problem.

    Much luck and again, welcome!

  3. #3
    jcdubs is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Question

    My project is to create a gui as a front end for the nmap program, used by network administrators to scan networks. Currently the gui's for nmap are creted using C and are OS dependant. I want to create 1 using java so that it will work on multiple OS's.

    The GUI will use the command line output (in the form of an xml document) and display a graphical map of the network. This i know how to do but i would also like the user to initiate the scan in the GUI. They would be able to either run the scan through the GUI with the command line being invisible to them, or i could provide a command line interface in a swing panel so that they could see the program working.

    Hopes this helps.:)

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Based on what you're saying, I'm not convinced that there would be any benefit trying to show the user a command-line like interface, but rather my own non-professional opinion would be to suggest that if you want a command line program then skip using Swing, but if you want a GUI application then don't try to show the command line which is a much more limited interface than a GUI interface. You're much better off using the GUI for what's it does best.

  5. #5
    jcdubs is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default

    I see what you meen, thanks. I am able to open the cmd.exe to run nmap but i am not sure whether or not the user will see the command line. ideally the command line will be invisible. is there a way to do this?

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by jcdubs View Post
    I see what you meen, thanks. I am able to open the cmd.exe to run nmap but i am not sure whether or not the user will see the command line. ideally the command line will be invisible. is there a way to do this?
    If you need to have your Java app run another program, one possible way is to create a Process via Runtime#exec(...). You can usually get the process's standard input and output streams via the getInputStream() and getOutputStream() methods which can help you communicate with the process. And if you're doing this in a Swing application, you'll probably want to do your processing in a background thread such as a SwingWorker thread.

    Oh, one other thing, when using Runtime, it's a good idea to know about potential traps which are pretty well described in this article: Java World: When Runtime.exec() won't

    Clear as mud? Best of luck!
    :)

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    Quote Originally Posted by Fubarable View Post
    Oh, one other thing, when using Runtime, it's a good idea to know about potential traps which are pretty well described in this article: Java World: When Runtime.exec() won't
    As advised in the cross post.
    OTN Discussion Forums : Command line in Swing ...

    db

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by Darryl.Burke View Post
    As advised in the cross post.
    OTN Discussion Forums : Command line in Swing ...

    db
    ah crud!

    Original poster, why didn't you notify us of the cross-post? Most of us don't like to waste our time here answering questions that have already been answered elsewhere. If you're paying for advice, then fine, cross-post all you want, but if you're asking volunteers to help you for free, proper etiquette and common sense should tell you to let all know where else you're asking this same question so to prevent us from doing work on a problem that's already been answered elsewhere. Thank you for your cooperation.

  9. #9
    jcdubs is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default

    Sorry didnt realize that that wasnt the norm, it wont happen again. Thanks for your help.

Similar Threads

  1. can i run line by line command in netbean?
    By choconlongxu in forum NetBeans
    Replies: 1
    Last Post: 07-19-2010, 08:41 PM
  2. Replies: 2
    Last Post: 07-02-2010, 02:20 PM
  3. Command Line Arguments
    By Nakira in forum NetBeans
    Replies: 10
    Last Post: 02-04-2010, 03:45 PM
  4. Searching command line
    By McChill in forum New To Java
    Replies: 5
    Last Post: 02-25-2009, 06:00 PM
  5. Unable to execute command line command in java
    By LordSM in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 12:23 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •