![]() |
[Java] L- Systems : Tree - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Java, JVM, & JRE (https://sinister.ly/Forum-Java-JVM-JRE) +--- Thread: [Java] L- Systems : Tree (/Thread-Java-L-Systems-Tree) |
[Java] L- Systems : Tree - Psycho_Coder - 10-21-2013 Tree Fractal example code. ![]() Code: import java.awt.Color; Played a bit with the code and got some simple designs :- Spoiler: RE: [Java] L- Systems : Tree - Deque - 10-21-2013 Neat. That's beautiful code (as far as Java can be beautiful) and a beautiful result. Some minor things: The @author tag belongs above the class declaration. If you print the stacktrace you don't need to print the error message too. It is already done with the stacktrace. You can use invokeLater() instead of invokeAndWait(). The latter is used for applets. Code: frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); RE: [Java] L- Systems : Tree - Psycho_Coder - 10-21-2013 (10-21-2013, 07:37 PM)Deque Wrote: Neat. That's beautiful code (as far as Java can be beautiful) and a beautiful result. Now this is an example that we must never be in a hurry. I had to the post code in my fb group and I was in a hurry, and then forgot to re-factor it. I knew about the first three things that you said. Initially I made an applet but later changed to JFrame but forgot to change the invokeAndWait() to invokeLater(). but about the 4th point that you mentioned about using DISPOSE_ON_CLOSE why ? will you please state the reason. I find that JFrame.EXIT_ON_CLOSE is used in most places and even in the Oracles Java tutorial section examples and so I used EXIT_ON_CLOSE. Whatever the reason maybe I will from now on use what you asked me to do (just as I followed your saying always) Code Updated. Sorry for this silly mistakes, I will take care from now on to verify and refactor my code before posting. Thanks. RE: [Java] L- Systems : Tree - Deque - 10-21-2013 (10-21-2013, 07:56 PM)Psycho_Coder Wrote: but about the 4th point that you mentioned about using DISPOSE_ON_CLOSE why ? will you please state the reason. I find that JFrame.EXIT_ON_CLOSE is used in most places and even in the Oracles Java tutorial section examples and so I used EXIT_ON_CLOSE. Whatever the reason maybe I will from now on use what you asked me to do (just as I followed your saying always) It's for the same reason you shouldn't use System.exit() in your code. EXIT_ON_CLOSE shuts down the JVM. This results into code that is:
I.e. if you create a .jar another person want's to use in his/her program and your program comes to call EXIT, because the window is closed, the program that embeds your .jar will be closed too. No matter if there are still windows open. I.e. if you place a ShutdownHook or take any other precautions to close everything correctly before shutdown (cleaning temp files, closing streams, save actions, ...), it won't be called. I.e. it will be impossible to create unit tests when the program just shuts down. Don't use EXIT_ON_CLOSE or System.exit(). DISPOSE_ON_CLOSE will shut down your program if the last window was closed and nothing else (threads etc) still runs. (If you use Eclipse you can see if it runs at the red square.) Of course you will have to take more care for a proper shutdown. It may happen that your program still runs after closing it, because something else is still running in the background. But it is your responsibility to close everything properly. If every programmer would just do that (avoid System.exit()) it would have already had spared me a lot of time decompiling, fixing and recompiling .jar files. RE: [Java] L- Systems : Tree - Psycho_Coder - 10-22-2013 Played with the code and got some simple designs. EDIT: The code has not been updated with the code that has effects. RE: [Java] L- Systems : Tree - cervito21 - 11-26-2013 hi sir im newbie can help how to run that codes? its amazing RE: [Java] L- Systems : Tree - cervito21 - 11-26-2013 hi sir im newbie can help how to run that codes? its amazing RE: [Java] L- Systems : Tree - Psycho_Coder - 11-26-2013 (11-26-2013, 03:46 PM)cervito21 Wrote: hi sir im newbie can help how to run that codes? its amazing Do you use any Java IDE ? If not then just paste the code in any text editor and save as L_Systems_Tree.java, then from terminal write the following ;- javac L_Systems_Tree.java java L_Systems_Tree RE: [Java] L- Systems : Tree - Psycho_Coder - 11-26-2013 (11-26-2013, 03:46 PM)cervito21 Wrote: hi sir im newbie can help how to run that codes? its amazing Do you use any Java IDE ? If not then just paste the code in any text editor and save as L_Systems_Tree.java, then from terminal write the following ;- javac L_Systems_Tree.java java L_Systems_Tree RE: [Java] L- Systems : Tree - cervito21 - 11-27-2013 sir i am using netbeans ide, how can i run it? |