From JPanel to DOS

Hello all,
I have a program that runs from DOS by typing "java myProgram" which calls a JFrame class "myClass" that implements some button actions.
Is it possible to create a new JButton("Return to DOS") with an action that closes the current frame window and returns to the DOS prompt from where we ran the "java myProgram" command?
Thanks as usual for your help!

OK maybe with some code the picture is more clear...
So let's say I have 2 classes, 'DrawRectangle' and 'menu' as follows:
import java.awt.geom.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DrawRectangle extends JPanel implements ActionListener
   Rectangle2D.Float rectangle2D;
   protected JButton menu;
   public DrawRectangle()
       //PS: I know that the following should not be in the constructor.
       //This is just a sample example.
       rectangle2D = new Rectangle2D.Float(50F,50F,200,200);
       menu = new JButton("Return to DOS menu");
       add(menu);
       menu.addActionListener(this);
   public void actionPerformed(ActionEvent e)
      if (e.getSource() == menu)
         System.exit(0);           
   public void paint(Graphics g)
       Graphics2D g2 = (Graphics2D)g;
       g2.setPaint(Color.blue);
       g2.draw(rectangle2D);      
    public static void main ()
       JFrame rectangle = new JFrame("My Project");
       rectangle.setSize(400, 400);     
       Container container = rectangle.getContentPane();              
       container.add(new DrawRectangle());      
       rectangle.setVisible(true);      
import java.io.*;
class menu
    menu()
       int choice = -1;
       while (choice != 0)
          System.out.println("Please choose an option from 1 to 4, 0 to exit\n");
          BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
          try
             choice = Integer.parseInt(in.readLine());
             switch(choice)
                case 1: choice1(); break;
                case 2: choice2(); break;
                case 3: choice3(); break;
                case 4: choice4(); break;
          catch (Exception ex)
       System.out.println("Exit");       
   private void choice1()
       new DrawRectangle().main();
   private void choice2()
       System.out.println("Choice 2");
   private void choice3()
       System.out.println("Choice 3");      
   private void choice4()
       System.out.println("Choice 4");      
   public static void main(String [] args)
       new menu();
}Now just to explain, I open a DOS prompt, type 'java menu' and you have four options: 1,2,3,4 and 0 to exit. If you type 2, the system returns "Choice 2" and you can choose another option (which is what I want). If you type 1, the system calls the main method of class 'DrawRectangle' and a JFrame with a painted rectangle opens up. When I click the "Return to DOS menu" button, the JFrame closes and the DOS window is active again. However, the DOS goes on C:\ prompt and not on "Please choose an option from 1 to 4, 0 to exit" as I want. And you have to type again 'java menu' to run the program. Instead, any other option like 2,3 or 4 will give you the chance to choose another option.
I know that all this sound strange to you, but unfortunately the requirements given to me is to run the program from a DOS prompt and to be able to choose another option without the need of typing again 'java menu'.
Thanks for your help and attention.

