Your question / my comments:
I want to implement reset feature in my application which cleans up some directories, copies files etc. then in order to complete the process I need to restart it. How to make application reruns itself?
This is a common feature/need of many applications, and not just academic assignments. Unfortunately there is no one-size-fits all solution to this, and it will all depend on the specifics of your program. If your program is very modular and written with smart M-V-C separation of concerns, it becomes much easier to do this, often just resetting the model to its initial state, or by loading a new model into the GUI.
I think opening second instance and closing this one would be enough, altough it is not real restart.
I think that this is a very bad idea. Better to simply reset the state of your text components, buttons, checkboxes, etc to their original state. Again, the more modular your code, the easier it is to do. Each separate module could have its own reset()
method that takes care of initializing it.
In my case I want to reload the JFrame consisting of many JPanels. I have done that:
Again, I urge you not to go this route.
You could place some of your JTextComponents into an ArrayList for ease of resetting. For example, you could reset your GUI fields inside of reset. Something like:
public void reset() {
// assuming you have an ArrayList of JTextComponents called textComponents
for (JTextComponent textComponent : textComponents) {
textComponent.setText("");
}
// same if you had a bunch of comboboxes in a List called comboBoxes
for (JComboBox comboBox : comboBoxes) {
comboBox.setSelection(-1); // consider removing listeners first, then re-adding them
// etc for other components
}
}
Edit
I found out that my solution -> disposing JFrame is not so good. I have a lot of static blocks, loading serialized files etc. I need to really restart it. Maybe there is easy way to application execute itself.
Sorry, but this only suggests to me that your program could probably have its organization improved upon. It should be reset-able, and if not, consider changing it so that it can be so. Does it follow a Model-View-Control structure? If not, consider doing this.