Advertisement
Conderoga

CPowerFish

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