Robert_G

GuildFisher

Feb 12th, 2012
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.94 KB | None | 0 0
  1. //This script is the sole property of Robert G
  2. //Anyone found re-distributing it may face legal consequences!
  3.  
  4. import java.awt.BasicStroke;
  5. import java.awt.BorderLayout;
  6. import java.awt.Color;
  7. import java.awt.Container;
  8. import java.awt.Font;
  9. import java.awt.Graphics;
  10. import java.awt.Graphics2D;
  11. import java.awt.GridBagConstraints;
  12. import java.awt.GridBagLayout;
  13. import java.awt.Image;
  14. import java.awt.Insets;
  15. import java.awt.Point;
  16. import java.awt.Rectangle;
  17. import java.awt.RenderingHints;
  18. import java.awt.event.ActionEvent;
  19. import java.awt.event.ActionListener;
  20. import java.awt.event.MouseEvent;
  21. import java.awt.event.MouseListener;
  22. import java.io.BufferedReader;
  23. import java.io.IOException;
  24. import java.io.InputStreamReader;
  25. import java.lang.reflect.InvocationTargetException;
  26. import java.net.MalformedURLException;
  27. import java.net.URL;
  28. import java.text.NumberFormat;
  29. import javax.imageio.ImageIO;
  30. import javax.swing.DefaultComboBoxModel;
  31. import javax.swing.GroupLayout;
  32. import javax.swing.JButton;
  33. import javax.swing.JCheckBox;
  34. import javax.swing.JComboBox;
  35. import javax.swing.JFrame;
  36. import javax.swing.JLabel;
  37. import javax.swing.JPanel;
  38. import javax.swing.LayoutStyle;
  39. import javax.swing.SwingUtilities;
  40. import javax.swing.border.EmptyBorder;
  41.  
  42. import com.rarebot.event.events.MessageEvent;
  43. import com.rarebot.event.listeners.MessageListener;
  44. import com.rarebot.event.listeners.PaintListener;
  45. import com.rarebot.script.Script;
  46. import com.rarebot.script.ScriptManifest;
  47. import com.rarebot.script.methods.Skills;
  48. import com.rarebot.script.methods.Game.Tab;
  49. import com.rarebot.script.util.Filter;
  50. import com.rarebot.script.util.Timer;
  51. import com.rarebot.script.wrappers.RSComponent;
  52. import com.rarebot.script.wrappers.RSNPC;
  53. import com.rarebot.script.wrappers.RSObject;
  54. import com.rarebot.script.wrappers.RSTile;
  55.  
  56. @ScriptManifest(authors = { "Robert G" }, name = "GuildFisher", version = 1.3)
  57. public class GuildFisher extends Script implements MessageListener, PaintListener, MouseListener {
  58.  
  59. private static final int bankBooth = 49018;
  60. private static int spotID;
  61. private static final int[] FISHING_URN = { 20334, 20335, 20336 };
  62. private static final int[] STRONG_URN = { 20340, 20341, 20342 };
  63. private static final int[] DECORATED_URN = { 20346, 20347, 20348 };
  64. private static int[] urnID = null;
  65. private static boolean useUrns;
  66. private static RSTile spotTile;
  67. private static final RSTile bankTile = new RSTile(2586, 3422);
  68. private static String catchOption;
  69. private static boolean powerFishing;
  70. private static boolean start = false;
  71. private static long startTime, runTime, timeTNL;
  72. private static int expGained, startExp, startLVL, gainedLVL, currentLVL, TNL, expPH, fish = 0;
  73. private static String status = "Loading...";
  74. private static final Rectangle close = new Rectangle(6, 344, 506, 131);
  75. private static boolean hide;
  76. private static final NumberFormat nf = NumberFormat.getInstance();
  77. private static GuildFisherGUI g;
  78. private static final String versionUrl = "http://pastebin.com/raw.php?i=cWteFCiU";
  79. ScriptManifest props = getClass().getAnnotation(ScriptManifest.class);
  80.  
  81. private boolean checkVersion(double currentVersion, double latestVersion) {
  82. return (currentVersion >= latestVersion);
  83. }
  84.  
  85. private double getCurrentVersion(String webUrl, String search) {
  86. try {
  87. URL url = new URL(webUrl);
  88. BufferedReader x = new BufferedReader(new InputStreamReader(
  89. url.openStream()));
  90. String inputLine;
  91. while ((inputLine = x.readLine()) != null) {
  92. if (inputLine.contains(search)) {
  93. return Double.parseDouble(x.readLine());
  94. }
  95. }
  96. x.close();
  97. } catch (MalformedURLException e) {
  98. e.printStackTrace();
  99. } catch (IOException e) {
  100. e.printStackTrace();
  101. }
  102. return -1D;
  103. }
  104.  
  105. private boolean checkForUrns() {
  106. if (inventory.containsOneOf(FISHING_URN)) {
  107. log("Fishing urn detected, urn support enabled.");
  108. urnID = new int[3];
  109. urnID = FISHING_URN;
  110. return useUrns = true;
  111. } else if (inventory.containsOneOf(STRONG_URN)) {
  112. log("Strong fishing urn detected, urn support enabled.");
  113. urnID = new int[3];
  114. urnID = STRONG_URN;
  115. return useUrns = true;
  116. } else if (inventory.containsOneOf(DECORATED_URN)) {
  117. log("Decorated fishing urn detected, urn support enabled.");
  118. urnID = new int[3];
  119. urnID = DECORATED_URN;
  120. return useUrns = true;
  121. } else {
  122. return useUrns = false;
  123. }
  124. }
  125.  
  126. public class imageLoader extends Thread {
  127.  
  128. private imageLoader() {
  129. Thread t = new Thread(this);
  130. t.start();
  131. }
  132.  
  133. @Override
  134. public void run() {
  135. log("Loading images....");
  136. img1 = getImage("http://desmond.imageshack.us/Himg23/scaled.php?server=23&filename=cooltext643592515.png&res=medium");
  137. img2 = getImage("http://img834.imageshack.us/img834/9746/thfishingcapet.png");
  138. img3 = getImage("http://img525.imageshack.us/img525/6704/cooltext643600500.png");
  139. log("Finished loading images.");
  140. }
  141.  
  142. }
  143.  
  144. @Override
  145. public boolean onStart() {
  146. log("Welcome to GuildFisher by Robert G");
  147. log("Checking script version");
  148. if (checkVersion(props.version(), getCurrentVersion(versionUrl, props.name()))) {
  149. log("You have the latest version, starting up.");
  150. } else {
  151. log.severe("New version available, please update.");
  152. return false;
  153. }
  154. try {
  155. SwingUtilities.invokeAndWait(new Runnable() {
  156. @Override
  157. public void run() {
  158. g = new GuildFisherGUI();
  159. }
  160. });
  161. } catch (InterruptedException e) {
  162. e.printStackTrace();
  163. } catch (InvocationTargetException e) {
  164. e.printStackTrace();
  165. }
  166. while (g.isVisible()) {
  167. sleep(200);
  168. }
  169. if (start) {
  170. setValues();
  171. checkForUrns();
  172. new imageLoader();
  173. }
  174. return start;
  175. }
  176.  
  177. private void setValues() {
  178. startExp = skills.getCurrentExp(Skills.FISHING);
  179. startLVL = skills.getCurrentLevel(Skills.FISHING);
  180. startTime = System.currentTimeMillis();
  181. }
  182.  
  183. private RSNPC getSpot() {
  184. return npcs.getNearest(new Filter<RSNPC>() {
  185. @Override
  186. public boolean accept(RSNPC npc) {
  187. return npc.getID() == spotID;
  188. }
  189. });
  190. }
  191.  
  192. private boolean atSpot() {
  193. return getSpot() != null;
  194. }
  195.  
  196. public class camera extends Thread {
  197.  
  198. private RSNPC npc;
  199.  
  200. private camera(RSNPC npc) {
  201. this.npc = npc;
  202. Thread t = new Thread(this);
  203. if (!t.isAlive()) {
  204. t.start();
  205. }
  206.  
  207. }
  208.  
  209. @Override
  210. public void run() {
  211. camera.turnTo(npc);
  212. camera.setPitch(true);
  213. }
  214.  
  215. }
  216.  
  217. private int missClick = 0;
  218.  
  219. private boolean fish() {
  220. final RSNPC spot = getSpot();
  221. if (spot != null) {
  222. if (!spot.isOnScreen()) {
  223. new camera(spot);
  224. return walking.walkTileMM(spot.getLocation());
  225. } else {
  226. if (missClick == random(5, 10)) {
  227. missClick = 0;
  228. mouse.hop(spot.getPoint());
  229. mouse.click(false);
  230. sleep(600, 800);
  231. mouse.moveSlightly();
  232. } else {
  233. missClick++;
  234. mouse.hop(spot.getPoint());
  235. return spot.interact(catchOption);
  236. }
  237. }
  238. }
  239. return false;
  240. }
  241.  
  242. private void antiban() {
  243. int b = random(0, 9);
  244. switch (b) {
  245. case 1:
  246. if (random(0, 60) == 1) {
  247. status = "Antiban: Moving mouse.";
  248. mouse.moveSlightly();
  249. sleep(2000, 6000);
  250. mouse.moveRandomly(1500, 1600);
  251. }
  252. break;
  253. case 2:
  254. if (random(0, 73) == 2) {
  255. status = "Antiban: Setting camera.";
  256. camera.setAngle(random(30, 130));
  257. sleep(400, 800);
  258. }
  259. break;
  260. case 3:
  261. if (random(0, 80) == 3) {
  262. status = "Antiban: Setting camera.";
  263. camera.setAngle(random(150, 270));
  264. sleep(1200, 1500);
  265. }
  266. break;
  267. case 4:
  268. if (random(0, 100) == 4) {
  269. status = "Antiban: Checking xp.";
  270. game.openTab(Tab.STATS);
  271. if (skills.doHover(Skills.INTERFACE_FISHING)) {
  272. sleep(2100, 3400);
  273. }
  274. }
  275. break;
  276. case 5:
  277. if (random(0, 100) == 5) {
  278. status = "Antiban: Opening random tab.";
  279. if (game.openTab(game.getRandomTab())) {
  280. sleep(3000, 3400);
  281. }
  282. }
  283. break;
  284. case 6:
  285. if (random(0, 70) == 6) {
  286. status = "Antiban: Miss-clicking mouse.";
  287. mouse.click(false);
  288. sleep(1400, 1800);
  289. mouse.moveRandomly(150, 350);
  290. sleep(1500, 1600);
  291. }
  292. break;
  293. case 7:
  294. if (random(0, 50) == 7) {
  295. status = "Antiban: AFK.";
  296. mouse.moveOffScreen();
  297. sleep(2000, 14000);
  298. }
  299. break;
  300. case 8:
  301. if (random(0, 80) == 10) {
  302. status = "Antiban: Rotate screen.";
  303. camera.setCompass(randomChar());
  304. sleep(2000, 2500);
  305. }
  306. break;
  307. case 9:
  308. if (random(0, 36) == 10 && useUrns) {
  309. if (!needUrn()) {
  310. final RSComponent urn = inventory.getItem(urnID).getComponent();
  311. if (urn != null) {
  312. mouse.move(urn.getCenter(), 3, 3);
  313. urn.interact("Check");
  314. sleep(1000, 1200);
  315. }
  316. }
  317. }
  318. break;
  319. }
  320. }
  321.  
  322. private char randomChar() {
  323. int b = random(0, 4);
  324. return b == 1 ? 'n' : b == 2 ? 'e' : b == 3 ? 'w' : 's';
  325. }
  326.  
  327. private boolean open() {
  328. final RSObject booth = objects.getNearest(bankBooth);
  329. if (booth != null) {
  330. if (booth.isOnScreen()) {
  331. camera.turnTo(booth);
  332. return booth.interact("Bank");
  333. } else {
  334. camera.turnTo(booth);
  335. return walking.walkTileMM(booth.getLocation(), 2, 2);
  336. }
  337. }
  338. return false;
  339. }
  340.  
  341. private boolean urnCheck() {
  342. return useUrns && inventory.contains(urnID[2]);
  343. }
  344.  
  345. private boolean needUrn() {
  346. return useUrns && !inventory.containsOneOf(urnID);
  347. }
  348.  
  349. private boolean teleportUrn() {
  350. final RSComponent f = inventory.getItem(urnID[2]).getComponent();
  351. mouse.move(f.getCenter(), 3, 3);
  352. if (f != null) {
  353. if (f.interact("Teleport")) {
  354. waitFor(1500, getInt().isValid());
  355. }
  356. }
  357. if (getInt().isValid()) {
  358. if (getInt().doClick()) {
  359. return true;
  360. }
  361. }
  362. return false;
  363. }
  364.  
  365. private RSComponent getInt() {
  366. return interfaces.getComponent(905, 14);
  367. }
  368.  
  369. private void waitFor(long time, boolean stop) {
  370. final long start = System.currentTimeMillis();
  371. while (System.currentTimeMillis() - start < time) {
  372. sleep(50);
  373. if (stop)break;
  374. }
  375. }
  376.  
  377. @Override
  378. public int loop() {
  379. switch (getState()) {
  380. case SLEEP:
  381. status = "Waiting for client.";
  382. return random(1200, 1500);
  383. case ANTIBAN:
  384. status = "Antiban.";
  385. antiban();
  386. break;
  387. case WALK_SPOT:
  388. if (walking.walkTileMM(spotTile, 2, 2)) {
  389. return random(2000, 2100);
  390. }
  391. break;
  392. case TELEPORT_URN:
  393. status = "Teleporting urn.";
  394. if (teleportUrn()) {
  395. return random(1000, 1200);
  396. }
  397. break;
  398. case FISH:
  399. status = "Interacting with fishing spot.";
  400. if (fish()) {
  401. return random(1200, 1400);
  402. }
  403. break;
  404. case FISHING:
  405. status = "Catching fish.";
  406. return random(1000, 15000);
  407. case DROP:
  408. if (inventory.dropAll(1)) {
  409. return random(200, 300);
  410. }
  411. break;
  412. case WALK_BANK:
  413. status = "Walking to bank.";
  414. if (walking.walkTileMM(bankTile, 2 ,2)) {
  415. return random(2000, 2100);
  416. }
  417. break;
  418. case BANK:
  419. if (!bank.isOpen()) {
  420. status = "Opening bank.";
  421. if (open()) {
  422. return random(1800, 2000);
  423. }
  424. } else {
  425. status = "Depositing fish.";
  426. if (!useUrns) {
  427. bank.depositAll();
  428. } else {
  429. if (bank.depositAllExcept(urnID[0], urnID[1], urnID[2])) {
  430. sleep(500, 600);
  431. }
  432. }
  433. if (useUrns && needUrn()) {
  434. if (bank.getCount(urnID) > 0) {
  435. status = "Withdrawing urn.";
  436. for(int i = 0; i < urnID.length; i++) {
  437. if (bank.withdraw(urnID[i], 1)) {
  438. sleep(500, 600);
  439. }
  440. }
  441. } else {
  442. status = "Ran out of urns, disabling urn support.";
  443. useUrns = false;
  444. }
  445. }
  446. status = "Closing bank.";
  447. if (bank.close()) {
  448. return 100;
  449. }
  450. }
  451. break;
  452. case CLOSE:
  453. status = "Closing collection box.";
  454. if (interfaces.getComponent(109, 14).isValid()) {
  455. if (interfaces.getComponent(109, 14).doClick()) {
  456. return random(1000, 1200);
  457. }
  458. }
  459. break;
  460. }
  461. return 0;
  462. }
  463.  
  464. @Override
  465. public void onFinish() {
  466. log(Color.blue, "Thanks for using GuildFisher by Robert G!");
  467. log(Color.blue, "You gained fishing: " + nf(expGained) + " xp and " + gainedLVL + " fishing levels");
  468. log(Color.blue, "Total fish caught: " + nf(fish) + " averaging " + PH(fish) + " per hour.");
  469. }
  470.  
  471. private enum State {
  472. WALK_SPOT, FISH, WALK_BANK, BANK, DROP, SLEEP, ANTIBAN, FISHING, CLOSE, TELEPORT_URN
  473. }
  474.  
  475. private State getState() {
  476. if (!game.isLoggedIn() || game.isWelcomeScreen()) {
  477. return State.SLEEP;
  478. } else {
  479. if (urnCheck()) {
  480. return State.TELEPORT_URN;
  481. }
  482. if (needUrn()) {
  483. if (calc.distanceTo(bankTile) < 5) {
  484. if (interfaces.getComponent(109, 14).isValid()) {
  485. return State.CLOSE;
  486. } else {
  487. return State.BANK;
  488. }
  489. } else {
  490. return State.WALK_BANK;
  491. }
  492. }
  493. if (!inventory.isFull()) {
  494. if (atSpot()) {
  495. if (getMyPlayer().getInteracting() == null || !getMyPlayer().getInteracting().equals(getSpot())) {
  496. return State.FISH;
  497. } else {
  498. if (random(0, 20) == 9) {
  499. return State.ANTIBAN;
  500. } else {
  501. return State.FISHING;
  502. }
  503. }
  504. } else {
  505. return State.WALK_SPOT;
  506. }
  507. } else {
  508. if (!powerFishing) {
  509. if (calc.distanceTo(bankTile) < 5) {
  510. if (interfaces.getComponent(109, 14).isValid()) {
  511. return State.CLOSE;
  512. } else {
  513. return State.BANK;
  514. }
  515. } else {
  516. return State.WALK_BANK;
  517. }
  518. } else {
  519. return State.DROP;
  520. }
  521. }
  522. }
  523. }
  524.  
  525. private Image getImage(String url) {
  526. try {
  527. return ImageIO.read(new URL(url));
  528. } catch (IOException e) {
  529. return null;
  530. }
  531. }
  532.  
  533. private int PH(int arg0) {
  534. int PH = (int) (3600000.0 / runTime * arg0);
  535. return PH;
  536. }
  537.  
  538. private String nf(int number) {
  539. return nf.format(number);
  540. }
  541.  
  542. @Override
  543. public void mouseClicked(MouseEvent e) {
  544. Point p = e.getPoint();
  545. if (close.contains(p) && !hide) {
  546. hide = true;
  547. } else if (close.contains(p) && hide) {
  548. hide = false;
  549. }
  550. }
  551.  
  552. @Override
  553. public void mouseEntered(MouseEvent arg0) {
  554. // TODO Auto-generated method stub
  555.  
  556. }
  557.  
  558. @Override
  559. public void mouseExited(MouseEvent arg0) {
  560. // TODO Auto-generated method stub
  561.  
  562. }
  563.  
  564. @Override
  565. public void mousePressed(MouseEvent arg0) {
  566. // TODO Auto-generated method stub
  567.  
  568. }
  569.  
  570. @Override
  571. public void mouseReleased(MouseEvent arg0) {
  572. // TODO Auto-generated method stub
  573.  
  574. }
  575.  
  576. private void setGraphics(Graphics g1){
  577. ((Graphics2D) g1).setRenderingHint(RenderingHints.KEY_ANTIALIASING,
  578. RenderingHints.VALUE_ANTIALIAS_ON);
  579. ((Graphics2D) g1).setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
  580. RenderingHints.VALUE_COLOR_RENDER_QUALITY);
  581. ((Graphics2D) g1).setRenderingHint(RenderingHints.KEY_RENDERING,
  582. RenderingHints.VALUE_RENDER_QUALITY);
  583. }
  584.  
  585. private final Color color1 = new Color(194, 194, 194);
  586. private final Color color2 = new Color(248, 0, 0);
  587. private final Color color3 = new Color(0, 0, 0);
  588.  
  589. private final BasicStroke stroke1 = new BasicStroke(1);
  590.  
  591. private final Font font1 = new Font("Calibri", 1, 18);
  592. private final Font font2 = new Font("Calibri", 1, 16);
  593.  
  594. private Image img1;
  595. private Image img2;
  596. private Image img3;
  597.  
  598.  
  599. @Override
  600. public void onRepaint(Graphics g1) {
  601. Graphics2D g = (Graphics2D) g1;
  602. setGraphics(g1);
  603. if (!hide) {
  604. runTime = System.currentTimeMillis() - startTime;
  605. expGained = skills.getCurrentExp(Skills.FISHING) - startExp;
  606. currentLVL = skills.getRealLevel(Skills.FISHING);
  607. gainedLVL = currentLVL - startLVL;
  608. TNL = skills.getExpToNextLevel(Skills.FISHING);
  609. if (expGained > 0)timeTNL = (long) ((double) TNL / (double) expPH * 3600000);
  610. if (expGained > 0)expPH = PH(expGained);
  611. g.drawImage(img1, -2, 337, null);
  612. g.setFont(font1);
  613. g.setColor(color1);
  614. g.drawString("Run Time: " + Timer.format(runTime), 15, 365);
  615. g.drawString("Start Level: " + startLVL, 15, 385);
  616. g.drawString("Current Level: " + currentLVL, 15, 405);
  617. g.drawString("Levels Gained: " + gainedLVL, 15, 425);
  618. g.drawString("XP Gained: " + nf(expGained), 15, 445);
  619. g.drawString("XP / PH: " + nf(PH(expGained)), 260, 365);
  620. g.drawString("Time TNL: " + Timer.format(timeTNL), 260, 385);
  621. g.drawString("Fish Caught: " + nf(fish), 260, 405);
  622. g.drawString("Fish / PH: " + PH(fish), 260, 425);
  623. g.drawString("Status: " + status, 260, 445);
  624. final int percent = skills.getPercentToNextLevel(Skills.FISHING);
  625. final int length = (percent * 487) / 100;
  626. g.setColor(color2);
  627. g.fillRect(15, 450, 487, 15);
  628. g.setColor(color3);
  629. g.setStroke(stroke1);
  630. g.drawRect(15, 450, 487, 15);
  631. g.setColor(Color.GREEN);
  632. g.fillRect(15, 450, length, 15);
  633. g.setColor(color3);
  634. g.setStroke(stroke1);
  635. g.drawRect(15, 450, length, 15);
  636. g.setColor(color3);
  637. g.setFont(font2);
  638. g.drawString(percent + "% (" + nf(TNL) + " XP TNL)", 175, 462);
  639. g.drawImage(img2, 416, 349, null);
  640. g.drawImage(img3, 45, 5, null);
  641. }
  642.  
  643. }
  644.  
  645. @Override
  646. public void messageReceived(MessageEvent e) {
  647. String x = e.getMessage().toLowerCase();
  648. if (x.contains("you catch a")) {
  649. fish++;
  650. }
  651.  
  652. }
  653.  
  654. public static enum fishingType {
  655. LOBSTER(312, "Cage", new RSTile(2600, 3421)),
  656. SWORDFISH(312, "Harpoon", new RSTile(2600, 3421)),
  657. SHARK(313, "Harpoon", new RSTile(2604, 3412));
  658.  
  659. private int spotID;
  660. private String catchOption;
  661. private RSTile tile;
  662.  
  663. private fishingType(int spotID, String catchOption, RSTile tile) {
  664. this.spotID = spotID;
  665. this.catchOption = catchOption;
  666. this.tile = tile;
  667. }
  668.  
  669. public int getSpotID() {
  670. return spotID;
  671. }
  672.  
  673. public String getCatchOption() {
  674. return catchOption;
  675. }
  676.  
  677. public RSTile getSpotTile() {
  678. return tile;
  679. }
  680.  
  681. @Override
  682. public String toString() {
  683. String name = name().toLowerCase();
  684. name = name.substring(0, 1).toUpperCase() + name.substring(1);
  685. return name.replaceAll("_", " ");
  686. }
  687. }
  688.  
  689. /**
  690. * @author Robert G
  691. */
  692. public class GuildFisherGUI extends JFrame {
  693. /**
  694. *
  695. */
  696. private static final long serialVersionUID = 1L;
  697.  
  698. public GuildFisherGUI() {
  699. initComponents();
  700. }
  701.  
  702. private void okButtonActionPerformed(ActionEvent e) {
  703. catchOption = ((fishingType)fishSelected.getSelectedItem()).getCatchOption();
  704. spotID = ((fishingType)fishSelected.getSelectedItem()).getSpotID();
  705. spotTile = ((fishingType)fishSelected.getSelectedItem()).getSpotTile();
  706. powerFishing = checkBox1.isSelected();
  707. start = true;
  708. dispose();
  709. }
  710.  
  711. private void initComponents() {
  712. dialogPane = new JPanel();
  713. contentPanel = new JPanel();
  714. label1 = new JLabel();
  715. label2 = new JLabel();
  716. fishSelected = new JComboBox();
  717. label3 = new JLabel();
  718. checkBox1 = new JCheckBox();
  719. buttonBar = new JPanel();
  720. okButton = new JButton();
  721.  
  722. // ======== this ========
  723. Container contentPane = getContentPane();
  724. contentPane.setLayout(new BorderLayout());
  725.  
  726. // ======== dialogPane ========
  727. {
  728. dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
  729. dialogPane.setBorder(new javax.swing.border.CompoundBorder(
  730. new javax.swing.border.TitledBorder(
  731. new javax.swing.border.EmptyBorder(0, 0, 0, 0),
  732. "", javax.swing.border.TitledBorder.CENTER,
  733. javax.swing.border.TitledBorder.BOTTOM,
  734. new java.awt.Font("Dialog", java.awt.Font.BOLD,
  735. 12), java.awt.Color.red), dialogPane
  736. .getBorder()));
  737. dialogPane
  738. .addPropertyChangeListener(new java.beans.PropertyChangeListener() {
  739. @Override
  740. public void propertyChange(
  741. java.beans.PropertyChangeEvent e) {
  742. if ("border".equals(e.getPropertyName()))
  743. throw new RuntimeException();
  744. }
  745. });
  746.  
  747. dialogPane.setLayout(new BorderLayout());
  748.  
  749. // ======== contentPanel ========
  750. {
  751.  
  752. // ---- label1 ----
  753. label1.setText("Welcome to Robert G's GuildFisher!");
  754. label1.setFont(new Font("Georgia", Font.BOLD, 12));
  755.  
  756. // ---- label2 ----
  757. label2.setText("Select fish to catch:");
  758.  
  759. // ---- fishSelected ----
  760. fishSelected.setModel(new DefaultComboBoxModel(fishingType.values()));
  761.  
  762. // ---- label3 ----
  763. label3.setText("By default the script will bank ");
  764.  
  765. // ---- checkBox1 ----
  766. checkBox1.setText("tick here for powerfishing mode.");
  767.  
  768. GroupLayout contentPanelLayout = new GroupLayout(
  769. contentPanel);
  770. contentPanel.setLayout(contentPanelLayout);
  771. contentPanelLayout
  772. .setHorizontalGroup(contentPanelLayout
  773. .createParallelGroup()
  774. .addGroup(
  775. contentPanelLayout
  776. .createSequentialGroup()
  777. .addGroup(
  778. contentPanelLayout
  779. .createParallelGroup()
  780. .addComponent(
  781. label1)
  782. .addGroup(
  783. contentPanelLayout
  784. .createSequentialGroup()
  785. .addComponent(
  786. label2)
  787. .addPreferredGap(
  788. LayoutStyle.ComponentPlacement.UNRELATED)
  789. .addComponent(
  790. fishSelected,
  791. GroupLayout.PREFERRED_SIZE,
  792. 100,
  793. GroupLayout.PREFERRED_SIZE))
  794. .addGroup(
  795. contentPanelLayout
  796. .createSequentialGroup()
  797. .addComponent(
  798. label3)
  799. .addPreferredGap(
  800. LayoutStyle.ComponentPlacement.UNRELATED)
  801. .addComponent(
  802. checkBox1)))
  803. .addContainerGap(36,
  804. Short.MAX_VALUE)));
  805. contentPanelLayout
  806. .setVerticalGroup(contentPanelLayout
  807. .createParallelGroup()
  808. .addGroup(
  809. contentPanelLayout
  810. .createSequentialGroup()
  811. .addComponent(label1)
  812. .addGap(40, 40, 40)
  813. .addGroup(
  814. contentPanelLayout
  815. .createParallelGroup(
  816. GroupLayout.Alignment.TRAILING)
  817. .addComponent(
  818. label2)
  819. .addComponent(
  820. fishSelected,
  821. GroupLayout.PREFERRED_SIZE,
  822. GroupLayout.DEFAULT_SIZE,
  823. GroupLayout.PREFERRED_SIZE))
  824. .addGap(38, 38, 38)
  825. .addGroup(
  826. contentPanelLayout
  827. .createParallelGroup(
  828. GroupLayout.Alignment.BASELINE)
  829. .addComponent(
  830. label3)
  831. .addComponent(
  832. checkBox1))
  833. .addContainerGap(77,
  834. Short.MAX_VALUE)));
  835. }
  836. dialogPane.add(contentPanel, BorderLayout.WEST);
  837.  
  838. // ======== buttonBar ========
  839. {
  840. buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
  841. buttonBar.setLayout(new GridBagLayout());
  842. ((GridBagLayout) buttonBar.getLayout()).columnWidths = new int[] {
  843. 0, 80 };
  844. ((GridBagLayout) buttonBar.getLayout()).columnWeights = new double[] {
  845. 1.0, 0.0 };
  846.  
  847. // ---- okButton ----
  848. okButton.setText("OK");
  849. okButton.addActionListener(new ActionListener() {
  850. @Override
  851. public void actionPerformed(ActionEvent e) {
  852. okButtonActionPerformed(e);
  853. }
  854. });
  855. buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1,
  856. 0.0, 0.0, GridBagConstraints.CENTER,
  857. GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0,
  858. 0));
  859. }
  860. dialogPane.add(buttonBar, BorderLayout.SOUTH);
  861. }
  862. contentPane.add(dialogPane, BorderLayout.CENTER);
  863. pack();
  864. setLocationRelativeTo(getOwner());
  865. setVisible(true);
  866. }
  867.  
  868. private JPanel dialogPane;
  869. private JPanel contentPanel;
  870. private JLabel label1;
  871. private JLabel label2;
  872. private JComboBox fishSelected;
  873. private JLabel label3;
  874. private JCheckBox checkBox1;
  875. private JPanel buttonBar;
  876. private JButton okButton;
  877. }
  878.  
  879. }
Advertisement
Add Comment
Please, Sign In to add comment