Guest User

Untitled

a guest
Dec 7th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.13 KB | None | 0 0
  1. package org.WhiteberriesPro;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Point;
  5. import java.awt.event.ActionEvent;
  6. import java.io.FileInputStream;
  7. import java.io.FileOutputStream;
  8. import java.io.IOException;
  9. import java.io.ObjectInputStream;
  10. import java.io.ObjectOutputStream;
  11. import java.util.ArrayList;
  12.  
  13. import javax.swing.GroupLayout;
  14. import javax.swing.JButton;
  15. import javax.swing.JFrame;
  16. import javax.swing.JLabel;
  17. import javax.swing.JTextField;
  18. import javax.swing.LayoutStyle;
  19.  
  20. import org.rsbot.script.Script;
  21. import org.rsbot.script.ScriptManifest;
  22. import org.rsbot.script.util.Filter;
  23. import org.rsbot.script.wrappers.RSGroundItem;
  24. import org.rsbot.script.wrappers.RSItem;
  25. import org.rsbot.script.wrappers.RSNPC;
  26. import org.rsbot.script.wrappers.RSObject;
  27. import org.rsbot.script.wrappers.RSTile;
  28.  
  29.  
  30. @ScriptManifest(authors = {"Daniel987600"}, keywords = {"Quicker Picker Upper"}, name = "DPickUp", description = "Picks up items", version = 1.0)
  31.  
  32. //Is on Top method has been fixed. Fix pickUp method
  33. //Look into serialization to store data (need to make load method)
  34.  
  35. public class DPickUp extends Script {
  36.  
  37. public interface Condition {
  38. public boolean isTrue();
  39. }
  40.  
  41. ArrayList <RSTile> walkToBank = new ArrayList <RSTile>();
  42. ArrayList <RSTile> walkToItems = new ArrayList <RSTile>();
  43. ArrayList <Integer> pickUpIDList = new ArrayList <Integer>();
  44. ArrayList <String> pickUpNameList = new ArrayList <String>();
  45. int [] pickUpIDs;
  46. String [] pickUpNames;
  47. RSTile centerTile;
  48. int i = 0;
  49. int j = 0;
  50. int l = 0;
  51. int k = 0;
  52. boolean recording = false;
  53. boolean GUIStillGoing = true;
  54. boolean stopScript = false;
  55. boolean usingID;
  56. PickingGUI GUI = new PickingGUI();
  57.  
  58. public boolean onStart() {
  59. log (Color.YELLOW, "Using an item&#039;s name to pick up an item is now supported!");
  60. log (Color.YELLOW, "However, if you wish to use names, you must write the name WITHOUT ERRORS");
  61. log (Color.YELLOW, "Capitalization DOES NOT count as an error!");
  62. GUI.setVisible (true);
  63. while (GUIStillGoing) {
  64. while (recording) {
  65. final RSTile dest = recordPath();
  66. waitIf (5000, new Condition () {
  67. public boolean isTrue () {
  68. RSTile Dest = walking.getDestination();
  69. if (Dest != null) {
  70. return (dest.equals(Dest));
  71. }
  72. return (calc.distanceBetween(players.getMyPlayer().getLocation(), dest) > 5);
  73. }
  74. });
  75. }
  76. k = 0;
  77. sleep(500);
  78. }
  79. GUI.setVisible(false);
  80. walkToItems = reversePath (walkToBank);
  81. if (walkToItems.size() == walkToBank.size() && walkToItems.get(walkToItems.size() - 1).equals(walkToBank.get(0)))
  82. log ("walkToItems successfully initialized!");
  83. else
  84. stopScript = true;
  85. log ("You are picking up the following items:");
  86. if (pickUpIDs.length > 0) {
  87. for (int jesus = 0; jesus < pickUpIDs.length; jesus++) {
  88. log ("Item #" +(jesus + 1) +" : (ID) " +pickUpIDs[jesus]);
  89. }
  90. }
  91. if (pickUpNames.length > 0) {
  92. for (int jesus = 0; jesus < pickUpNames.length; jesus++) {
  93. log ("Item #" +(jesus + 1 + pickUpIDs.length) +" : (Name) " +pickUpNames[jesus]);
  94. }
  95. }
  96. centerTile = walkToBank.get(0);
  97. return true;
  98. }
  99.  
  100. private enum State {
  101. WalkToBank, WalkToItems, PickUpItems, Bank, ClimbStairs, DescendStairs
  102. }
  103.  
  104. State getState () {
  105. if (inventory.isFull()) {
  106. RSNPC banker = npcs.getNearest("banker");
  107. if (objects.getNearest(36773, 36774) != null) return State.ClimbStairs;
  108. if (banker != null) return State.Bank;
  109. return State.WalkToBank;
  110. }
  111. if (game.getPlane() != 0) return State.DescendStairs;
  112. if (calc.distanceTo (centerTile) > 19) return State.WalkToItems;
  113. return State.PickUpItems;
  114. }
  115.  
  116. @Override
  117. public int loop() {
  118. if (stopScript)
  119. return -1;
  120. if (walking.getEnergy() > (random(70, 85)) && !walking.isRunEnabled())
  121. walking.setRun(true);
  122. State State = getState();
  123. switch (State) {
  124.  
  125. case WalkToBank:
  126. dropAllExcept();
  127. if (inventory.isFull()) {
  128. step (walkToBank);
  129. }
  130. break;
  131.  
  132. case WalkToItems:
  133. step (walkToItems);
  134. break;
  135.  
  136. case PickUpItems:
  137. if (waitIf (100000, new Condition () {
  138. public boolean isTrue () {
  139. return getNearest() == null;
  140. }
  141. })) pickUpItems();
  142. else step (walkToItems);
  143. break;
  144.  
  145. case Bank:
  146. RSNPC banker = npcs.getNearest("banker");
  147. if (banker != null) {
  148. if (!banker.isOnScreen()) {
  149. step(walkToBank);
  150. camera.turnTo(banker);
  151. if (!banker.isOnScreen())
  152. camera.setPitch(false);
  153. }
  154. if (banker.isOnScreen()) {
  155. banker.interact("Bank");
  156. if (waitIf(1000, new Condition() {
  157. public boolean isTrue() {
  158. return !bank.isOpen();
  159. }
  160. })) {
  161. bank.depositAll();
  162. bank.close();
  163. break;
  164. }
  165. if (bank.open()) {
  166. bank.depositAll();
  167. bank.close();
  168. }
  169. }
  170. }
  171. break;
  172.  
  173. case DescendStairs:
  174. climbDownStairs();
  175. break;
  176.  
  177. case ClimbStairs:
  178. climbUpStairs();
  179. break;
  180.  
  181. }
  182. return 0;
  183. }
  184.  
  185. private void climbUpStairs() {
  186. final int plane = game.getPlane();
  187. RSObject StairMan = objects.getNearest (36773, 36774);
  188. if (StairMan != null) {
  189. if (!StairMan.isOnScreen()) {
  190. step(walkToBank);
  191. camera.turnTo(StairMan);
  192. if (!StairMan.isOnScreen())
  193. camera.setPitch (false);
  194. }
  195. if (StairMan.isOnScreen()) {
  196. StairMan.interact("Climb-up");
  197. waitIf(1000, new Condition() {
  198. public boolean isTrue() {
  199. return game.getPlane() == plane;
  200. }
  201. });
  202. }
  203. return;
  204. } else {
  205. return;
  206. }
  207. }
  208.  
  209. private void climbDownStairs() {
  210. final int plane = game.getPlane();
  211. RSObject StairMan = objects.getNearest (36774, 36775);
  212. if (StairMan != null) {
  213. if (!StairMan.isOnScreen()) {
  214. step(walkToBank);
  215. camera.turnTo(StairMan);
  216. if (!StairMan.isOnScreen())
  217. camera.setPitch (false);
  218. }
  219. if (StairMan.isOnScreen()) {
  220. StairMan.interact("Climb-down");
  221. waitIf(1000, new Condition() {
  222. public boolean isTrue() {
  223. return game.getPlane() == plane;
  224. }
  225. });
  226. }
  227. return;
  228. } else {
  229. return;
  230. }
  231. }
  232.  
  233. private RSTile recordPath() {
  234. if (k == 0) {
  235. walkToBank.add (players.getMyPlayer().getLocation());
  236. k++;
  237. }
  238. RSTile dest = walking.getDestination();
  239. if (dest != null) {
  240. if (!walkToBank.get(walkToBank.size() - 1).equals(dest))
  241. walkToBank.add(dest);
  242. return dest;
  243. }
  244. if (waitIf (5000, new Condition () {
  245. public boolean isTrue () {
  246. return walking.getDestination() == null;
  247. }
  248. })) {
  249. RSTile location = walking.getDestination();
  250. walkToBank.add (location);
  251. return location;
  252. } else {
  253. RSTile playerLocation = players.getMyPlayer().getLocation();
  254. if (!walkToBank.contains(playerLocation))
  255. walkToBank.add(playerLocation);
  256. return playerLocation;
  257. }
  258. }
  259.  
  260. private void pickUpItems() {
  261. final RSGroundItem items = getNearest();
  262. if (items != null) {
  263. final int number = inventory.getCount(true, items.getItem().getID());
  264. RSTile itemSpot = items.getLocation();
  265. if (calc.distanceBetween (itemSpot, centerTile) <= 19) {
  266. if (!items.isOnScreen())
  267. walking.walkTo(itemSpot);
  268. camera.setPitch(true);
  269. camera.turnTo(itemSpot);
  270. if (items.isOnScreen()) {
  271. boolean onTop = isOnTop(items, itemSpot);
  272. while (!mouse.getLocation().equals(calc.tileToScreen(itemSpot)) && items.isOnScreen()) {
  273. mouse.move(calc.tileToScreen(itemSpot));
  274. RSTile dest = walking.getDestination();
  275. if (dest != null) {
  276. if (calc.distanceBetween(dest, itemSpot) > 3) {
  277. mouse.click(true);
  278. }
  279. }
  280. }
  281. if (items.isOnScreen()) {
  282. mouse.click(onTop);
  283. if (!onTop) {
  284. if (menu.doAction("Take", items.getItem().getName()))
  285. waitIf (random (1000, 2000), new Condition () {
  286. public boolean isTrue () {
  287. return number == inventory.getCount(true, items.getItem().getID()) && players.getMyPlayer().isMoving();
  288. }
  289. });
  290. } else
  291. waitIf (random (1000, 2000), new Condition () {
  292. public boolean isTrue () {
  293. return number == inventory.getCount(true, items.getItem().getID()) && players.getMyPlayer().isMoving();
  294. }
  295. });
  296. }
  297. }
  298. } else {
  299. step (walkToItems);
  300. }
  301. }
  302. }
  303.  
  304. private boolean isOnTop (RSGroundItem item, RSTile tile) {
  305. if (item != null) {
  306. RSGroundItem[] itemList = groundItems.getAllAt(tile);
  307. if (itemList.length > 0) {
  308. RSGroundItem items = itemList [itemList.length - 1];
  309. return noNPCAtTile (tile) && items.getItem().getID() == item.getItem().getID();
  310. }
  311. } return false;
  312. }
  313.  
  314. private boolean noNPCAtTile(final RSTile tile) {
  315. RSNPC[] npcList = npcs.getAll(new Filter <RSNPC> () {
  316. public boolean accept(RSNPC npc) {
  317. return npc.getLocation().equals(tile);
  318. }
  319. });
  320. return npcList.length == 0;
  321. }
  322.  
  323. RSGroundItem getNearest () {
  324. return groundItems.getNearest(new Filter <RSGroundItem> () {
  325. public boolean accept(final RSGroundItem item) {
  326. if (item != null) {
  327. final String name = item.getItem().getName();
  328. final int ID = item.getItem().getID();
  329. if (pickUpNames.length > 0) {
  330. for (final String n: pickUpNames) {
  331. if (n.equalsIgnoreCase(name)) {
  332. usingID = false;
  333. return true;
  334. }
  335. }
  336. }
  337. if (pickUpIDs.length > 0) {
  338. for (final int id : pickUpIDs) {
  339. if (id == ID) {
  340. usingID = true;
  341. return true;
  342. }
  343. }
  344. }
  345. }
  346. return false;
  347. }
  348. });
  349. }
  350.  
  351. public boolean dropAllExcept() {
  352. final int startCount = inventory.getCount();
  353. final RSTile startLocation = players.getMyPlayer().getLocation();
  354. boolean found_droppable = true;
  355. while (found_droppable && getCountExcept(false) != 0) {
  356. if (calc.distanceTo(startLocation) > 100) {
  357. break;
  358. }
  359. found_droppable = false;
  360. for (int j = 0; j < 28; j++) {
  361. final int c = j / 7;
  362. final int r = j % 7;
  363. final RSItem curItem = inventory.getItems()[c + r * 4];
  364. if (curItem != null) {
  365. int id = curItem.getID();
  366. if (id != -1) {
  367. boolean isInItems = false;
  368. for (final int i : pickUpIDs) {
  369. if (i == id) {
  370. isInItems = true;
  371. break;
  372. }
  373. }
  374. if (!isInItems) {
  375. for (final String string : pickUpNames) {
  376. if (string.equalsIgnoreCase(curItem.getName())) {
  377. isInItems = true;
  378. break;
  379. }
  380. }
  381. }
  382. if (!isInItems) {
  383. for (int d = 0; d < 3; d++) {
  384. if (inventory.dropItem(c, r)) {
  385. found_droppable = true;
  386. break;
  387. }
  388. sleep(random(100, 400));
  389. }
  390. }
  391. }
  392. }
  393. }
  394. sleep(random(400, 800));
  395. }
  396. return inventory.getCount() < startCount;
  397. }
  398.  
  399. public int getCountExcept(final boolean includeStacks) {
  400. int count = 0;
  401. for (final RSItem i : inventory.getItems()) {
  402. if (i.getID() != -1) {
  403. boolean skip = false;
  404. for (final int id : pickUpIDs) {
  405. if (i.getID() == id) {
  406. skip = true;
  407. break;
  408. }
  409. }
  410. if (!skip) {
  411. for (final String string : pickUpNames) {
  412. if (i.getName().equalsIgnoreCase(string)) {
  413. skip = true;
  414. break;
  415. }
  416. }
  417. }
  418. if (!skip) {
  419. count += includeStacks ? i.getStackSize() : 1;
  420. }
  421. }
  422. }
  423. return count;
  424. }
  425.  
  426. private int step(ArrayList<RSTile> path) {
  427. if (calc.distanceBetween(players.getMyPlayer().getLocation(), path.get(path.size() - 1)) < 2)
  428. return path.size();
  429. RSTile dest = walking.getDestination();
  430. int index = -1;
  431. int shortestDist = 0, dist, shortest = -16;
  432. if (dest != null) {
  433. for (int i = 0; i < path.size(); i++) {
  434. dist = (int) calc.distanceBetween(path.get(i), dest);
  435. if (shortest < 0 || shortestDist > dist) {
  436. shortest = i;
  437. shortestDist = dist;
  438. }
  439. }
  440. }
  441. for (int i = (path.size() - 1); i > -1; i--) {
  442. if (calc.distanceBetween(players.getMyPlayer().getLocation(), path.get(i)) < 17) {
  443. index = i;
  444. break;
  445. }
  446. }
  447. if (index >= 0) {
  448. for (int i = 0; i < 10 && dest != null && (index <= shortest) && players.getMyPlayer().isMoving(); i++) {
  449. if (game.getClientState() != 10 && game.getClientState() != 11) {
  450. i = 0;
  451. }
  452. sleep(100);
  453. }
  454. if (dest == null || (index > shortest) || !players.getMyPlayer().isMoving()) {
  455. walkTile(path.get(index), 0, 0);
  456. sleep(statNumberGenerator(180, 420, 265, 50));
  457. return index;
  458. }
  459. }
  460. if (walking.getDestination() != null && index >= 0) {
  461. if (calc.distanceBetween(walking.getDestination(), path.get(index)) < 3)
  462. return -2;
  463. return -1;
  464. } else if (walking.getDestination() == null) {
  465. if (stepTileInStraightLine(path.get(path.size() - 1))) return -2;
  466. return -1;
  467. } else {
  468. return -2;
  469. }
  470. }
  471.  
  472. private boolean stepTileInStraightLine(RSTile t) {
  473. RSTile PlayerPosition = players.getMyPlayer().getLocation();
  474. double x = t.getX() - PlayerPosition.getX();
  475. double y = t.getY() - PlayerPosition.getY();
  476. double theta = -Math.PI;
  477. theta = Math.atan(y/x);
  478. if (x < 0) theta = theta + Math.PI;
  479. if (theta < 0) theta = theta + 2*Math.PI;
  480. if (theta != -Math.PI) {
  481. Point p = calc.worldToMinimap((PlayerPosition.getX() + 17*Math.cos(theta)), (PlayerPosition.getY() + 17*Math.sin(theta)));
  482. if (!p.equals(new Point (-1, -1))) {
  483. mouse.move(p);
  484. mouse.click(true);
  485. return true;
  486. }
  487. }
  488. return false;
  489. }
  490.  
  491. private boolean waitIf (int threshold, Condition waitIf) {
  492. int millis = threshold / 2;
  493. while (millis > 100) {
  494. millis = millis / 2;
  495. }
  496. for (int i = 0; i < (int) (1 + (threshold / millis)) && waitIf.isTrue(); i++) {
  497. if (!game.isLoggedIn() || i == threshold/millis)
  498. return false;
  499. sleep(millis);
  500. }
  501. return true;
  502. }
  503.  
  504. private boolean walkTile(RSTile t, int x, int y) {
  505. RSTile dest = new RSTile(t.getX() + random(0, x), t.getY()
  506. + random(0, y));
  507. Point p = calc.tileToMinimap(dest);
  508. if (p.x != -1 && p.y != -1) {
  509. mouse.move(p);
  510. Point p2 = calc.tileToMinimap(dest);
  511. if (p2.x != -1 && p2.y != -1) {
  512. mouse.click(p2, true);
  513. return true;
  514. }
  515. }
  516. return false;
  517. }
  518.  
  519. private int statNumberGenerator(int lo, int hi, int mean, int sd) {
  520. java.util.Random r = new java.util.Random();
  521. int rand;
  522. do {
  523. rand = (int) (r.nextGaussian() * sd + mean);
  524. } while (rand < lo || rand >= hi);
  525. return rand;
  526. }
  527.  
  528. ArrayList <RSTile> reversePath (ArrayList <RSTile> path) {
  529. ArrayList <RSTile> backwardsPath = new ArrayList <RSTile>();
  530. for (int i = path.size() - 1; i > -1; i--) {
  531. backwardsPath.add(path.get(i));
  532. }
  533. return backwardsPath;
  534. }
  535.  
  536. public class PickingGUI extends JFrame {
  537. private static final long serialVersionUID = 1L;
  538. public PickingGUI() {
  539. initComponents();
  540. }
  541.  
  542. private void StartButtonActionPerformed(java.awt.event.ActionEvent evt) {
  543. if (walkToBank.size() < 1) log ("You have not yet recorded a path!");
  544. else if (pickUpIDList.size() < 1 && pickUpNameList.size() < 1) log ("You have not yet inputted items to pick up!");
  545. else {
  546. pickUpIDs = new int [j];
  547. for (int h = 0; h < pickUpIDList.size(); h++) {
  548. pickUpIDs[h] = pickUpIDList.get(h);
  549. }
  550.  
  551. pickUpNames = new String [l];
  552. for (int h = 0; h < pickUpNameList.size(); h++) {
  553. pickUpNames[h] = pickUpNameList.get(h);
  554. }
  555.  
  556. GUIStillGoing = false;
  557. }
  558. if (GUIStillGoing) log ("Please finish before you hit the StartButton!");
  559. }
  560.  
  561. private void CancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
  562. stopScript = true;
  563. GUIStillGoing = false;
  564. }
  565.  
  566. private void RecordButtonActionPerformed(java.awt.event.ActionEvent evt) {
  567. i++;
  568. if (i % 2 == 0) {
  569. recording = false;
  570. if (walkToBank.size() < 2) {
  571. jLabel5.setText("There was an error recording. Please record again!");
  572. RecordButton.setText("Click to start recording");
  573. } else {
  574. jLabel5.setText("You have successfully recorded a path!");
  575. RecordButton.setText("Path already recorded.");
  576. }
  577. } else {
  578. recording = true;
  579. jLabel5.setText("You are recording! Please use the Minimap to Walk!");
  580. RecordButton.setText("Recording!");
  581. }
  582. }
  583.  
  584. private void SaveButtonActionPerformed(java.awt.event.ActionEvent evt) {
  585. try {
  586. if (j > 0) {
  587. ObjectOutputStream outIDs = new ObjectOutputStream(new FileOutputStream("DPickUp.IDs"));
  588. pickUpIDs = new int [j];
  589. for (int h = 0; h < pickUpIDList.size(); h++) {
  590. pickUpIDs[h] = pickUpIDList.get(h);
  591. log ("Item Saved #" +(h + 1) +" : (ID) " +pickUpIDs[h]);
  592. }
  593. outIDs.writeObject(pickUpIDs);
  594. outIDs.flush();
  595. outIDs.close();
  596. }
  597. if (l > 0) {
  598. ObjectOutputStream outNames = new ObjectOutputStream(new FileOutputStream("DPickUp.Names"));
  599. pickUpNames = new String [l];
  600. for (int h = 0; h < pickUpNameList.size(); h++) {
  601. pickUpNames[h] = pickUpNameList.get(h);
  602. log ("Item #" +(h + 1 + pickUpIDs.length) +" : (Name) " +pickUpNames[h]);
  603. }
  604. outNames.writeObject(pickUpNames);
  605. outNames.flush();
  606. outNames.close();
  607. }
  608. if (walkToBank.size() > 0) {
  609. ObjectOutputStream outPath = new ObjectOutputStream(new FileOutputStream("DPickUp.Path"));
  610. outPath.writeObject(walkToBank);
  611. outPath.flush();
  612. outPath.close();
  613. ObjectOutputStream outTile = new ObjectOutputStream(new FileOutputStream("DPickUp.Tile"));
  614. outTile.writeObject(centerTile);
  615. outTile.flush();
  616. outTile.close();
  617. log ("You have saved your path to the bank");
  618. }
  619. } catch (IOException e) {
  620. log (Color.RED, "This is embarassing: unable to save your information.");
  621. log (Color.RED, "Please try again and make sure to post on the forums. Sorry!");
  622. e.printStackTrace();
  623. }
  624. }
  625.  
  626. @SuppressWarnings("unchecked")
  627. private void LoadButtonActionPerformed(java.awt.event.ActionEvent evt) {
  628. //TODO: What is a ClassNotFoundException?
  629. try {
  630. try {
  631. ObjectInputStream inIDs = new ObjectInputStream(new FileInputStream("DPickUp.IDs"));
  632. pickUpIDList = (ArrayList <Integer>) inIDs.readObject();
  633. inIDs.close();
  634. j = pickUpIDList.size();
  635. for (int jesus = 0; jesus < j; jesus++) {
  636. log ("Item Loaded #" +(jesus + 1) +" : (ID) " +pickUpIDList.get(jesus));
  637. }
  638. } catch (ClassNotFoundException e) {
  639. log (Color.YELLOW, "No IDs were found");
  640. log (Color.YELLOW, "If you are sure that you saved IDs, please post on the forums. Sorry!");
  641. e.printStackTrace();
  642. }
  643. try {
  644. ObjectInputStream inNames = new ObjectInputStream(new FileInputStream("DPickUp.Names"));
  645. pickUpNameList = (ArrayList<String>) inNames.readObject();
  646. inNames.close();
  647. l = pickUpNameList.size();
  648. for (int jesus = 0; jesus < l; jesus++) {
  649. log ("Item Loaded #" +(jesus + 1 + j) +" : (Name) " +pickUpNameList.get(jesus));
  650. }
  651. } catch (ClassNotFoundException e) {
  652. log (Color.YELLOW, "No Names were found");
  653. log (Color.YELLOW, "If you are sure that you saved Names, please post on the forums. Sorry!");
  654. e.printStackTrace();
  655. }
  656. try {
  657. ObjectInputStream inPath = new ObjectInputStream(new FileInputStream("DPickUp.Path"));
  658. walkToBank = (ArrayList <RSTile>) inPath.readObject();
  659. inPath.close();
  660. ObjectInputStream inTile = new ObjectInputStream(new FileInputStream("DPickUp.Tile"));
  661. centerTile = (RSTile) inTile.readObject();
  662. inTile.close();
  663. } catch (ClassNotFoundException e) {
  664. log (Color.YELLOW, "No Path to Bank was found");
  665. log (Color.YELLOW, "If you are sure that you saved a path to the bank, please post on the forums. Sorry!");
  666. e.printStackTrace();
  667. }
  668. } catch (IOException e) {
  669. log (Color.RED, "Unable to load your information. This error DOES NOT mean that you didn&#039;t save information. Please try again!");
  670. log(Color.RED, "If you have tried multiple times, please make sure to post on the forums. Sorry!");
  671. e.printStackTrace();
  672. }
  673. }
  674.  
  675. private void jButton2ActionPerformed(ActionEvent evt) {
  676. try {
  677. Integer currentID = Integer.parseInt (ItemIDField.getText());
  678. if (!pickUpIDList.contains(currentID)) {
  679. pickUpIDList.add(currentID);
  680. j++;
  681. InformationLabel.setText("The last ID you inputted: " +currentID);
  682. } else
  683. InformationLabel.setText("You already inputted this ID");
  684. } catch (NumberFormatException e) {
  685. log ("You did not enter a number. Shame on you!");
  686. }
  687. }
  688.  
  689. private void jButton3ActionPerformed(ActionEvent evt) {
  690. if (pickUpIDList.size() > 0) {
  691. int size = pickUpIDList.size() - 1;
  692. Integer e = pickUpIDList.get(size);
  693. pickUpIDList.remove(size);
  694. j--;
  695. InformationLabel.setText("You removed the ID: " +e.intValue());
  696. } else InformationLabel.setText ("Please input IDs before you try to remove them.");
  697. }
  698.  
  699. private void jButton4ActionPerformed(ActionEvent evt) {
  700. try {
  701. Integer currentID = Integer.parseInt (ItemNameField.getText());
  702. if (!pickUpIDList.contains(currentID)) {
  703. pickUpIDList.add(currentID);
  704. j++;
  705. InformationLabel.setText("The last Name you inputted: " +currentID);
  706. } else
  707. InformationLabel.setText("You already inputted this Name");
  708. } catch (NumberFormatException e) {
  709. String currentString = ItemNameField.getText();
  710. if (!pickUpNameList.contains(currentString)) {
  711. pickUpNameList.add (currentString);
  712. l++;
  713. InformationLabel.setText("The last Name you inputted: " + currentString);
  714. } else
  715. InformationLabel.setText("You already inputted this name");
  716. }
  717. }
  718.  
  719. private void jButton5ActionPerformed(ActionEvent evt) {
  720. if (pickUpNameList.size() > 0) {
  721. int size = pickUpNameList.size() - 1;
  722. String e = pickUpNameList.get(size);
  723. pickUpNameList.remove(size);
  724. l--;
  725. InformationLabel.setText("You removed the Name: " +e);
  726. } else InformationLabel.setText ("Please input Names before you try to remove them.");
  727. }
  728.  
  729.  
  730. private void initComponents() {
  731.  
  732. InformationLabel = new JLabel();
  733. jLabel1 = new JLabel();
  734. jLabel2 = new JLabel();
  735. jLabel5 = new JLabel();
  736. StartButton = new JButton();
  737. RecordButton = new JButton();
  738. CancelButton = new JButton();
  739. SaveButton = new JButton();
  740. LoadButton = new JButton();
  741. jButton2 = new JButton();
  742. jButton3 = new JButton();
  743. jButton4 = new JButton();
  744. jButton5 = new JButton();
  745. ItemIDField = new JTextField();
  746. ItemNameField = new JTextField();
  747.  
  748. StartButton.setText("Let&#039;s Start!");
  749. StartButton.setName("StartButton");
  750. StartButton.addActionListener(new java.awt.event.ActionListener() {
  751. public void actionPerformed(java.awt.event.ActionEvent evt) {
  752. StartButtonActionPerformed(evt);
  753. }
  754. });
  755.  
  756. CancelButton.setText("Cancel");
  757. CancelButton.setName("CancelButton");
  758. CancelButton.addActionListener(new java.awt.event.ActionListener() {
  759. public void actionPerformed(java.awt.event.ActionEvent evt) {
  760. CancelButtonActionPerformed(evt);
  761. }
  762. });
  763.  
  764. RecordButton.setText("Click to start recording");
  765. RecordButton.setName("RecordButton");
  766. RecordButton.addActionListener(new java.awt.event.ActionListener() {
  767. public void actionPerformed(java.awt.event.ActionEvent evt) {
  768. RecordButtonActionPerformed(evt);
  769. }
  770. });
  771.  
  772. SaveButton.setText("Click to start recording");
  773. SaveButton.setName("SaveButton");
  774. SaveButton.addActionListener(new java.awt.event.ActionListener() {
  775. public void actionPerformed(java.awt.event.ActionEvent evt) {
  776. SaveButtonActionPerformed(evt);
  777. }
  778. });
  779.  
  780. LoadButton.setText("Click to start recording");
  781. LoadButton.setName("LoadButton");
  782. LoadButton.addActionListener(new java.awt.event.ActionListener() {
  783. public void actionPerformed(java.awt.event.ActionEvent evt) {
  784. LoadButtonActionPerformed(evt);
  785. }
  786. });
  787.  
  788. jButton2.setText("Click: Insert ID");
  789. jButton2.setName("jButton2");
  790. jButton2.addActionListener(new java.awt.event.ActionListener() {
  791. public void actionPerformed(java.awt.event.ActionEvent evt) {
  792. jButton2ActionPerformed(evt);
  793. }
  794. });
  795.  
  796. jButton3.setText("Click: Remove last ID");
  797. jButton3.setName("jButton3");
  798. jButton3.addActionListener(new java.awt.event.ActionListener() {
  799. public void actionPerformed(java.awt.event.ActionEvent evt) {
  800. jButton3ActionPerformed(evt);
  801. }
  802. });
  803.  
  804. jButton4.setText("Click: Insert Name");
  805. jButton4.setName("jButton4");
  806. jButton4.addActionListener(new java.awt.event.ActionListener() {
  807. public void actionPerformed(java.awt.event.ActionEvent evt) {
  808. jButton4ActionPerformed(evt);
  809. }
  810. });
  811.  
  812. jButton5.setText("Click: Remove last Name");
  813. jButton5.setName("jButton5");
  814. jButton5.addActionListener(new java.awt.event.ActionListener() {
  815. public void actionPerformed(java.awt.event.ActionEvent evt) {
  816. jButton5ActionPerformed(evt);
  817. }
  818. });
  819.  
  820. ItemIDField.setText("Insert ID of item HERE");
  821. ItemIDField.setName("ItemIDField");
  822.  
  823. ItemNameField.setText("Insert Name of item HERE");
  824. ItemNameField.setName ("ItemNameField");
  825.  
  826. InformationLabel.setText("You have not inputted any IDs yet. You can put in multiple!");
  827. InformationLabel.setName("InformationLabel");
  828.  
  829. jLabel1.setFont(new java.awt.Font("Lucida Grande", 0, 30));
  830. jLabel1.setText("DPickUp");
  831. jLabel1.setName("jLabel1");
  832.  
  833. jLabel2.setFont(new java.awt.Font("Lucida Grande", 0, 22));
  834. jLabel2.setText("Picks Up Stuff for You!");
  835.  
  836. jLabel5.setText("Click button below: record your path from the SPOT to the BANK");
  837. jLabel5.setName("jLabel5");
  838.  
  839. GroupLayout layout = new GroupLayout(getContentPane());
  840. getContentPane().setLayout(layout);
  841. layout.setHorizontalGroup(
  842. layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  843. .addGroup(layout.createSequentialGroup()
  844. .addContainerGap()
  845. .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  846. .addGroup(layout.createSequentialGroup()
  847. .addComponent(InformationLabel, GroupLayout.DEFAULT_SIZE, 425, Short.MAX_VALUE)
  848. .addContainerGap())
  849. .addGroup(layout.createSequentialGroup()
  850. .addGap(24, 24, 24)
  851. .addComponent(jLabel2, GroupLayout.DEFAULT_SIZE, 399, Short.MAX_VALUE)
  852. .addGap(22, 22, 22))
  853. .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  854. .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
  855. .addComponent(jLabel5, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 379, Short.MAX_VALUE)
  856. .addGroup(layout.createSequentialGroup()
  857. .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  858. .addComponent(ItemNameField, GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE)
  859. .addComponent(ItemIDField, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE))
  860. .addGap(18, 18, 18)
  861. .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
  862. .addComponent(jButton3, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  863. .addComponent(jButton2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  864. .addComponent(jButton4, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  865. .addComponent(jButton5, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
  866. .addComponent(CancelButton, GroupLayout.PREFERRED_SIZE, 163, GroupLayout.PREFERRED_SIZE))
  867. .addGap(66, 66, 66))
  868. .addGroup(layout.createSequentialGroup()
  869. .addComponent(jLabel1)
  870. .addGap(47, 47, 47)
  871. .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
  872. .addComponent(SaveButton, GroupLayout.PREFERRED_SIZE, 209, GroupLayout.PREFERRED_SIZE)
  873. .addComponent(LoadButton, GroupLayout.PREFERRED_SIZE, 209, GroupLayout.PREFERRED_SIZE))
  874. .addContainerGap())))
  875. .addGroup(layout.createSequentialGroup()
  876. .addGap(88, 88, 88)
  877. .addComponent(RecordButton, GroupLayout.PREFERRED_SIZE, 206, GroupLayout.PREFERRED_SIZE)
  878. .addContainerGap(171, Short.MAX_VALUE))
  879. .addGroup(layout.createSequentialGroup()
  880. .addContainerGap()
  881. .addComponent(StartButton, GroupLayout.PREFERRED_SIZE, 163, GroupLayout.PREFERRED_SIZE)
  882. .addContainerGap(285, Short.MAX_VALUE))
  883. );
  884. layout.setVerticalGroup(
  885. layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  886. .addGroup(layout.createSequentialGroup()
  887. .addContainerGap()
  888. .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  889. .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
  890. .addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
  891. .addComponent(LoadButton, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE))
  892. .addComponent(SaveButton, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE))
  893. .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  894. .addComponent(jLabel2)
  895. .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
  896. .addComponent(InformationLabel)
  897. .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  898. .addGroup(layout.createSequentialGroup()
  899. .addGap(7, 7, 7)
  900. .addComponent(jButton2, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
  901. .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  902. .addComponent(jButton3, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
  903. .addGap(5, 5, 5)
  904. .addComponent(jButton4, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
  905. .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  906. .addComponent(jButton5, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE))
  907. .addGroup(layout.createSequentialGroup()
  908. .addGap(18, 18, 18)
  909. .addComponent(ItemIDField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
  910. .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  911. .addComponent(ItemNameField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
  912. .addGap(24, 24, 24)
  913. .addComponent(jLabel5)
  914. .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  915. .addComponent(RecordButton)
  916. .addGap(18, 18, 18)
  917. .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
  918. .addComponent(StartButton)
  919. .addComponent(CancelButton))
  920. .addContainerGap())
  921. );
  922. pack();
  923. }
  924.  
  925. private JButton StartButton;
  926. private JButton CancelButton;
  927. private JButton RecordButton;
  928. private JButton SaveButton;
  929. private JButton LoadButton;
  930. private JButton jButton2;
  931. private JButton jButton3;
  932. private JButton jButton4;
  933. private JButton jButton5;
  934. private JTextField ItemIDField;
  935. private JTextField ItemNameField;
  936. private JLabel InformationLabel;
  937. private JLabel jLabel1;
  938. private JLabel jLabel2;
  939. private JLabel jLabel5;
  940. }
  941. }
Add Comment
Please, Sign In to add comment