#I need help making my console not close
1 messages · Page 1 of 1 (latest)
Hey, @sonic storm!
Please remember to /close this post once your question has been answered!
wdym
like a loop?
no
how do i make
public class Console {
}
class CommandLineExample
{
public static void main ( String [] arguments )
{
System.out.println("Elystro.js");
}
}
liike not close when i open it
it stays pen forever until i press the close button
That's not under Java's control
Open the console first and run the program in then. Can be done with a Windows shortcut
dude
im making a console in java
thats all
on gui or application
just console by itself
I don't know what IDE you're using, because most have the console integrated into the same window.
Try doing System.in.read() at the end
The console is closing because the program has ended. If you want to keep the program running you have to do something to make it keep running such as in.read as suggested above, which indefinitely await input from stdin unless/until you give some input
yes i think so it remebers and keeps in memory the outputs or the list of liens u can do that too
can u show ur console code
Wdym?
System.out.println
Or do you want Eclipse's source code for the console widget?
oh i thought u were making a console
nvm i thought u were op sorrylol
Well, IDEs are aware that they're being used by people currently trying to develop something and who need the potential feedback to stay.
Windows consoles, not so much, though I wouldn't deny if someone said that's another of Microsoft's stupid decisions
I assumed this was being run from an IDE
Does it involve a batch script?
(to OP)
oh ok
nah
i managed to fix it
just made a gui
then set visibility to false
you could use a Thread to do it
might use less resources i think.
ok
ExecutorService console = Executors.newFixedThreadPool(1);
console.execute(() -> {
try {
while (true) {
Thread.sleep(1);
}
}
catch (InterruptedException e) {
e.prinStackTrace;
}
});
Why would you use a thread pool?
and you shouldn't use (Throwable::/e.)printStackTrace
why?
Well, I guess it's fine for small programs
but having a thread that always waits I don't think is considered good practice
because that's essentially what they're doing anyway when they create a gui
more control over your thread?
how?
BufferedReader reader = new BufferedReader(System.in);
for(;;) {
String input = reader.readLine();
if(input.equals("stop")) {
break;
}
}
or
BufferedReader reader = new BufferedReader(System.in);
boolean running = true;
while(running) {
String input = reader.readLine();
if(input.equals("stop")) {
running = false;
continue;
}
}
if you prefer
i guess I don't fully understand what they are doing in the first place but this is probably the better option