Guest User

Untitled

a guest
Dec 7th, 2017
81
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 walking.getDestination() != null
  266. playerDest = walking.getDestination();
  267. if (calc.distanceBetween (itemSpot, centerTile) <= 19) {
  268. if (!items.isOnScreen() || calc.distanceBetween(itemSpot, playerDest) > 3)
  269. walking.walkTo(itemSpot);
  270. camera.setPitch(true);
  271. camera.turnTo(itemSpot);
  272. if (items.isOnScreen()) {
  273. boolean onTop = isOnTop(items, itemSpot);
  274. while (!mouse.getLocation().equals(calc.tileToScreen(itemSpot)) && items.isOnScreen())
  275. mouse.move(calc.tileToScreen(itemSpot));
  276. if (items.isOnScreen()) {
  277. mouse.click(onTop);
  278. if (!onTop) {
  279. if (menu.doAction("Take", items.getItem().getName()))
  280. waitIf (random (1000, 2000), new Condition () {
  281. public boolean isTrue () {
  282. return number == inventory.getCount(true, items.getItem().getID()) && players.getMyPlayer().isMoving();
  283. }
  284. });
  285. } else
  286. waitIf (random (1000, 2000), new Condition () {
  287. public boolean isTrue () {
  288. return number == inventory.getCount(true, items.getItem().getID()) && players.getMyPlayer().isMoving();
  289. }
  290. });
  291. }
  292. }
  293. } else {
  294. step (walkToItems);
  295. }
  296. }
  297. }
  298.  
  299. private boolean isOnTop (RSGroundItem item, RSTile tile) {
  300. if (item != null) {
  301. RSGroundItem[] itemList = groundItems.getAllAt(tile);
  302. if (itemList.length > 0) {
  303. RSGroundItem items = itemList [itemList.length - 1];
  304. return noNPCAtTile (tile) && items.getItem().getID() == item.getItem().getID();
  305. }
  306. } return false;
  307. }
  308.  
  309. private boolean noNPCAtTile(final RSTile tile) {
  310. RSNPC[] npcList = npcs.getAll(new Filter <RSNPC> () {
  311. public boolean accept(RSNPC npc) {
  312. return npc.getLocation().equals(tile);
  313. }
  314. });
  315. return npcList.length == 0;
  316. }
  317.  
  318. RSGroundItem getNearest () {
  319. return groundItems.getNearest(new Filter <RSGroundItem> () {
  320. public boolean accept(final RSGroundItem item) {
  321. if (item != null) {
  322. final String name = item.getItem().getName();
  323. final int ID = item.getItem().getID();
  324. if (pickUpNames.length > 0) {
  325. for (final String n: pickUpNames) {
  326. if (n.equalsIgnoreCase(name)) {
  327. usingID = false;
  328. return true;
  329. }
  330. }
  331. }
  332. if (pickUpIDs.length > 0) {
  333. for (final int id : pickUpIDs) {
  334. if (id == ID) {
  335. usingID = true;
  336. return true;
  337. }
  338. }
  339. }
  340. }
  341. return false;
  342. }
  343. });
  344. }
  345.  
  346. public boolean dropAllExcept() {
  347. final int startCount = inventory.getCount();
  348. final RSTile startLocation = players.getMyPlayer().getLocation();
  349. boolean found_droppable = true;
  350. while (found_droppable && getCountExcept(false) != 0) {
  351. if (calc.distanceTo(startLocation) > 100) {
  352. break;
  353. }
  354. found_droppable = false;
  355. for (int j = 0; j < 28; j++) {
  356. final int c = j / 7;
  357. final int r = j % 7;
  358. final RSItem curItem = inventory.getItems()[c + r * 4];
  359. if (curItem != null) {
  360. int id = curItem.getID();
  361. if (id != -1) {
  362. boolean isInItems = false;
  363. for (final int i : pickUpIDs) {
  364. if (i == id) {
  365. isInItems = true;
  366. break;
  367. }
  368. }
  369. if (!isInItems) {
  370. for (final String string : pickUpNames) {
  371. if (string.equalsIgnoreCase(curItem.getName())) {
  372. isInItems = true;
  373. break;
  374. }
  375. }
  376. }
  377. if (!isInItems) {
  378. for (int d = 0; d < 3; d++) {
  379. if (inventory.dropItem(c, r)) {
  380. found_droppable = true;
  381. break;
  382. }
  383. sleep(random(100, 400));
  384. }
  385. }
  386. }
  387. }
  388. }
  389. sleep(random(400, 800));
  390. }
  391. return inventory.getCount() < startCount;
  392. }
  393.  
  394. public int getCountExcept(final boolean includeStacks) {
  395. int count = 0;
  396. for (final RSItem i : inventory.getItems()) {
  397. if (i.getID() != -1) {
  398. boolean skip = false;
  399. for (final int id : pickUpIDs) {
  400. if (i.getID() == id) {
  401. skip = true;
  402. break;
  403. }
  404. }
  405. if (!skip) {
  406. for (final String string : pickUpNames) {
  407. if (i.getName().equalsIgnoreCase(string)) {
  408. skip = true;
  409. break;
  410. }
  411. }
  412. }
  413. if (!skip) {
  414. count += includeStacks ? i.getStackSize() : 1;
  415. }
  416. }
  417. }
  418. return count;
  419. }
  420.  
  421. private int step(ArrayList<RSTile> path) {
  422. if (calc.distanceBetween(players.getMyPlayer().getLocation(), path.get(path.size() - 1)) < 2)
  423. return path.size();
  424. RSTile dest = walking.getDestination();
  425. int index = -1;
  426. int shortestDist = 0, dist, shortest = -16;
  427. if (dest != null) {
  428. for (int i = 0; i < path.size(); i++) {
  429. dist = (int) calc.distanceBetween(path.get(i), dest);
  430. if (shortest < 0 || shortestDist > dist) {
  431. shortest = i;
  432. shortestDist = dist;
  433. }
  434. }
  435. }
  436. for (int i = (path.size() - 1); i > -1; i--) {
  437. if (calc.distanceBetween(players.getMyPlayer().getLocation(), path.get(i)) < 17) {
  438. index = i;
  439. break;
  440. }
  441. }
  442. if (index >= 0) {
  443. for (int i = 0; i < 10 && dest != null && (index <= shortest) && players.getMyPlayer().isMoving(); i++) {
  444. if (game.getClientState() != 10 && game.getClientState() != 11) {
  445. i = 0;
  446. }
  447. sleep(100);
  448. }
  449. if (dest == null || (index > shortest) || !players.getMyPlayer().isMoving()) {
  450. walkTile(path.get(index), 0, 0);
  451. sleep(statNumberGenerator(180, 420, 265, 50));
  452. return index;
  453. }
  454. }
  455. if (walking.getDestination() != null && index >= 0) {
  456. if (calc.distanceBetween(walking.getDestination(), path.get(index)) < 3)
  457. return -2;
  458. return -1;
  459. } else if (walking.getDestination() == null) {
  460. if (stepTileInStraightLine(path.get(path.size() - 1))) return -2;
  461. return -1;
  462. } else {
  463. return -2;
  464. }
  465. }
  466.  
  467. private boolean stepTileInStraightLine(RSTile t) {
  468. RSTile PlayerPosition = players.getMyPlayer().getLocation();
  469. double x = t.getX() - PlayerPosition.getX();
  470. double y = t.getY() - PlayerPosition.getY();
  471. double theta = -Math.PI;
  472. theta = Math.atan(y/x);
  473. if (x < 0) theta = theta + Math.PI;
  474. if (theta < 0) theta = theta + 2*Math.PI;
  475. if (theta != -Math.PI) {
  476. Point p = calc.worldToMinimap((PlayerPosition.getX() + 17*Math.cos(theta)), (PlayerPosition.getY() + 17*Math.sin(theta)));
  477. if (!p.equals(new Point (-1, -1))) {
  478. mouse.move(p);
  479. mouse.click(true);
  480. return true;
  481. }
  482. }
  483. return false;
  484. }
  485.  
  486. private boolean waitIf (int threshold, Condition waitIf) {
  487. int millis = threshold / 2;
  488. while (millis > 100) {
  489. millis = millis / 2;
  490. }
  491. for (int i = 0; i < (int) (1 + (threshold / millis)) && waitIf.isTrue(); i++) {
  492. if (!game.isLoggedIn() || i == threshold/millis)
  493. return false;
  494. sleep(millis);
  495. }
  496. return true;
  497. }
  498.  
  499. private boolean walkTile(RSTile t, int x, int y) {
  500. RSTile dest = new RSTile(t.getX() + random(0, x), t.getY()
  501. + random(0, y));
  502. Point p = calc.tileToMinimap(dest);
  503. if (p.x != -1 && p.y != -1) {
  504. mouse.move(p);
  505. Point p2 = calc.tileToMinimap(dest);
  506. if (p2.x != -1 && p2.y != -1) {
  507. mouse.click(p2, true);
  508. return true;
  509. }
  510. }
  511. return false;
  512. }
  513.  
  514. private int statNumberGenerator(int lo, int hi, int mean, int sd) {
  515. java.util.Random r = new java.util.Random();
  516. int rand;
  517. do {
  518. rand = (int) (r.nextGaussian() * sd + mean);
  519. } while (rand < lo || rand >= hi);
  520. return rand;
  521. }
  522.  
  523. ArrayList <RSTile> reversePath (ArrayList <RSTile> path) {
  524. ArrayList <RSTile> backwardsPath = new ArrayList <RSTile>();
  525. for (int i = path.size() - 1; i > -1; i--) {
  526. backwardsPath.add(path.get(i));
  527. }
  528. return backwardsPath;
  529. }
  530.  
  531. public class PickingGUI extends JFrame {
  532. private static final long serialVersionUID = 1L;
  533. public PickingGUI() {
  534. initComponents();
  535. }
  536.  
  537. private void StartButtonActionPerformed(java.awt.event.ActionEvent evt) {
  538. if (walkToBank.size() < 1) log ("You have not yet recorded a path!");
  539. else if (pickUpIDList.size() < 1 && pickUpNameList.size() < 1) log ("You have not yet inputted items to pick up!");
  540. else {
  541. pickUpIDs = new int [j];
  542. for (int h = 0; h < pickUpIDList.size(); h++) {
  543. pickUpIDs[h] = pickUpIDList.get(h);
  544. }
  545.  
  546. pickUpNames = new String [l];
  547. for (int h = 0; h < pickUpNameList.size(); h++) {
  548. pickUpNames[h] = pickUpNameList.get(h);
  549. }
  550.  
  551. GUIStillGoing = false;
  552. }
  553. if (GUIStillGoing) log ("Please finish before you hit the StartButton!");
  554. }
  555.  
  556. private void CancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
  557. stopScript = true;
  558. GUIStillGoing = false;
  559. }
  560.  
  561. private void RecordButtonActionPerformed(java.awt.event.ActionEvent evt) {
  562. i++;
  563. if (i % 2 == 0) {
  564. recording = false;
  565. if (walkToBank.size() < 2) {
  566. jLabel5.setText("There was an error recording. Please record again!");
  567. RecordButton.setText("Click to start recording");
  568. } else {
  569. jLabel5.setText("You have successfully recorded a path!");
  570. RecordButton.setText("Path already recorded.");
  571. }
  572. } else {
  573. recording = true;
  574. jLabel5.setText("You are recording! Please use the Minimap to Walk!");
  575. RecordButton.setText("Recording!");
  576. }
  577. }
  578.  
  579. private void SaveButtonActionPerformed(java.awt.event.ActionEvent evt) {
  580. try {
  581. if (j > 0) {
  582. ObjectOutputStream outIDs = new ObjectOutputStream(new FileOutputStream("DPickUp.IDs"));
  583. pickUpIDs = new int [j];
  584. for (int h = 0; h < pickUpIDList.size(); h++) {
  585. pickUpIDs[h] = pickUpIDList.get(h);
  586. log ("Item Saved #" +(h + 1) +" : (ID) " +pickUpIDs[h]);
  587. }
  588. outIDs.writeObject(pickUpIDs);
  589. outIDs.flush();
  590. outIDs.close();
  591. }
  592. if (l > 0) {
  593. ObjectOutputStream outNames = new ObjectOutputStream(new FileOutputStream("DPickUp.Names"));
  594. pickUpNames = new String [l];
  595. for (int h = 0; h < pickUpNameList.size(); h++) {
  596. pickUpNames[h] = pickUpNameList.get(h);
  597. log ("Item #" +(h + 1 + pickUpIDs.length) +" : (Name) " +pickUpNames[h]);
  598. }
  599. outNames.writeObject(pickUpNames);
  600. outNames.flush();
  601. outNames.close();
  602. }
  603. if (walkToBank.size() > 0) {
  604. ObjectOutputStream outPath = new ObjectOutputStream(new FileOutputStream("DPickUp.Path"));
  605. outPath.writeObject(walkToBank);
  606. outPath.flush();
  607. outPath.close();
  608. ObjectOutputStream outTile = new ObjectOutputStream(new FileOutputStream("DPickUp.Tile"));
  609. outTile.writeObject(centerTile);
  610. outTile.flush();
  611. outTile.close();
  612. log ("You have saved your path to the bank");
  613. }
  614. } catch (IOException e) {
  615. log (Color.RED, "This is embarassing: unable to save your information.");
  616. log (Color.RED, "Please try again and make sure to post on the forums. Sorry!");
  617. e.printStackTrace();
  618. }
  619. }
  620.  
  621. @SuppressWarnings("unchecked")
  622. private void LoadButtonActionPerformed(java.awt.event.ActionEvent evt) {
  623. //TODO: What is a ClassNotFoundException?
  624. try {
  625. try {
  626. ObjectInputStream inIDs = new ObjectInputStream(new FileInputStream("DPickUp.IDs"));
  627. pickUpIDList = (ArrayList <Integer>) inIDs.readObject();
  628. inIDs.close();
  629. j = pickUpIDList.size();
  630. for (int jesus = 0; jesus < j; jesus++) {
  631. log ("Item Loaded #" +(jesus + 1) +" : (ID) " +pickUpIDList.get(jesus));
  632. }
  633. } catch (ClassNotFoundException e) {
  634. log (Color.YELLOW, "No IDs were found");
  635. log (Color.YELLOW, "If you are sure that you saved IDs, please post on the forums. Sorry!");
  636. e.printStackTrace();
  637. }
  638. try {
  639. ObjectInputStream inNames = new ObjectInputStream(new FileInputStream("DPickUp.Names"));
  640. pickUpNameList = (ArrayList<String>) inNames.readObject();
  641. inNames.close();
  642. l = pickUpNameList.size();
  643. for (int jesus = 0; jesus < l; jesus++) {
  644. log ("Item Loaded #" +(jesus + 1 + j) +" : (Name) " +pickUpNameList.get(jesus));
  645. }
  646. } catch (ClassNotFoundException e) {
  647. log (Color.YELLOW, "No Names were found");
  648. log (Color.YELLOW, "If you are sure that you saved Names, please post on the forums. Sorry!");
  649. e.printStackTrace();
  650. }
  651. try {
  652. ObjectInputStream inPath = new ObjectInputStream(new FileInputStream("DPickUp.Path"));
  653. walkToBank = (ArrayList <RSTile>) inPath.readObject();
  654. inPath.close();
  655. ObjectInputStream inTile = new ObjectInputStream(new FileInputStream("DPickUp.Tile"));
  656. centerTile = (RSTile) inTile.readObject();
  657. inTile.close();
  658. } catch (ClassNotFoundException e) {
  659. log (Color.YELLOW, "No Path to Bank was found");
  660. log (Color.YELLOW, "If you are sure that you saved a path to the bank, please post on the forums. Sorry!");
  661. e.printStackTrace();
  662. }
  663. } catch (IOException e) {
  664. log (Color.RED, "Unable to load your information. This error DOES NOT mean that you didn&#039;t save information. Please try again!");
  665. log(Color.RED, "If you have tried multiple times, please make sure to post on the forums. Sorry!");
  666. e.printStackTrace();
  667. }
  668. }
  669.  
  670. private void jButton2ActionPerformed(ActionEvent evt) {
  671. try {
  672. Integer currentID = Integer.parseInt (ItemIDField.getText());
  673. if (!pickUpIDList.contains(currentID)) {
  674. pickUpIDList.add(currentID);
  675. j++;
  676. InformationLabel.setText("The last ID you inputted: " +currentID);
  677. } else
  678. InformationLabel.setText("You already inputted this ID");
  679. } catch (NumberFormatException e) {
  680. log ("You did not enter a number. Shame on you!");
  681. }
  682. }
  683.  
  684. private void jButton3ActionPerformed(ActionEvent evt) {
  685. if (pickUpIDList.size() > 0) {
  686. int size = pickUpIDList.size() - 1;
  687. Integer e = pickUpIDList.get(size);
  688. pickUpIDList.remove(size);
  689. j--;
  690. InformationLabel.setText("You removed the ID: " +e.intValue());
  691. } else InformationLabel.setText ("Please input IDs before you try to remove them.");
  692. }
  693.  
  694. private void jButton4ActionPerformed(ActionEvent evt) {
  695. try {
  696. Integer currentID = Integer.parseInt (ItemNameField.getText());
  697. if (!pickUpIDList.contains(currentID)) {
  698. pickUpIDList.add(currentID);
  699. j++;
  700. InformationLabel.setText("The last Name you inputted: " +currentID);
  701. } else
  702. InformationLabel.setText("You already inputted this Name");
  703. } catch (NumberFormatException e) {
  704. String currentString = ItemNameField.getText();
  705. if (!pickUpNameList.contains(currentString)) {
  706. pickUpNameList.add (currentString);
  707. l++;
  708. InformationLabel.setText("The last Name you inputted: " + currentString);
  709. } else
  710. InformationLabel.setText("You already inputted this name");
  711. }
  712. }
  713.  
  714. private void jButton5ActionPerformed(ActionEvent evt) {
  715. if (pickUpNameList.size() > 0) {
  716. int size = pickUpNameList.size() - 1;
  717. String e = pickUpNameList.get(size);
  718. pickUpNameList.remove(size);
  719. l--;
  720. InformationLabel.setText("You removed the Name: " +e);
  721. } else InformationLabel.setText ("Please input Names before you try to remove them.");
  722. }
  723.  
  724.  
  725. private void initComponents() {
  726.  
  727. InformationLabel = new JLabel();
  728. jLabel1 = new JLabel();
  729. jLabel2 = new JLabel();
  730. jLabel5 = new JLabel();
  731. StartButton = new JButton();
  732. RecordButton = new JButton();
  733. CancelButton = new JButton();
  734. SaveButton = new JButton();
  735. LoadButton = new JButton();
  736. jButton2 = new JButton();
  737. jButton3 = new JButton();
  738. jButton4 = new JButton();
  739. jButton5 = new JButton();
  740. ItemIDField = new JTextField();
  741. ItemNameField = new JTextField();
  742.  
  743. StartButton.setText("Let&#039;s Start!");
  744. StartButton.setName("StartButton");
  745. StartButton.addActionListener(new java.awt.event.ActionListener() {
  746. public void actionPerformed(java.awt.event.ActionEvent evt) {
  747. StartButtonActionPerformed(evt);
  748. }
  749. });
  750.  
  751. CancelButton.setText("Cancel");
  752. CancelButton.setName("CancelButton");
  753. CancelButton.addActionListener(new java.awt.event.ActionListener() {
  754. public void actionPerformed(java.awt.event.ActionEvent evt) {
  755. CancelButtonActionPerformed(evt);
  756. }
  757. });
  758.  
  759. RecordButton.setText("Click to start recording");
  760. RecordButton.setName("RecordButton");
  761. RecordButton.addActionListener(new java.awt.event.ActionListener() {
  762. public void actionPerformed(java.awt.event.ActionEvent evt) {
  763. RecordButtonActionPerformed(evt);
  764. }
  765. });
  766.  
  767. SaveButton.setText("Click to start recording");
  768. SaveButton.setName("SaveButton");
  769. SaveButton.addActionListener(new java.awt.event.ActionListener() {
  770. public void actionPerformed(java.awt.event.ActionEvent evt) {
  771. SaveButtonActionPerformed(evt);
  772. }
  773. });
  774.  
  775. LoadButton.setText("Click to start recording");
  776. LoadButton.setName("LoadButton");
  777. LoadButton.addActionListener(new java.awt.event.ActionListener() {
  778. public void actionPerformed(java.awt.event.ActionEvent evt) {
  779. LoadButtonActionPerformed(evt);
  780. }
  781. });
  782.  
  783. jButton2.setText("Click: Insert ID");
  784. jButton2.setName("jButton2");
  785. jButton2.addActionListener(new java.awt.event.ActionListener() {
  786. public void actionPerformed(java.awt.event.ActionEvent evt) {
  787. jButton2ActionPerformed(evt);
  788. }
  789. });
  790.  
  791. jButton3.setText("Click: Remove last ID");
  792. jButton3.setName("jButton3");
  793. jButton3.addActionListener(new java.awt.event.ActionListener() {
  794. public void actionPerformed(java.awt.event.ActionEvent evt) {
  795. jButton3ActionPerformed(evt);
  796. }
  797. });
  798.  
  799. jButton4.setText("Click: Insert Name");
  800. jButton4.setName("jButton4");
  801. jButton4.addActionListener(new java.awt.event.ActionListener() {
  802. public void actionPerformed(java.awt.event.ActionEvent evt) {
  803. jButton4ActionPerformed(evt);
  804. }
  805. });
  806.  
  807. jButton5.setText("Click: Remove last Name");
  808. jButton5.setName("jButton5");
  809. jButton5.addActionListener(new java.awt.event.ActionListener() {
  810. public void actionPerformed(java.awt.event.ActionEvent evt) {
  811. jButton5ActionPerformed(evt);
  812. }
  813. });
  814.  
  815. ItemIDField.setText("Insert ID of item HERE");
  816. ItemIDField.setName("ItemIDField");
  817.  
  818. ItemNameField.setText("Insert Name of item HERE");
  819. ItemNameField.setName ("ItemNameField");
  820.  
  821. InformationLabel.setText("You have not inputted any IDs yet. You can put in multiple!");
  822. InformationLabel.setName("InformationLabel");
  823.  
  824. jLabel1.setFont(new java.awt.Font("Lucida Grande", 0, 30));
  825. jLabel1.setText("DPickUp");
  826. jLabel1.setName("jLabel1");
  827.  
  828. jLabel2.setFont(new java.awt.Font("Lucida Grande", 0, 22));
  829. jLabel2.setText("Picks Up Stuff for You!");
  830.  
  831. jLabel5.setText("Click button below: record your path from the SPOT to the BANK");
  832. jLabel5.setName("jLabel5");
  833.  
  834. GroupLayout layout = new GroupLayout(getContentPane());
  835. getContentPane().setLayout(layout);
  836. layout.setHorizontalGroup(
  837. layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  838. .addGroup(layout.createSequentialGroup()
  839. .addContainerGap()
  840. .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  841. .addGroup(layout.createSequentialGroup()
  842. .addComponent(InformationLabel, GroupLayout.DEFAULT_SIZE, 425, Short.MAX_VALUE)
  843. .addContainerGap())
  844. .addGroup(layout.createSequentialGroup()
  845. .addGap(24, 24, 24)
  846. .addComponent(jLabel2, GroupLayout.DEFAULT_SIZE, 399, Short.MAX_VALUE)
  847. .addGap(22, 22, 22))
  848. .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  849. .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
  850. .addComponent(jLabel5, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 379, Short.MAX_VALUE)
  851. .addGroup(layout.createSequentialGroup()
  852. .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  853. .addComponent(ItemNameField, GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE)
  854. .addComponent(ItemIDField, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE))
  855. .addGap(18, 18, 18)
  856. .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
  857. .addComponent(jButton3, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  858. .addComponent(jButton2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  859. .addComponent(jButton4, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  860. .addComponent(jButton5, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
  861. .addComponent(CancelButton, GroupLayout.PREFERRED_SIZE, 163, GroupLayout.PREFERRED_SIZE))
  862. .addGap(66, 66, 66))
  863. .addGroup(layout.createSequentialGroup()
  864. .addComponent(jLabel1)
  865. .addGap(47, 47, 47)
  866. .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
  867. .addComponent(SaveButton, GroupLayout.PREFERRED_SIZE, 209, GroupLayout.PREFERRED_SIZE)
  868. .addComponent(LoadButton, GroupLayout.PREFERRED_SIZE, 209, GroupLayout.PREFERRED_SIZE))
  869. .addContainerGap())))
  870. .addGroup(layout.createSequentialGroup()
  871. .addGap(88, 88, 88)
  872. .addComponent(RecordButton, GroupLayout.PREFERRED_SIZE, 206, GroupLayout.PREFERRED_SIZE)
  873. .addContainerGap(171, Short.MAX_VALUE))
  874. .addGroup(layout.createSequentialGroup()
  875. .addContainerGap()
  876. .addComponent(StartButton, GroupLayout.PREFERRED_SIZE, 163, GroupLayout.PREFERRED_SIZE)
  877. .addContainerGap(285, Short.MAX_VALUE))
  878. );
  879. layout.setVerticalGroup(
  880. layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  881. .addGroup(layout.createSequentialGroup()
  882. .addContainerGap()
  883. .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  884. .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
  885. .addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
  886. .addComponent(LoadButton, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE))
  887. .addComponent(SaveButton, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE))
  888. .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  889. .addComponent(jLabel2)
  890. .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
  891. .addComponent(InformationLabel)
  892. .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  893. .addGroup(layout.createSequentialGroup()
  894. .addGap(7, 7, 7)
  895. .addComponent(jButton2, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
  896. .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  897. .addComponent(jButton3, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
  898. .addGap(5, 5, 5)
  899. .addComponent(jButton4, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
  900. .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  901. .addComponent(jButton5, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE))
  902. .addGroup(layout.createSequentialGroup()
  903. .addGap(18, 18, 18)
  904. .addComponent(ItemIDField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
  905. .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  906. .addComponent(ItemNameField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
  907. .addGap(24, 24, 24)
  908. .addComponent(jLabel5)
  909. .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  910. .addComponent(RecordButton)
  911. .addGap(18, 18, 18)
  912. .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
  913. .addComponent(StartButton)
  914. .addComponent(CancelButton))
  915. .addContainerGap())
  916. );
  917. pack();
  918. }
  919.  
  920. private JButton StartButton;
  921. private JButton CancelButton;
  922. private JButton RecordButton;
  923. private JButton SaveButton;
  924. private JButton LoadButton;
  925. private JButton jButton2;
  926. private JButton jButton3;
  927. private JButton jButton4;
  928. private JButton jButton5;
  929. private JTextField ItemIDField;
  930. private JTextField ItemNameField;
  931. private JLabel InformationLabel;
  932. private JLabel jLabel1;
  933. private JLabel jLabel2;
  934. private JLabel jLabel5;
  935. }
  936. }
Add Comment
Please, Sign In to add comment