Diclonius Posted June 25, 2013 Share Posted June 25, 2013 (edited) First up I'm not a java expert so there maybe be bad java practice in this tutorial. It would help if you could point out things I have done wrong . Also I'm pretty tired when making this so there is bound to be at lease one mistake. I hope you guys appreciate the time it took to take, crop and upload all these damn pictures. So first up your script should look something like this (But hopefully you can spell your own username correctly). http://i.imgur.com/L2i1KyH.png Now the first thing we are going to do is create a new variable of type long called lastCheck. This is going to hold the time that we last checked for an update. We also want to set this variable to the current time which we do by setting it to System.currentTimeMillis() in the onstart method. Finally we are going to create a new method, checkForUpdate() http://i.imgur.com/SWiCq10.png So we want to make the script check for an update every 10 minutes so if the last time we checked, plus 600000 milliseconds is less than the current time in milliseconds, we want to check for an update. http://i.imgur.com/aVX3O8l.png Ok so how are we actually going to check for an update? Well we are going to create a paste on the website http://pastebin.com/ . Browse to this website and click sign up (Unless you already have an account). http://i.imgur.com/1fAWFtM.png Now you should fill in the details and do what you need to do to create an account. After this is done sign in and create a new paste. http://i.imgur.com/kgAL4YJ.png Next we want to fill in the version of your script and also name it at the bottom. http://i.imgur.com/U46fjVY.png Then click on raw http://i.imgur.com/PvZTYUf.png This will open up a new page which will only contain our script version. We want to copy the URL of this page. http://i.imgur.com/e7Ft8Er.png Now we need to have this URL in a way the script can actually use it so we create a new URL object. Change the URL to your URL and import URL. http://i.imgur.com/mlUjmoi.png Add a try/catch http://i.imgur.com/TBjEaYe.png Now we want to change the exception type because we are going to be doing some other stuff aswell http://i.imgur.com/qTjLprb.png Now we need to read what is at the URL so we create a scanner that scans the URL and then we store the first line of text that the scanner gets in the variable latestVersion. Finally we close the scanner (Very important). http://i.imgur.com/zh6GsZJ.png Then we can get the version of our script and convert it into a string too so that they are both the same type. Also we print out the two versions and also an error message in the catch section which is ran if there was an error. http://i.imgur.com/CQG7Bs2.png Now let's be a cool kid and check if the two versions are the same http://i.imgur.com/njXqWTq.png So we want something to actually happen if the script is out of date right? So we right click our package and go to new --> other http://i.imgur.com/esmdthq.png Select Jframe under Windowbuilder --> Swing Designer http://i.imgur.com/KUFGJoq.png Give this beast a sensible name http://i.imgur.com/fJ3gP5a.png Click design which is at the bottom http://i.imgur.com/bpyRosQ.png Now it should look like this http://i.imgur.com/ZZamScG.png To make editing the window easy we need to set it to absolute layout. We do this by selecting absolute layout by clicking it, then clicking our window on the right. It should get highlighted in green. http://i.imgur.com/YOQrhFn.png Now we want to add a message to the window so click JTextPane and then click on the window. You can then move and resize the object much like you would in Microsoft word. http://i.imgur.com/xzKmb31.png Resize the box to however you want and then select it and press text to add a message. http://i.imgur.com/VVG1snW.png Enter your message in this box http://i.imgur.com/lDgDGjO.png Click JButton and click your window on the right to place it. You should resize it too. http://i.imgur.com/AtMmlYd.png Click text again and change the text if you want http://i.imgur.com/QyO3CIE.png Now the window looks correct we need to make it do stuff, so click source http://i.imgur.com/hPd6Q8j.png It should now look like this http://i.imgur.com/IItPLEX.png We can remove public static void main because it is only used if this was it's own stand-alone program. http://i.imgur.com/kY5uiqY.png Now we want to something to happen when we click the button so we type this and import ActionListener http://i.imgur.com/ylco7Rn.png Then add unimplimented methods http://i.imgur.com/nGrNzqu.png And it should look like this: http://i.imgur.com/bVhr3dO.png Now similarly to what we did before, we create a URI (Different to URL) and import it. The link should be one to your thread or download page. http://i.imgur.com/0J5WSLc.png Surround it with a try/catch http://i.imgur.com/Swvgb97.png Now to make the script open this webpage we need to create a desktop instance and import it like so: http://i.imgur.com/63yNrqy.png Then we can use the browse method to open the web page. Remember to add a try/catch: http://i.imgur.com/Hg26OhI.png We are nearly done! Just scroll to the top and edit this line to say DISPOSE and not EXIT. This will stop the whole client from closing when this window is closed. http://i.imgur.com/fVTu6hP.png Now we need to make our script open the window so we need to create a new global instance of it. Just place it inside the class but outside of any methods: http://i.imgur.com/dKS2oNv.png Now we want to make the window visible when an update is detected. http://i.imgur.com/U5ygNqN.png And to update the version, all you have to do is edit the version in the script here: http://i.imgur.com/y8Esc82.png and on pastebin by signing in and editing the paste. Edited June 25, 2013 by Diclonius 3 Link to comment Share on other sites More sharing options...
Nicholas Posted June 25, 2013 Share Posted June 25, 2013 thanks this will be usefull Link to comment Share on other sites More sharing options...
Sex Posted June 25, 2013 Share Posted June 25, 2013 Cool already knew this :lol: Link to comment Share on other sites More sharing options...
Jordan Posted June 29, 2013 Share Posted June 29, 2013 Very detailed guide. Thanks for this. Link to comment Share on other sites More sharing options...
Zuup Posted June 29, 2013 Share Posted June 29, 2013 Wow, you've definitely put time in this, thank you for such a very nice guide, I've learned quite a good bit by going through this guide! . On another note, is it somehow possible to make the script download the new version itself and run it, I don't think the client supports this though? - Atleast I've noticed I have to hit the "Refresh" button each time I edit my script (I like to edit a part, run the script to see that part, etc). Thanks again Link to comment Share on other sites More sharing options...
Diclonius Posted June 29, 2013 Author Share Posted June 29, 2013 (edited) Wow, you've definitely put time in this, thank you for such a very nice guide, I've learned quite a good bit by going through this guide! . On another note, is it somehow possible to make the script download the new version itself and run it, I don't think the client supports this though? - Atleast I've noticed I have to hit the "Refresh" button each time I edit my script (I like to edit a part, run the script to see that part, etc). Thanks again You could make your script just a downloader then make it download the latest script from a server every time it is ran. It's not too difficult at all but it is a bit more complex than this. Edited June 29, 2013 by Diclonius Link to comment Share on other sites More sharing options...
Zuup Posted June 29, 2013 Share Posted June 29, 2013 Makes good sense, thanks for the quick response . Link to comment Share on other sites More sharing options...