GithubHelp home page GithubHelp logo

How to restart gracefully about text-io HOT 4 OPEN

mokun avatar mokun commented on August 25, 2024
How to restart gracefully

from text-io.

Comments (4)

siordache avatar siordache commented on August 25, 2024

How does terminal.dispose(null) crash? Can you post the stack trace?

from text-io.

mokun avatar mokun commented on August 25, 2024

Sorry. not crashing. I meant the JFrame was disposed before I can save up some objects.

So I'm hoping not to dispose the JFrame.

But if I set the keepRunning to false, the beryx console would just halt and no longer work.

So my question is how can I make the console work again without disposing/rebuilding the whole JFrame ?

from text-io.

siordache avatar siordache commented on August 25, 2024

I'm not sure if it helps, but try to replace this line with:

((MarsTerminal)InteractiveTerm.getTextIO().getTextTerminal()).getFrame().setVisible(false);

from text-io.

mokun avatar mokun commented on August 25, 2024

My first objective is to find out how to exit the text-io properly.

In my case in a class called MarsTerminal that extends SwingTextTerminal, I attach a listener to the top-right corner exit button to ask for confirmation if I want to exit as follows :

  private void configureMainMenu() {
        frame = getFrame();
         
	frame.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent event) {
				// Save simulation and UI configuration when window is closed.
				int reply = JOptionPane.showConfirmDialog(null, "Are you sure you want to quit?", "Exit", JOptionPane.YES_NO_OPTION);
		        if (reply == JOptionPane.YES_OPTION) {
		            printf("Exiting the Simulation..." + System.lineSeparator());
		            Simulation sim = Simulation.instance();
		        	sim.endSimulation(); 
		    		sim.getSimExecutor().shutdownNow();
		    		if (sim.getMasterClock() != null)
		    			sim.getMasterClock().exitProgram();
		    		logger.info("Exiting the Simulation.");
		    		InteractiveTerm.setKeepRunning(false);
					System.exit(0);
					frame.setVisible(false);
			    	dispose(null);
		        }
			}
		});

When I choose the Yes button to quit, I have the following stacktrace :

java.lang.RuntimeException: read interrupted
	at org.beryx.textio.swing.SwingTextTerminal.read(SwingTextTerminal.java:378)
	at org.beryx.textio.InputReader.readWithPrompt(InputReader.java:437)
	at org.beryx.textio.InputReader.lambda$read$3(InputReader.java:382)
	at org.beryx.textio.TextTerminal.applyWithPropertiesConfigurator(TextTerminal.java:243)
	at org.beryx.textio.InputReader.executeWithTerminal(InputReader.java:461)
	at org.beryx.textio.InputReader.read(InputReader.java:380)
	at org.beryx.textio.InputReader.read(InputReader.java:368)
	at org.mars.sim.console.SwingHandler$Task.run(SwingHandler.java:188)
	at org.mars.sim.console.SwingHandler.executeOneTask(SwingHandler.java:345)
	at org.mars.sim.console.InteractiveTerm.selectMode(InteractiveTerm.java:165)
	at org.mars.sim.console.InteractiveTerm.startModeSelection(InteractiveTerm.java:136)
	at org.mars_sim.main.MarsProject.handleNewSimulation(MarsProject.java:418)
	at org.mars_sim.main.MarsProject.initializeSimulation(MarsProject.java:191)
	at org.mars_sim.main.MarsProject$SimulationTask.run(MarsProject.java:164)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.InterruptedException
	at java.base/java.lang.Object.wait(Native Method)
	at java.base/java.lang.Object.wait(Object.java:328)
	at org.beryx.textio.swing.SwingTextTerminal.read(SwingTextTerminal.java:355)
	... 18 more

from text-io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.