View difference between Paste ID: VtfhtmKv and
SHOW:
|
|
- or go back to the newest paste.
| 1 | - | |
| 1 | + | import java.awt.Container; |
| 2 | import java.awt.Dimension; | |
| 3 | import java.awt.Font; | |
| 4 | import java.awt.Insets; | |
| 5 | import java.awt.Paint; | |
| 6 | import java.awt.Rectangle; | |
| 7 | import java.awt.event.ActionEvent; | |
| 8 | import java.awt.event.ActionListener; | |
| 9 | import java.awt.*; | |
| 10 | import java.util.*; | |
| 11 | import java.net.*; | |
| 12 | import java.util.List; | |
| 13 | import java.util.logging.Level; | |
| 14 | import java.lang.reflect.Method; | |
| 15 | import javax.accessibility.*; | |
| 16 | import javax.swing.*; | |
| 17 | import org.rsbot.*; | |
| 18 | import org.rsbot.bot.Bot; | |
| 19 | import org.rsbot.script.*; | |
| 20 | import org.rsbot.script.wrappers.*; | |
| 21 | import org.rsbot.event.listeners.*; | |
| 22 | import org.rsbot.event.events.ServerMessageEvent; | |
| 23 | import org.rsbot.util.ScreenshotUtil; | |
| 24 | ||
| 25 | @ScriptManifest(authors = { "Conderoga" }, keywords = "Fletching", name = "Conderoga's Stringer", version = 1.4,description = "The fastest stringer, ever.")
| |
| 26 | /*UpdateLog: | |
| 27 | v1.0 - Updated for RSBot v2.0 | |
| 28 | v1.1 - fixed everything | |
| 29 | v1.2 - fixed not starting after randoms. | |
| 30 | v1.3 - fixed the fix | |
| 31 | v1.4 - Still tinkering | |
| 32 | */ | |
| 33 | ||
| 34 | ||
| 35 | public class CFletch extends Script implements PaintListener, ServerMessageListener {
| |
| 36 | ||
| 37 | private boolean guiWait = true; | |
| 38 | private boolean guiExit = true; | |
| 39 | private String action = "WAITING"; | |
| 40 | ||
| 41 | ||
| 42 | CFletchGui gui; | |
| 43 | private int unstrungBowId = 0; | |
| 44 | private int logId = 0; | |
| 45 | private int bowstring = 1777; | |
| 46 | private int startLevel; | |
| 47 | private int startExp; | |
| 48 | private int expGained; | |
| 49 | private int lvlsGained; | |
| 50 | private long startTime; | |
| 51 | private double startTimeDbl; | |
| 52 | private long ExpHr; | |
| 53 | private int safety = 0; | |
| 54 | private String status; | |
| 55 | private Point p; | |
| 56 | private boolean stringing = false; | |
| 57 | private boolean fletching = false; | |
| 58 | private int []bankerIds; | |
| 59 | private RSNPC test; | |
| 60 | private long stringStartTime = 0; | |
| 61 | private int tempNumStrung = 0; | |
| 62 | private int oneTimeOnly = 0; | |
| 63 | private String version = "v1.4"; | |
| 64 | private int bowsStrung = 0; | |
| 65 | private int failsafe = 0; | |
| 66 | ||
| 67 | ||
| 68 | ||
| 69 | ||
| 70 | public boolean onStart() {
| |
| 71 | gui = new CFletchGui(); | |
| 72 | gui.setVisible(true); | |
| 73 | while(guiWait) | |
| 74 | {
| |
| 75 | sleep(100); | |
| 76 | } | |
| 77 | log("Action: "+action);
| |
| 78 | startTime = System.currentTimeMillis(); | |
| 79 | startTimeDbl = System.currentTimeMillis(); | |
| 80 | //Credits to Zombieknight for this:----------------- | |
| 81 | final int welcome = JOptionPane.showConfirmDialog(null,"Before using my script, would you like to thank me\nby clicking some adverts?","Welcome", JOptionPane.YES_NO_OPTION); | |
| 82 | if (welcome == 0) {
| |
| 83 | final String message = "<html>Thank you for your support!<br />"+"You will now be redirected to an advert loop.<br />"+"Just keep pressing skip ad as long as you wish.</html>"; | |
| 84 | JOptionPane.showMessageDialog(null, message); | |
| 85 | openURL("http://adf.ly/317631/agsn");
| |
| 86 | } | |
| 87 | //-------------------------------------------------- | |
| 88 | return !guiExit; | |
| 89 | } | |
| 90 | public void startUpStuff() | |
| 91 | {
| |
| 92 | bankerIds = bank.BANKERS; | |
| 93 | test = npcs.getNearest(bankerIds); | |
| 94 | if(action.equals("Normal Short - String"))
| |
| 95 | {
| |
| 96 | stringing = true; | |
| 97 | unstrungBowId = 50; | |
| 98 | } | |
| 99 | if(action.equals("Normal Long - String"))
| |
| 100 | {
| |
| 101 | stringing = true; | |
| 102 | unstrungBowId = 48; | |
| 103 | } | |
| 104 | if(action.equals("Oak Short - String"))
| |
| 105 | {
| |
| 106 | stringing = true; | |
| 107 | unstrungBowId = 54; | |
| 108 | } | |
| 109 | if(action.equals("Oak Long - String"))
| |
| 110 | {
| |
| 111 | stringing = true; | |
| 112 | unstrungBowId = 52; | |
| 113 | } | |
| 114 | if(action.equals("Willow Short - String"))
| |
| 115 | {
| |
| 116 | stringing = true; | |
| 117 | unstrungBowId = 60; | |
| 118 | } | |
| 119 | if(action.equals("Willow Long - String"))
| |
| 120 | {
| |
| 121 | stringing = true; | |
| 122 | unstrungBowId = 58; | |
| 123 | } | |
| 124 | if(action.equals("Maple Short - String"))
| |
| 125 | {
| |
| 126 | stringing = true; | |
| 127 | unstrungBowId = 64; | |
| 128 | } | |
| 129 | if(action.equals("Maple Long - String"))
| |
| 130 | {
| |
| 131 | stringing = true; | |
| 132 | unstrungBowId = 62; | |
| 133 | } | |
| 134 | if(action.equals("Yew Short - String"))
| |
| 135 | {
| |
| 136 | stringing = true; | |
| 137 | unstrungBowId = 68; | |
| 138 | } | |
| 139 | if(action.equals("Yew Long - String"))
| |
| 140 | {
| |
| 141 | stringing = true; | |
| 142 | unstrungBowId = 66; | |
| 143 | } | |
| 144 | if(action.equals("Magic Short - String"))
| |
| 145 | {
| |
| 146 | stringing = true; | |
| 147 | unstrungBowId = 72; | |
| 148 | } | |
| 149 | if(action.equals("Magic Long - String"))
| |
| 150 | {
| |
| 151 | stringing = true; | |
| 152 | unstrungBowId = 70; | |
| 153 | } | |
| 154 | } | |
| 155 | public void serverMessageRecieved(final ServerMessageEvent a){
| |
| 156 | final String serverString = a.getMessage(); | |
| 157 | if (serverString.toLowerCase().contains("you add a string to the bow"))
| |
| 158 | {tempNumStrung++;
| |
| 159 | bowsStrung++; | |
| 160 | } | |
| 161 | } | |
| 162 | public boolean string() | |
| 163 | {
| |
| 164 | status = "Clicking."; | |
| 165 | tempNumStrung = 0; | |
| 166 | mouse.move(633,335,5,5); | |
| 167 | mouse.click(true); | |
| 168 | mouse.move(663,335,5,5); | |
| 169 | sleep(random(500,600)); | |
| 170 | mouse.click(true); | |
| 171 | sleep(random(1200,1300)); | |
| 172 | int x = random(253,273); | |
| 173 | int y = random(409,429); | |
| 174 | mouse.move(x,y,0,0); | |
| 175 | String [] actions = menu.getActions(); | |
| 176 | if(actions.length>0) | |
| 177 | {
| |
| 178 | for(int i = 0; i< actions.length;i++) | |
| 179 | if(actions[i].contains("Make All"))
| |
| 180 | {mouse.click(true);
| |
| 181 | return true;} | |
| 182 | } | |
| 183 | return false; | |
| 184 | } | |
| 185 | public void bank() | |
| 186 | {
| |
| 187 | if(random(1,20)==2) | |
| 188 | camera.setPitch(random(40,99)); | |
| 189 | test = npcs.getNearest(bankerIds); | |
| 190 | status = "Finding Banker."; | |
| 191 | if(test!=null) | |
| 192 | {
| |
| 193 | do{
| |
| 194 | mouse.move(test.getModel().getPoint()); | |
| 195 | menu.doAction("Bank Banker");
| |
| 196 | sleep(random(1000,1500)); | |
| 197 | }while(!bank.isOpen()); | |
| 198 | status = "Depositing."; | |
| 199 | mouse.move(395,308,5,5); | |
| 200 | sleep(random(300,400)); | |
| 201 | mouse.click(true); | |
| 202 | status = "Withdrawing."; | |
| 203 | if(stringing) | |
| 204 | {
| |
| 205 | mouse.move(55,109,5,5); | |
| 206 | mouse.click(false); | |
| 207 | sleep(random(300,400)); | |
| 208 | if(oneTimeOnly==0) | |
| 209 | {
| |
| 210 | menu.doAction("Withdraw-X");
| |
| 211 | sleep(random(1000,2000)); | |
| 212 | keyboard.sendText("" + 14, true);
| |
| 213 | oneTimeOnly++; | |
| 214 | } | |
| 215 | else | |
| 216 | {
| |
| 217 | if(!menu.doAction("Withdraw-14"))
| |
| 218 | menu.doAction("Withdraw-14");
| |
| 219 | ||
| 220 | } | |
| 221 | sleep(random(500,800)); | |
| 222 | mouse.move(96,107,5,5); | |
| 223 | mouse.click(false); | |
| 224 | sleep(random(300,400)); | |
| 225 | if(!menu.doAction("Withdraw-14"))
| |
| 226 | menu.doAction("Withdraw-14");
| |
| 227 | ||
| 228 | } | |
| 229 | status = "Closing."; | |
| 230 | mouse.move(491,35,2,2); | |
| 231 | sleep(random(300,400)); | |
| 232 | mouse.click(true); | |
| 233 | status = "Clicking."; | |
| 234 | } | |
| 235 | else | |
| 236 | test = npcs.getNearest(bankerIds); | |
| 237 | ||
| 238 | } | |
| 239 | public boolean stringInventoryHasProper() | |
| 240 | {
| |
| 241 | RSItem [] inv = inventory.getItems(); | |
| 242 | boolean uBow = false; | |
| 243 | boolean bString = false; | |
| 244 | for(int i = 0; i<inv.length;i++) | |
| 245 | {
| |
| 246 | if(inv[i].getID()==unstrungBowId) | |
| 247 | uBow = true; | |
| 248 | if(inv[i].getID()==bowstring) | |
| 249 | bString = true; | |
| 250 | } | |
| 251 | return bString&&uBow; | |
| 252 | } | |
| 253 | public boolean animCheck() | |
| 254 | {
| |
| 255 | return getMyPlayer().getAnimation()!=-1; | |
| 256 | } | |
| 257 | public int loop() {
| |
| 258 | try{
| |
| 259 | if(safety<1) | |
| 260 | {
| |
| 261 | startUpStuff(); | |
| 262 | camera.setPitch(true); | |
| 263 | safety=1; | |
| 264 | if(stringing) | |
| 265 | {
| |
| 266 | bank(); | |
| 267 | sleep(random(600,800)); | |
| 268 | if(stringInventoryHasProper()&&inventory.getCount()==28) | |
| 269 | {
| |
| 270 | string(); | |
| 271 | sleep(random(1200,1300)); | |
| 272 | } | |
| 273 | } | |
| 274 | failsafe=0; | |
| 275 | } | |
| 276 | ||
| 277 | antiBan(random(1,80)); | |
| 278 | if(failsafe>6) | |
| 279 | log(failsafe+" failed attempts."); | |
| 280 | ||
| 281 | if(stringing){ //Stuff to do if stringing
| |
| 282 | ||
| 283 | if(inventory.getCount()<28&&stringInventoryHasProper()&&inventory.getCount()!=14&&failsafe<10) | |
| 284 | {
| |
| 285 | status = "Stringing."; | |
| 286 | if(!animCheck()) | |
| 287 | failsafe++; | |
| 288 | else | |
| 289 | failsafe=0; | |
| 290 | sleep(600,800); | |
| 291 | } | |
| 292 | else if(stringInventoryHasProper()&&inventory.getCount()==28&&failsafe<10) | |
| 293 | {
| |
| 294 | if(string()) | |
| 295 | failsafe=0; | |
| 296 | sleep(random(600,800)); | |
| 297 | } | |
| 298 | else if(failsafe>=10&&failsafe<50) | |
| 299 | {
| |
| 300 | bank(); | |
| 301 | sleep(random(600,800)); | |
| 302 | if(stringInventoryHasProper()) | |
| 303 | {string();
| |
| 304 | failsafe=0;} | |
| 305 | else | |
| 306 | failsafe+=10; | |
| 307 | sleep(random(600,800)); | |
| 308 | } | |
| 309 | else if(failsafe>=50) | |
| 310 | {
| |
| 311 | log("Script has failed ~50 times, logging out as a precaution");
| |
| 312 | game.logout(true); | |
| 313 | stopScript(); | |
| 314 | } | |
| 315 | else | |
| 316 | {
| |
| 317 | bank(); | |
| 318 | sleep(random(600,800)); | |
| 319 | if(stringInventoryHasProper()) | |
| 320 | string(); | |
| 321 | sleep(random(1200,1500)); | |
| 322 | if(animCheck()) | |
| 323 | failsafe=0; | |
| 324 | else | |
| 325 | {
| |
| 326 | status = "Checking Animation..."; | |
| 327 | sleep(random(600,800)); | |
| 328 | if(animCheck()) | |
| 329 | failsafe=0; | |
| 330 | } | |
| 331 | } | |
| 332 | } | |
| 333 | ||
| 334 | ||
| 335 | ||
| 336 | } | |
| 337 | catch (Exception e){}
| |
| 338 | return random(600,800); | |
| 339 | } | |
| 340 | public void antiBan(int rand){
| |
| 341 | status += "(AB)"; | |
| 342 | if(rand==2) | |
| 343 | if(random(1, 8) == 2) | |
| 344 | mouse.moveRandomly(random(400,800)); | |
| 345 | if(rand==3) | |
| 346 | if(random(1, 8) == 2) | |
| 347 | mouse.moveRandomly(random(200,700)); | |
| 348 | if(rand==4) //THIS CHECKS THE FLETCHING STAT | |
| 349 | if(random(1, 8) == 2) | |
| 350 | {
| |
| 351 | game.openTab(game.TAB_STATS); | |
| 352 | mouse.move(random(614, 667), random(360, 370),0,0); | |
| 353 | sleep(random(900,1000)); | |
| 354 | game.openTab(game.TAB_INVENTORY); | |
| 355 | } | |
| 356 | if(rand==5) //THIS CLICKS THE XP BUTTON UNDER THE COMPASS | |
| 357 | if(random(1, 18) == 2) | |
| 358 | {
| |
| 359 | mouse.move(random(527, 540), random(58, 65),0,0); | |
| 360 | mouse.click(true); | |
| 361 | mouse.moveRandomly(random(20,50)); | |
| 362 | sleep(random(900,1000)); | |
| 363 | mouse.move(random(527, 540), random(58, 65),0,0); | |
| 364 | mouse.click(true); | |
| 365 | } | |
| 366 | if(rand==6) //THIS CHECKS CURRENT GOAL | |
| 367 | if(random(1, 18) == 2) | |
| 368 | {
| |
| 369 | mouse.move(random(527, 543), random(471, 496),0,0); | |
| 370 | mouse.click(true); | |
| 371 | sleep(random(300,1000)); | |
| 372 | mouse.move(random(604, 630), random(394, 399),0,0); | |
| 373 | sleep(random(900,1000)); | |
| 374 | game.openTab(game.TAB_INVENTORY); | |
| 375 | } | |
| 376 | if(rand==7) //RANDOM SPIN | |
| 377 | if(random(1, 3) == 2) | |
| 378 | {camera.setAngle(random(1,359));
| |
| 379 | camera.setPitch(random(1,99));} | |
| 380 | if(rand==8) //THIS CHECKS A RANDOM TAB | |
| 381 | if(random(1, 6) == 2) | |
| 382 | {
| |
| 383 | int[] tabs = {0,2,3,5,6,7,9,10,11,12,13,14,15};
| |
| 384 | game.openTab(tabs[random(0,tabs.length-1)]); | |
| 385 | mouse.moveRandomly(75,100); | |
| 386 | sleep(random(1600,1800)); | |
| 387 | sleep(random(900,1000)); | |
| 388 | } | |
| 389 | if(rand==9) | |
| 390 | if(random(1,3)==2) | |
| 391 | mouse.moveOffScreen(); | |
| 392 | status=status.substring(0,status.indexOf('('));
| |
| 393 | ||
| 394 | } | |
| 395 | public void onRepaint(Graphics g) | |
| 396 | {
| |
| 397 | if(game.isLoggedIn()) | |
| 398 | {
| |
| 399 | try{
| |
| 400 | if(startExp==0) | |
| 401 | {
| |
| 402 | startExp = skills.getCurrentExp(skills.getIndex("fletching"));
| |
| 403 | startLevel = skills.getCurrentLevel(skills.getIndex("fletching"));
| |
| 404 | } | |
| 405 | ||
| 406 | lvlsGained = skills.getCurrentLevel(skills.getIndex("fletching")) - startLevel;
| |
| 407 | expGained = skills.getCurrentExp(skills.getIndex("fletching")) - startExp;
| |
| 408 | ||
| 409 | //setting up the time | |
| 410 | long ms = System.currentTimeMillis() - startTime; | |
| 411 | double ms2 = System.currentTimeMillis() - startTimeDbl; | |
| 412 | long hours = ms/3600000; | |
| 413 | ms = ms-(hours*3600000); | |
| 414 | long minutes = ms/60000; | |
| 415 | ms = ms-(minutes*60000); | |
| 416 | long seconds = ms/1000; | |
| 417 | // | | |
| 418 | //Background v transparency! | |
| 419 | g.setColor(new Color(0, 0, 0, 205)); | |
| 420 | g.fillRoundRect(333, 175, 181, 164, 6, 6); //Background | |
| 421 | long expToLvl = skills.getExpToNextLevel(skills.getIndex("fletching"));
| |
| 422 | long time2Lvl = 0; | |
| 423 | long time2LvlHrs = 0; | |
| 424 | long time2LvlMins = 0; | |
| 425 | long time2LvlSec = 0; | |
| 426 | if(ms2!=0&&expGained!=0){
| |
| 427 | time2Lvl = (long)(expToLvl/(expGained/(ms2/3600000))*3600000); | |
| 428 | time2LvlHrs = time2Lvl/3600000; | |
| 429 | time2Lvl -= time2LvlHrs*3600000; | |
| 430 | time2LvlMins = time2Lvl/60000; | |
| 431 | time2Lvl -= time2LvlMins*60000; | |
| 432 | time2LvlSec = time2Lvl/1000; | |
| 433 | } | |
| 434 | //Text Color and Output | |
| 435 | g.setColor(new Color(255,0,0,255)); | |
| 436 | g.setFont(new Font("Comic Sans MS", Font.PLAIN, 12));
| |
| 437 | g.drawString("Conderoga's Stringer "+version,338,192);
| |
| 438 | g.setFont(new Font("Comic Sans MS", Font.PLAIN, 11));
| |
| 439 | g.drawString("Levels Gained: "+lvlsGained,344,207);
| |
| 440 | ||
| 441 | ||
| 442 | if(action.equals("Normal Short - String"))
| |
| 443 | g.drawString("Norm Shorts Strung: "+expGained/5,344,222);
| |
| 444 | else if(action.equals("Normal Long - String"))
| |
| 445 | g.drawString("Norm Longs Strung: "+expGained/10,344,222);
| |
| 446 | else if(action.equals("Oak Short - String"))
| |
| 447 | g.drawString("Oak Shorts Strung: "+(int)((expGained+1)/16.5),344,222);
| |
| 448 | else if(action.equals("Oak Long - String"))
| |
| 449 | g.drawString("Oak Longs Strung: "+expGained/25,344,222);
| |
| 450 | else if(action.equals("Willow Short - String"))
| |
| 451 | g.drawString("Willow Shorts Strung: "+(int)((expGained+1)/33.3),344,222);
| |
| 452 | else if(action.equals("Willow Long - String"))
| |
| 453 | g.drawString("Willow Longs Strung: "+(int)((expGained+1)/41.5),344,222);
| |
| 454 | else if(action.equals("Maple Short - String"))
| |
| 455 | g.drawString("Maple Shorts Strung: "+(expGained/50),344,222);
| |
| 456 | else if(action.equals("Maple Long - String"))
| |
| 457 | g.drawString("Maple Longs Strung: "+(int)((expGained+1)/58.3),344,222);
| |
| 458 | else if(action.equals("Yew Short - String"))
| |
| 459 | g.drawString("Yew Shorts Strung: "+(int)((expGained+1)/67.5),344,222);
| |
| 460 | else if(action.equals("Yew Long - String"))
| |
| 461 | g.drawString("Yew Longs Strung: "+expGained/75,344,222);
| |
| 462 | else if(action.equals("Magic Short - String"))
| |
| 463 | g.drawString("Magic Shorts Strung: "+(int)((expGained+1)/83.3),344,222);
| |
| 464 | else if(action.equals("Magic Long - String"))
| |
| 465 | g.drawString("Magic Longs Strung: "+(int)((expGained+1)/91.5),344,222);
| |
| 466 | ||
| 467 | ||
| 468 | ||
| 469 | ||
| 470 | ||
| 471 | ||
| 472 | //g.drawString("Failsafe: "+failsafe,357,382);
| |
| 473 | g.drawString("Exp Gained: "+expGained,344,237);
| |
| 474 | g.drawString("Time Running: "+hours+":"+minutes+":"+seconds,344, 252);
| |
| 475 | ||
| 476 | //Progress Bar | |
| 477 | g.fillRoundRect(344,256,150,20,8,8); //Bar background | |
| 478 | g.setColor(new Color(0,255,0,255)); //GREEN | |
| 479 | g.fillRoundRect(344,256,(int)(skills.getPercentToNextLevel(skills.getIndex("fletching"))*1.5),20,8,8);
| |
| 480 | g.setColor(new Color(0,0,0,255)); | |
| 481 | g.setColor(new Color(255,255,255,100)); | |
| 482 | g.drawString(skills.getPercentToNextLevel(skills.getIndex("fletching"))+"% to: "+(skills.getCurrentLevel(skills.getIndex("fletching"))+1)+" ("+expToLvl+")",348,271);
| |
| 483 | g.fillRoundRect(345,266,148,10,8,8); | |
| 484 | g.setColor(new Color(0,0,0,255)); | |
| 485 | g.drawString(skills.getPercentToNextLevel(skills.getIndex("fletching"))+"% to: "+(skills.getCurrentLevel(skills.getIndex("fletching"))+1)+" ("+expToLvl+")",347,270);
| |
| 486 | g.setColor(new Color(255,0,0,255)); | |
| 487 | if(ms2!=0) | |
| 488 | g.drawString("Exp/Hr: "+(int)(expGained/(ms2/3600000)),344,289);
| |
| 489 | g.drawString("Status: "+status,344,304);
| |
| 490 | if(ms2!=0) | |
| 491 | g.drawString("Bows/Hr: "+(int)(bowsStrung/(ms2/3600000)),344,319);
| |
| 492 | g.drawString("Est. Time to Lvl: "+time2LvlHrs+":"+time2LvlMins+":"+time2LvlSec,344,334);
| |
| 493 | ||
| 494 | //Mouse Stuff | |
| 495 | Point tempPoint = mouse.getLocation(); | |
| 496 | int tempXCoordinate = (int)tempPoint.getX(); | |
| 497 | int tempYCoordinate = (int)tempPoint.getY(); | |
| 498 | g.setColor(new Color(0,255,0,140)); | |
| 499 | g.drawLine(tempXCoordinate,0,tempXCoordinate,501); | |
| 500 | g.drawLine(0,tempYCoordinate,764,tempYCoordinate); | |
| 501 | }catch(Exception e){};
| |
| 502 | ||
| 503 | } | |
| 504 | } | |
| 505 | public void onFinish() {
| |
| 506 | log("Exp gained: "+expGained);
| |
| 507 | log("Levels gained: "+lvlsGained);
| |
| 508 | log("Thanks for using Conderoga's Fletcher!");
| |
| 509 | } | |
| 510 | public void openURL(final String url) { // Credits ZombieKnight
| |
| 511 | //who gave credits to Dave who gave credits | |
| 512 | // to | |
| 513 | // some guy who made this. | |
| 514 | final String osName = System.getProperty("os.name");
| |
| 515 | try {
| |
| 516 | if (osName.startsWith("Mac OS")) {
| |
| 517 | final Class<?> fileMgr = Class | |
| 518 | .forName("com.apple.eio.FileManager");
| |
| 519 | final Method openURL = fileMgr.getDeclaredMethod("openURL",new Class[]{String.class});
| |
| 520 | openURL.invoke(null, new Object[]{url});
| |
| 521 | } else if (osName.startsWith("Windows")) {
| |
| 522 | Runtime.getRuntime().exec( | |
| 523 | "rundll32 url.dll,FileProtocolHandler " + url); | |
| 524 | } else { // assume Unix or Linux
| |
| 525 | final String[] browsers = {"firefox", "opera", "konqueror",
| |
| 526 | "epiphany", "mozilla", "netscape"}; | |
| 527 | String browser = null; | |
| 528 | for (int count = 0; count < browsers.length && browser == null; count++) {
| |
| 529 | if (Runtime.getRuntime().exec( | |
| 530 | new String[]{"which", browsers[count]})
| |
| 531 | .waitFor() == 0) {
| |
| 532 | browser = browsers[count]; | |
| 533 | } | |
| 534 | } | |
| 535 | if (browser == null) {
| |
| 536 | throw new Exception("Could not find web browser");
| |
| 537 | } else {
| |
| 538 | Runtime.getRuntime().exec(new String[]{browser, url});
| |
| 539 | } | |
| 540 | } | |
| 541 | } catch (final Exception e) {
| |
| 542 | } | |
| 543 | } | |
| 544 | public class CFletchGui extends JFrame {
| |
| 545 | ||
| 546 | private static final long serialVersionUID = 1L; | |
| 547 | public CFletchGui() | |
| 548 | {
| |
| 549 | initComponents(); | |
| 550 | } | |
| 551 | ||
| 552 | private void button2ActionPerformed(ActionEvent e) {
| |
| 553 | guiWait = false; | |
| 554 | guiExit = true; | |
| 555 | dispose(); | |
| 556 | } | |
| 557 | ||
| 558 | private void button1ActionPerformed(ActionEvent e) {
| |
| 559 | action = comboBox1.getSelectedItem().toString(); | |
| 560 | guiExit = false; | |
| 561 | guiWait = false; | |
| 562 | dispose(); | |
| 563 | } | |
| 564 | ||
| 565 | private void initComponents() {
| |
| 566 | //GEN-BEGIN:initComponents | |
| 567 | label1 = new JLabel(); | |
| 568 | label2 = new JLabel(); | |
| 569 | comboBox1 = new JComboBox(); | |
| 570 | label3 = new JLabel(); | |
| 571 | button1 = new JButton(); | |
| 572 | button2 = new JButton(); | |
| 573 | ||
| 574 | //======== this ======== | |
| 575 | setTitle("Conderoga's Speed Stringer");
| |
| 576 | setResizable(false); | |
| 577 | setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); | |
| 578 | Container contentPane = getContentPane(); | |
| 579 | contentPane.setLayout(null); | |
| 580 | ||
| 581 | //---- label1 ---- | |
| 582 | label1.setText("Conderoga's Stringer Settings");
| |
| 583 | label1.setFont(new Font("Comic Sans MS", Font.PLAIN, 16));
| |
| 584 | contentPane.add(label1); | |
| 585 | label1.setBounds(10, -10, 380, 70); | |
| 586 | ||
| 587 | //---- label2 ---- | |
| 588 | label2.setText("Select the action: ");
| |
| 589 | contentPane.add(label2); | |
| 590 | label2.setBounds(new Rectangle(new Point(15, 50), label2.getPreferredSize())); | |
| 591 | ||
| 592 | //---- comboBox1 ---- | |
| 593 | comboBox1.setMaximumRowCount(12); | |
| 594 | comboBox1.setModel(new DefaultComboBoxModel(new String[] {
| |
| 595 | "Normal Short - String", | |
| 596 | "Normal Long - String", | |
| 597 | "Oak Short - String", | |
| 598 | "Oak Long - String", | |
| 599 | "Willow Short - String", | |
| 600 | "Willow Long - String", | |
| 601 | "Maple Short - String", | |
| 602 | "Maple Long - String", | |
| 603 | "Yew Short - String", | |
| 604 | "Yew Long - String", | |
| 605 | "Magic Short - String", | |
| 606 | "Magic Long - String" | |
| 607 | ||
| 608 | ||
| 609 | ||
| 610 | })); | |
| 611 | contentPane.add(comboBox1); | |
| 612 | comboBox1.setBounds(175, 45, 125, 25); | |
| 613 | ||
| 614 | //---- label3 ---- | |
| 615 | label3.setText(version); | |
| 616 | contentPane.add(label3); | |
| 617 | label3.setBounds(15, 80, 124, label3.getPreferredSize().height); | |
| 618 | ||
| 619 | //---- button1 ---- | |
| 620 | button1.setText("Start!");
| |
| 621 | button1.addActionListener(new ActionListener() {
| |
| 622 | public void actionPerformed(ActionEvent e) {
| |
| 623 | button1ActionPerformed(e); | |
| 624 | } | |
| 625 | }); | |
| 626 | contentPane.add(button1); | |
| 627 | button1.setBounds(40, 115, 75, 30); | |
| 628 | ||
| 629 | //---- button2 ---- | |
| 630 | button2.setText("Exit");
| |
| 631 | button2.addActionListener(new ActionListener() {
| |
| 632 | public void actionPerformed(ActionEvent e) {
| |
| 633 | button2ActionPerformed(e); | |
| 634 | } | |
| 635 | }); | |
| 636 | contentPane.add(button2); | |
| 637 | button2.setBounds(200, 115, 75, 30); | |
| 638 | ||
| 639 | { // compute preferred size
| |
| 640 | Dimension preferredSize = new Dimension(); | |
| 641 | for(int i = 0; i < contentPane.getComponentCount(); i++) {
| |
| 642 | Rectangle bounds = contentPane.getComponent(i).getBounds(); | |
| 643 | preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width); | |
| 644 | preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height); | |
| 645 | } | |
| 646 | Insets insets = contentPane.getInsets(); | |
| 647 | preferredSize.width += insets.right; | |
| 648 | preferredSize.height += insets.bottom; | |
| 649 | contentPane.setMinimumSize(preferredSize); | |
| 650 | contentPane.setPreferredSize(preferredSize); | |
| 651 | } | |
| 652 | setSize(325, 190); | |
| 653 | setLocationRelativeTo(getOwner()); | |
| 654 | //GEN-END:initComponents | |
| 655 | } | |
| 656 | ||
| 657 | //GEN-BEGIN:variables | |
| 658 | private JLabel label1; | |
| 659 | private JLabel label2; | |
| 660 | private JComboBox comboBox1; | |
| 661 | private JLabel label3; | |
| 662 | private JButton button1; | |
| 663 | private JButton button2; | |
| 664 | //GEN-END:variables | |
| 665 | } | |
| 666 | ||
| 667 | } |