Similar Messages

  • Error reading data from the MS Dos Console.

    Hi,
    We have a legacy application which is launched via a 3rd-party Telnet Server - the app acts as a remote shell for an RF device. The system has been functioning for many years but now we have migrated to Server 2012 the system no longer launches.
    The RF device successfully connects to the telnet server, logs-in with embedded credentails but drops the connection when the shell application is launched.
    The server has the following Application error
    Error reading data from the MS Dos Console.
    The pipe has been ended. 109 (0x6d)
    The application can successfully be launched locally outside of the shell on the server. The error is reproducable across RF devices and desktop telnet connections.
    The firewalls are off.
    Are there some additional protections in Server 2012 which would cause the pipe-based link to be stopped when launching the exe? Am I missing something? The 3rd-party telnet server is certified for Server 2012.
    Thnak you

    I'd ask in the
    Windows Server General Forum, or ask the third party vendor.
    Karl
    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer
    My Blog: http://unlockpowershell.wordpress.com
    My Book:
    Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})

  • How To Boot Windows 7 from Windows 7 DOS Prompt?

    I got hit by the GVU virus.  Spent a week poking around and made some interesting discoveries!
    The GVU virus appears to lock you out of your computer always going to a page in german demanding 100 euros to restore it.
    If you reboot while pressing F8 you can get to the debug page which lists several options including boot to DOS prompt.
    Select this option.
    Windows 7 will boot and ask you to login.  Do this.
    Your computer will now go to the DOS prompt.
    On a second computer I installed an up to date copy of Spybot.  Using explorer I found the Spybot directory tree under Program files and copied it to a jump drive.
    Remove the jump drive from the second computer and insert it in your sick computer.
    On the sick computer you are at the DOS Prompt. Type explorer and press enter.
    A window will open similar to windows 7 explorer.  Right clicks will not work, but you will find all the usual right click menu items under Files and Edit on the menu bar.
    Click View then Refresh to display your jump drive.  You may have to do this a couple of times, but your jump drive will appear in the usual spot.
    Select the spybot directory on your jump drive and launch spybot.  Run a systems scan and delete every thing it finds.  Do this step Several times.
    Reboot your computer.
    Select Boot windows as normal.
    It will ask you to login in. Do so.
    Your computer will boot to explorer, the version that you saw in step 9.
    Press CTL + ALT + Delete then select Task Manager
    Task Manager will launch.  If you click the process tab you will see only ten or so processes are running.
    Click on the applications tab, then in the bottom right corner click on the button New Task.
    Type win and press enter.
    You will notice that the number of processes will jump to 90 give or take.  When CPU use drops to 5% again or there abouts click new task again.
    You are now in windows 7 minus the task bar but with networking etc.
    Enter a windows program such as Outlook and press enter.  Outlook will boot and run perfectly.  I suspect that most windows programs will also run perfectly.
    I know if you boot from your windows 7 DVD you can repair your system to normal.  My question is can I do this without the disk?  At this point I can do all my usual tasks, just without the convenience of the task bar and start button.  I
    am in the middle of unpacking from a move, cannn't find my Windows 7 install disk.  I am so close to getting this computer back to running normally but I am not sure what to do next.  Can someone help?
    Bob Jones

    Hi,
    If you system files are corrupted, we can use SFC to fix missing and corrupted system file:
    http://support.microsoft.com/kb/929833/en-us
    this could be performed in command prompt mode.
    If you have any feedback on our support, please click
    here
    Alex Zhao
    TechNet Community Support

  • Remove images from JPanel

    Hi,
    I have a JPanel called imagePanel and a JTree and every time a node is selected in the tree, a set of images are gonna be displayed on the imagePanel
    with the loop below. But the next time a node is selected the images that were added via the loop the first time, has to be removed. What code can I use to
    empty the imagePanel everytime, before the for-loop runs?
    //Some code here to empty the imagePanel so it begins from  scratch
      for(int index=0; index < imageNames.size(); index++)
    ImageIcon newImage = createImageIcon("images/" +
       (String)imageNames.elementAt(index));
    imagePanel.add(new JLabel(newImage));
    pictureLabel.setText(null);
    }

    Hi ,
    try this
    jlabel.setIcon( null ) ;

  • Can't getGraphics from JPanel

    Hi,
    I want to get the graphics context from a JPanel so I can draw on it. In the example below, theStage ends up null, causing a null pointer exception - where am I going wrong??
    class win extends JFrame{
          Container c;
          win(){
                stage stage = new stage();
                c = getContentPane();
                c.add(stage);
                setSize(400,400);
                setResizable(false);
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                setVisible(true);
          class stage extends JPanel {
                      stage(){
                         Graphics2D theStage = (Graphics2D)getGraphics();
                         theStage.drawLine(0,0,100,100);
    }big thanks for any help,
    Des

    Swing questions should go in the Swing forum.
    And the "drawLine" call should go in the paintComponent method. You need to override the JPanel's paintComponent method to do your drawing.
    The Graphics is null because the JPanel isn't visible yet.

  • HELP: How to get window (JFrame) from JPanel ???

    Hi there,
    anyone knows how I can get a ref. to the window (in the form of JFrame) from my JPanel that is in the actual window??
    I need that window when I display a modal dialog from the panel, as the dialog constructor takes the window as a param.
    I could always pass a window-ref. to the JPanel when I create it, but as I have a lot of panels, I'd rather be able to get it just when I need it from the JPanel!
    Thanks a lot for any help on this issue!
    Best regards,
    AC

    Thanks a lot!
    I'll use windowForComponent in swingUtils, I think getRootPane() would only return the panel that the component is in!
    Regards,
    AC

  • A Bunch of Rookie Questions from an old DOS guy

    Equipment, brand new iMAC 24" with wireless keyboard & mouse, wired LAN.
    I started in the computer world with punch cards and the Microsoft world with DOS 2.0. I now have my first MAC so forgive the dumb questions. I bought a big reference book, I've been through it and the help screens but no luck so far.
    There doesn't seem to be any uninstall for software. Am I correct in assuming that uninstalling is simply a matter of dragging the software folder to the trash?
    How come the Home and End keys don't seem to work in Mail text on my wireless keyboard?
    Why doesn't Searchlight display a "didn't find anything" message?
    Thanks, Peter
    iMAC   Mac OS X (10.4.9)  

    I'll simply add the following regarding software uninstall:
    Uninstalling Software: The Basics
    Most OS X applications are completely self-contained "packages" that can be uninstalled by simply dragging the application to the Trash. Most applications create preference files which are stored in the /Home/Library/Preferences/ folder. Although they do nothing once you delete the associated application, they do take up some disk space. If you want you can located them in the above location and delete them, too.
    Some applications may install an uninstaller program that can be used to remove the application. In some cases the uninstaller may be part of the application's installer, and is invoked by clicking on a Customize button that will appear during the install process.
    Some applications may install components in the /Home/Library/Applications Support/ folder. You can also check there to see if the application has created a folder. You can also delete the folder that's in the Applications Support folder. Again, they don't do anything but take up disk space once the application is trashed.
    Some applications may install a startupitem or a Log In item. Startupitems are usually installed in the /Library/StartupItems/ folder and less often in the /Home/Library/StartupItems/ folder. Log In Items are set in the Accounts preferences. Open System Preferences, click on the Accounts icon, then click on the LogIn Items tab. Locate the item in the list for the application you want to remove and click on the "-" button to delete it from the list.
    If an application installs any other files the best way to track them down is to do a Finder search using the application name or the developer name as the search term.
    There are also several shareware utilities that can uninstall applications:
    AppZapper
    CleanApp
    Yank
    SuperPop
    Uninstaller
    Spring Cleaning
    Look for them at VersionTracker or MacUpdate.
    For more information visit The XLab FAQs and read the FAQ on removing software.

  • Writing jpg from jpanel

    Hi.
    I want to write a jpg-file showing the contents of a JPanel. Is there any way to do this?
    Greetings,
    Feanor's Curse

    Im using your method to save a JPG image from a JPanel too
    It isn't working for me.
    I am running a command line version of my program, but still need to save the JPanel.
    I am just getting a blank image saved.
    Obviously, I think, the problem is that it never gets inserted into a Frame (as I don't have one!) so is never visible. The 'paint(Graphics g)' is obviously too clever and not drawing it, when not in view?

  • Calling JDialog from JPanel

    Hi there, I will try to make this problem simple to understand,
    I have a Jframe which makes use of Jpanels, in a seperate file I have made an extension of a Jpanel which has buttons and when one of these buttons is pressed I want to call up a JDialog from another seperate file. The problem is in the call up where I need the parent frame but I do not have it in the JPanel class i've created (hense this wouldnt work). Any ideas or is there an easier solution to this, I've searched the forum and I cannot find any suitable answers to this (or at least any i can understand)
    Thank you for your time

    Hi!
    One way is to create a new JFrame as parent... it isn't right but it works....
    In constructor call super(new JFrame(), "Dialog Title")Another one could be to send the reference from main frame to the dialog and use as owner frame...
    /Andrew

  • Signal dissappears from JPanel

    Hi
    I have created a new class that extends JPanel and over-writes its paintComponent method to display a signal (using drawPolyLine()). If this panel is given the signal it displays it perfectly. However, in my overall GUI I allow the user to choose a file from disk, using a JFileChooser, and the signal from this (audio) file is then displayed. However, the signal is displayed perfectly except for the area where the JFileChooser was which is blank (the JFileChooser has now shut down). Equally, if I minimise the GUI, which currently displays a signal, and then display the GUI again the signal has completey dissappeared.
    Can anyone help me with this? - I would like the signal to be displayed fully all the time
    Thank you for your help
    David

    Hi
    I have created a new class that extends JPanel and over-writes its paintComponent method to display a signal (using drawPolyLine()). If this panel is given the signal it displays it perfectly. However, in my overall GUI I allow the user to choose a file from disk, using a JFileChooser, and the signal from this (audio) file is then displayed. However, the signal is displayed perfectly except for the area where the JFileChooser was which is blank (the JFileChooser has now shut down). Equally, if I minimise the GUI, which currently displays a signal, and then display the GUI again the signal has completey dissappeared.
    Can anyone help me with this? - I would like the signal to be displayed fully all the time
    Thank you for your help
    David

  • Disposing JFrame from JPanel

    Right, I suspect this has an easy solution, or maybe I have already happened on it, but I thought I'd best ask just in case.
    I have an application that creates a JFrame from another JFrame, with a JPanel internal to it. What I want to happen is for the JPanel to do its business in its paintComponent method, and then dispose of its parent JFrame (that's dispose - no System.exit(0)'s here please :) ).
    The only way I can see to do it is to pass a reference to the JFrame when the JPanel is created. But this seems to be a bit messy encapsulation-wise.
    Any comers?

    you could make the parent JFrame have a thread that checked the status of the child JFrame's JPanel every second or so and then close itself when the JPanel is finished doing whatever it is doing.

  • Remove component from JPanel

    Hi,
    i've to remove a component from the center (BorderLayout.CENTER) of a JPanel without knowing the name of the component at runtime. I know only that the component is in the center position of the panel. How can i do?
    Thanks
    Luca

    normally what i will do i removeall first and then i add the north or south component so you dont have to worry what is in your center of the panel

  • Need to convert lab from UNIX to DOS

    I need to convert this lab from Unix so that it will run as a batch file in Windows (substitute with the appropriate commands). (I will definitely be starting some UNIX classes soon).
    FILE=${1:?'Parameter 1 should be set to file name'}
    BLOCK=${2:?'Parameter 2 should be set to block to be corrupted''}
    BLOCKSIZE=${3:?Parameter 3 should be set to blocksize'}
    dd of=$FILE bs=$BLOCKSIZE conv=notrunc seek=$BLOCK <<EOF
    CORRUPT
    EOF
    dd of=$FILE bs=$BLOCKSIZE conv=notrunc seek='expr 1 + $BLOCK' <<EOF
    CORRUPT
    EOF
    dd of=$FILE bs=$BLOCKSIZE conv=notrunc seek='expr 2 + $BLOCK' <<EOF
    CORRUPT
    EOF
    dd of=$FILE bs=$BLOCKSIZE conv=notrunc seek='expr 3 + $BLOCK' <<EOF
    CORRUPT
    EOF

    Look up the SimpleDateFormat class: http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
    Arwinder wrote:
    This is absolutely necessary... any help plz..For you maybe, not others. Please refrain from trying to urge others to answer your queries. They'll do it at their own pace ( if at all ).
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    (Yes I know it's on JavaRanch but I think it applies everywhere)
    ----------------------------------------------------------------

  • Get back component from JPanel

    by java
    I know JPanel can get back components by JPanel.getComponents() like
    private JPanel panelCenter = new JPanel ();
    panelCenter.getComponents();
    I want to know is JPanel able to get component just by the specified component's name?
    e.g. panelCenter.getComponent("buttom");
    or like vb.net Me.Controls("buttom").Visible = True
    Thanks
    Francis SZE

    None of JPanel, JComponent, Container or Component have a method to get a component by name.
    You can either:
    1. Keep references to the objects you place in your JPanel (highly recommended :)
    or
    2. Iterate over the result of getComponents() and test for getName().equals(requestedName)

  • From JPanel to JLayeredPane

    Hi all, I'm having some trouble with something I though it would be easier...
    I had a JApplet with a main JPanel I added directly to the contentPane, and worked ok, something like...
    JPanel jpan = functionThatCreatesJPanel();
    Container contentPane = getContentPane();
    contentPane.add(jpan);... but now, I need to display some screens over this panel, so I was thinking in using a JLayeredPane, add the old JPanel as background layer, and add new JPanels over it. Is this idea correct?
    JLayeredPane lp = new JLayeredPane();
    lp.setPreferredSize(new Dimension(975,575));
    lp.add(functionThatCreatesJPanel(),new Integer(1));
    lp.setVisible(true);
    Container contentPane = getContentPane();
    contentPane.add(lp);and my applet stays gray! no error messages are shown...
    what do you think?
    thanks!

    Well, this might be a little late to help you, but I was experiencing the same problem. I solved it by adding a component listener on the layered pane that relayed resize events to the contained JPanel, like so:
    layeredPane.addComponentListener(new java.awt.event.ComponentAdapter() {
                public void componentResized(java.awt.event.ComponentEvent evt) {
                     backgroundPanel.setSize(layeredPane.getSize());
            });This appears to correctly paint the panel.

Maybe you are looking for

  • How to apply dll file or user defined function in B1

    Dear all, I have dll file and user defined function which use for converting number amount to text of my language. I plan to create UDF to keep the result of function on A/R invoice and I will use this UDF on print layout desiner but I don't know how

  • Displays for G5

    I have recently purchased a second hand G5 from an advertising agency I work for sometimes and was thinking of using an lcd monitor until i can afford an apple led cinema display. I have a recently bought samsung LS19CFEKF/EN at home and was wonderin

  • Authentication APIs

    Guys, can any one tell me from where i can download the API for Identity Server Authentication for ex.com.sun.identity.authentication api. Thanks, Ramnath

  • Restoration of 10gR2 RMAN backupset onto 11gR1 database

    I am trying to restore my RMAN backupset from 10gR2 RAC database onto 11gR1 RAC database, both on HP Itanium v11.31. I was wondering if anyone has tried this before? RMAN> alter database open resetlogs; using target database control file instead of r

  • Chart in new browser window

    currently in my application , i have view chart option which opens the chart in popup. But how do i open it in new browser window?