I am simply trying to implement a button which will re run a main file in my program. So, essentially when the button is clicked, the application will restart, and it will be like the user is playing the game again from the start. Is this possible? and if so how would I go about coding this button? I am using netbeans IDE 8.0 Thank you all very much for taking the time to try and help me out :) I appreciate it. Kind regards.
Extra Edit 1: Is there anything that will just reopen the main class? I read somewhere that Application.Restart() will work in a C# application. Is there anything like this for NetBeans? Cheers in advance
for restarting application you can use below code
Runtime.getRuntime().exec("java -jar myApp.jar");
System.exit(0);
in netbeans platform application you can use this command
LifecycleManager.getDefault().markForRestart();
LifecycleManager.getDefault().exit();
Surely reading this will help:
http://docs.oracle.com/javase/tutorial/essential/concurrency/runthread.html
You should create a thread where the game is run.
Each time you pressed or reboot or wake up the thread.
I hope it's some help.
Related
I am new to java or coding in general. I am currently taking a course for Computer Programming. For this final assignment I need to make a .jar program or game. I have decided to make a game but it does not execute like it does in an IDE. Thank you in advance for the help.
successful launch in the ide
launch as a .jar file
Thank you for all the help, I have solved my own problem by adding a sleep timer to my gui from the main method and by default setting my gui to invisible, once the main method ran it set the gui to visible. Thank you again for all the help.
I'm recently working with Eclipse Che and have the task to import a Java Project that opens a GUI in it (like a simple Swing/SWT Calculator).
I am using the Java CentOS Stack, importing the .jar files, etc. is no problem but I get the "No X11 DISPLAY variable was set, but this program performed an operation which requires it." error.
Obviously, I found many threads about that Error, but I just wanted to ask if it is even possible to open a GUI in a web based IDE like Eclipse Che before wasting hours trying to fix that error when it's not even possible.
Maybe some of you already tried that and have a solution/tip or smth for me.
edit: found a video that answered my question. https://www.youtube.com/watch?v=AjgSp0dkxxU
Thanks anyway.
This will help you out - https://eclipse-che.readme.io/docs/che-and-swing
You need to use the right stack
You need to set the display variable. The way I did this was modify the run command to set it just before the other commands.
The command I used is:
export DISPLAY=:0.0
Also note that this worked for a while for me but randomly stop working a few days back so please tell if you manage to get it working.
I made a java program for a pop-up from time to time by running a batch file. Application is working fine but after running the application(Batch file) we are able to see the cmd prompt in taskbar(minimize state), but i want the application run in background (like skype or gtalk).
Please help me.
Thank you in advance
Make sure you launch it using javaw (instead of java).
Relevant portion from the first link from the first search here:
This is provided as a helper so that application launches its own GUI window and will not launch a console. Whenever we want to run a GUI based application and don’t require a command console, we can use this as application launcher.
I hope this helps you.
Use a vbs script to invoke the batch script it would hide the window
CreateObject("Wscript.Shell").Run "yourbatchname.bat",0,True
I'm having this issue in my MATLAB program.
I want to perform a set operation on my UI during a coding. In other words I'm pressing a button to launch my code and at the same time I want to change some uicontrols.
I tried with pause and wait with no luck.
I'm pretty sure that MATLAB gives priority to my coding part intead of the Java interface.
Anyone has any idea? Thanks
Thanks to nick I solved adding
waitnow; pause(.1);
Guys, unbelievable, that works on linux/OSX but not under windows..that's so weird
I close my application by pressing a "Close" button. But in the Eclipse I see a red square indicating that something is still running. When I press this red square, I kill my application completely.
Is it possible to find out what is still running (which method, which loop) using Eclipse?
P.S. I am a newbie. So, it would be nice to have a simple solution. I also might not understand your answer if you use "technical" words which I do not know.
ADDED:
I cannot use System.exit since it will kill not only my software but also an "external" software which calls my software.
Have a look at jps and jstack commands they will give you the process id for your application and then you can view the threads and their states using jstack.
Its very useful for this kind of issue.
Sorry just realised you wanted something in eclipse to do this. well I'll leave this answer as it should work but not inside eclipse.
Debug View shows just that. To see the concrete methods for each thread you need to stop the application. Most probably you just need to set default close operation for the main JFrame.