Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have been working on something almost similar to what you are trying to accomplish. I have a GUI where the user enters values and then click on a start button to run a program (that uses these values as inputs). When the program starts, I have the choice between:</p> <ul> <li>hide the GUI and start the program or...</li> <li>hide the input fields and show a log text box displaying the status of the program while the program is running.</li> </ul> <p>In both cases, I create a new java thread when I want to launch the program. </p> <p>Here are the resources that were useful to me:</p> <ul> <li>Code to create a file chooser GUI: <a href="http://docs.oracle.com/javase/tutorial/uiswing/examples/components/FileChooserDemoProject/src/components/FileChooserDemo.java" rel="nofollow">http://docs.oracle.com/javase/tutorial/uiswing/examples/components/FileChooserDemoProject/src/components/FileChooserDemo.java</a></li> <li>Code to create input dialog<a href="http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html#joptionpaneapi" rel="nofollow">http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html#joptionpaneapi</a></li> <li><p>Code to create an action listener that launches your program in a new thread:</p> <pre><code>//Handle LAUNCH action. else if (e.getSource() == launchButton) { JFrame launchConfirmationFrame = new JFrame("Launch Confirmation"); launchConfirmationFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); int answer; launchConfirmationFrame.pack(); //downloadDateframe.setVisible(true); //if answer=0 its yes, if its =1 its no! answer = JOptionPane.showConfirmDialog( launchConfirmationFrame ,"^^^^ ARE YOU SURE YOU WOULD LIKE TO PROCEED? ^^^^" ,"TITLE" ,JOptionPane.YES_NO_OPTION); if(answer==0) { buttonPanel.removeAll(); optionsFrame.repaint(); optionsFrame.setVisible(true); // THIS HIDES THE GUI FRAME if it is set to false. System.out.println("Launching YOURPROGRAM..."); //THIS CREATES AND STARTS THE THREAD WITH YOUR PROGRAM TO BE LAUNCHED //More info on threads here http://docs.oracle.com/javase/tutorial/essential/concurrency/runthread.html Thread t = new Thread(new Runnable() { public void run() { //Turn off metal's use of bold fonts UIManager.put("swing.boldMetal", Boolean.FALSE); launchYOURPROGRAM(); } }); t.start(); } else if (answer==1) { optionsFrame.setVisible(false); optionsFrame.setVisible(true); System.out.println("Returning to GUI Frame..."); } }' </code></pre></li> </ul> <p>Remember to make your Jframe (here I called it optionsFrame) static so that when you are in you YOURPROGRAM you can decide whether to display it again or hide it.</p> <p>From your program, you can call:</p> <pre><code>private AbstractAction start = new AbstractAction("start") { @Override public void actionPerformed(ActionEvent arg0) { optionsFrame.setVisible(false); } }; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload