Hafdellaren Posted December 28, 2016 Posted December 28, 2016 How do I use the string in onPaint? right now I have g.drawString("Elapsed Time: " + startTime, 20, 265); but it isn't working so well lol
itsvenec Posted December 28, 2016 Posted December 28, 2016 I'm still on the fence as far as trying to learn scripting, but if I do, I will definitely make use of this tutorial. Thanks!
progamerz Posted December 28, 2016 Posted December 28, 2016 How do I use the string in onPaint? right now I have g.drawString("Elapsed Time: " + startTime, 20, 265); but it isn't working so well lol Add this method: public final String formatTime(final long ms){ long s = ms / 1000, m = s / 60, h = m / 60; s %= 60; m %= 60; h %= 24; return String.format("%02d:%02d:%02d", h, m, s); } Taken from the OP. now in place of startTime, put formatTime(startTime) And it should work well.
Hafdellaren Posted December 28, 2016 Posted December 28, 2016 Add this method: public final String formatTime(final long ms){ long s = ms / 1000, m = s / 60, h = m / 60; s %= 60; m %= 60; h %= 24; return String.format("%02d:%02d:%02d", h, m, s); } Taken from the OP. now in place of startTime, put formatTime(startTime) And it should work well. At the login screen it says; Elapsed Time - 00:00:00 and when it actually starts ingame it just says 12:25:06 and stays like that. So I've added private long startTime; final long runTime = System.currentTimeMillis() - startTime; public final String formatTime(final long ms){ long s = ms / 1000, m = s / 60, h = m / 60; s %= 60; m %= 60; h %= 24; return String.format("%02d:%02d:%02d", h, m, s);} then to onStart I've added startTime = System.currentTimeMillis(); and onPaint: g.drawString("Elapsed Time: " + formatTime(startTime), 10, 332);
progamerz Posted December 28, 2016 Posted December 28, 2016 At the login screen it says; Elapsed Time - 00:00:00 and when it actually starts ingame it just says 12:25:06 and stays like that. So I've added private long startTime; final long runTime = System.currentTimeMillis() - startTime; public final String formatTime(final long ms){ long s = ms / 1000, m = s / 60, h = m / 60; s %= 60; m %= 60; h %= 24; return String.format("%02d:%02d:%02d", h, m, s);} then to onStart I've added startTime = System.currentTimeMillis(); and onPaint: g.drawString("Elapsed Time: " + formatTime(startTime), 10, 332); Oh should have been formatTime(runTime) Sorry was my bad or something. 1
Hafdellaren Posted December 28, 2016 Posted December 28, 2016 (edited) Oh should have been formatTime(runTime) Sorry was my bad or something. Now it just says 12:45:43 from login screen and aswell when it runs EDIT: It works now. Changed -> final long runTime = System.currentTimeMillis() - startTime; To -> long runTime = System.currentTimeMillis() - startTime; and moved it to onPaint Edited December 28, 2016 by Hafdellaren 1
progamerz Posted December 28, 2016 Posted December 28, 2016 Now it just says 12:45:43 from login screen and aswell when it runs EDIT: It works now. Changed -> final long runTime = System.currentTimeMillis() - startTime; To -> long runTime = System.currentTimeMillis() - startTime; and moved it to onPaint Oh i didn't know u didn't have it in onPaint() anywayz good job
CanCo Posted August 8, 2017 Posted August 8, 2017 On 12/2/2015 at 3:54 AM, Explv said: private Optional<Integer> getPrice(int id){ Optional<Integer> price = Optional.empty(); try { URL url = new URL("http://api.rsbuddy.com/grandExchange?a=guidePrice&i=" + id); URLConnection con = url.openConnection(); con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"); con.setUseCaches(true); BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream())); String[] data = br.readLine().replace("{", "").replace("}", "").split(","); br.close(); price = Optional.of(Integer.parseInt(data[0].split(":")[1])); } catch(Exception e){ e.printStackTrace(); } return price; } Hey i simply dont understand how to implement this code. What imports do i need for it?
HeyImJamie Posted August 9, 2017 Posted August 9, 2017 3 hours ago, CanCo said: Hey i simply dont understand how to implement this code. What imports do i need for it? Just input the price manually if you can't figure this out.
Antonio Kala Posted August 9, 2017 Posted August 9, 2017 3 hours ago, HeyImJamie said: Just input the price manually if you can't figure this out. How much cpu would you say having something that calculates gp/hr and runtime use? or would it be negligible?
IDontEB Posted August 9, 2017 Posted August 9, 2017 18 minutes ago, Antonio Kala said: How much cpu would you say having something that calculates gp/hr and runtime use? or would it be negligible? runtime would be near negligible but calculating GP/h depends on whether your getting prices from GE constantly and what other calculation your doing. if its a simple calculation also near negligible
Antonio Kala Posted August 9, 2017 Posted August 9, 2017 11 minutes ago, IDontEvenBot said: runtime would be near negligible but calculating GP/h depends on whether your getting prices from GE constantly and what other calculation your doing. if its a simple calculation also near negligible Someone told me paint runs on a separate thread regardless of what it is, and thus it's better if avoided?