Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 18.61 KB | None | 0 0
  1. import java.awt.BasicStroke;
  2. import java.awt.Color;
  3. import java.awt.Container;
  4. import java.awt.Dimension;
  5. import java.awt.Font;
  6. import java.awt.Graphics;
  7. import java.awt.Graphics2D;
  8. import java.awt.Insets;
  9. import java.awt.Rectangle;
  10. import java.awt.event.ActionEvent;
  11. import java.awt.event.ActionListener;
  12. import java.awt.event.MouseEvent;
  13. import java.awt.event.MouseListener;
  14. import java.text.DecimalFormat;
  15. import java.util.Map;
  16.  
  17. import javax.swing.DefaultComboBoxModel;
  18. import javax.swing.JButton;
  19. import javax.swing.JComboBox;
  20. import javax.swing.JFrame;
  21. import javax.swing.JLabel;
  22. import javax.swing.JPanel;
  23. import javax.swing.SwingConstants;
  24. import javax.swing.WindowConstants;
  25.  
  26. import org.rsbot.bot.Bot;
  27. import org.rsbot.event.events.MessageEvent;
  28. import org.rsbot.event.listeners.MessageListener;
  29. import org.rsbot.event.listeners.PaintListener;
  30. import org.rsbot.script.Script;
  31. import org.rsbot.script.ScriptManifest;
  32. import org.rsbot.script.methods.Game;
  33. import org.rsbot.script.methods.Skills;
  34. import org.rsbot.script.util.Timer;
  35.  
  36. @ScriptManifest(authors = { "Shadow Storm" }, keywords = { "Magic", "Enchant" }, name = "Shadow Enchanter", version = 0.1, description = "Enchants your jewelry.")
  37. public class ShadowEnchanter extends Script implements PaintListener,
  38.         MouseListener {
  39.     final ScriptManifest properties = getClass().getAnnotation(
  40.             ScriptManifest.class);
  41.  
  42.     int[] clickID = { 1637, 1639, 1641, 1643, 1645, 1656, 1658, 1660, 1662,
  43.             1664, 1694, 1696, 1698, 1700, 1702, 11072, 11076, 11085, 11092,
  44.             11115 };
  45.     public int madeID;
  46.     public int cosmicID = 564;
  47.     public int child;
  48.     public String chantedName;
  49.     public String status = ("Game Loading...");
  50.     private int startXP = 0;
  51.     private int startLVL = 0;
  52.     private long scriptStartTime;
  53.     public boolean startScript = false;
  54.     private boolean randomsState = true;
  55.     private boolean needToBank = true;
  56.     public boolean setAltitude = false;
  57.     Timer timer;
  58.     boolean guiExit, guiWait = true;
  59.     private static final DecimalFormat k = new DecimalFormat("#.#");
  60.     int casts;
  61.     GUI gui;
  62.     int mspeed;
  63.  
  64.     @Override
  65.     public boolean onStart() {
  66.         gui = new GUI();
  67.         while (guiWait) {
  68.             sleep(100);
  69.         }
  70.         randomsState = env.disableRandom("Login");
  71.         env.disableRandom("Login");
  72.         needToBank = false;
  73.         scriptStartTime = System.currentTimeMillis();
  74.         startScript = true;
  75.         timer = new Timer(0);
  76.         startXP = skills.getCurrentExp(Skills.MAGIC);
  77.         startLVL = skills.getCurrentLevel(Skills.MAGIC);
  78.         return guiExit;
  79.  
  80.     }
  81.  
  82.     @Override
  83.     public void onFinish() {
  84.         logProgressReport();
  85.     }
  86.  
  87.     public void logProgressReport() {
  88.         final int currentXP = skills.getCurrentExp(Skills.MAGIC);
  89.         final int XPgained = currentXP - startXP;
  90.         final long runTime = System.currentTimeMillis() - scriptStartTime;
  91.         final int seconds = (int) ((runTime / 1000) % 60);
  92.         final int minutes = (int) ((runTime / 1000) / 60) % 60;
  93.         final int hours = (int) (((runTime / 1000) / 60) / 60) % 60;
  94.         final StringBuilder t1 = new StringBuilder();
  95.         if (hours < 10) {
  96.             t1.append('0');
  97.         }
  98.         t1.append(hours);
  99.         t1.append(" : ");
  100.         if (minutes < 10) {
  101.             t1.append('0');
  102.         }
  103.         t1.append(minutes);
  104.         t1.append(" : ");
  105.         if (seconds < 10) {
  106.             t1.append('0');
  107.         }
  108.         t1.append(seconds);
  109.         log("Thank you for using this script. Please visit its page on the Powerbot site");
  110.         log(properties.name() + ", " + properties.version());
  111.         log("Run Time: " + t1);
  112.         log("XP Gained: " + XPgained);
  113.     }
  114.  
  115.     public int loop() {
  116.         mouse.setSpeed(random(mspeed - 2, mspeed));
  117.         if (getMyPlayer().getAnimation() != -1) {
  118.             casts++;
  119.         }
  120.         if (startXP == 0) {
  121.             startXP = skills.getCurrentExp(Skills.MAGIC);
  122.             startLVL = skills.getCurrentLevel(Skills.MAGIC);
  123.         }
  124.  
  125.         if (!setAltitude) {
  126.             camera.setPitch(true);
  127.             sleep(random(250, 500));
  128.             setAltitude = true;
  129.             return random(50, 100);
  130.         }
  131.  
  132.         if (!handleEnchant() && randomsState) {
  133.             if (randomsState) {
  134.                 randomsState = false;
  135.                 log.info("Randoms Able.");
  136.             }
  137.         } else {
  138.             if (handleEnchant() && !randomsState) {
  139.                 if (randomsState) {
  140.                     randomsState = false;
  141.                     log.info("Randoms Able.");
  142.                 } else if (randomsState) {
  143.                     randomsState = false;
  144.                     log.info("Randoms Able.");
  145.                 } else {
  146.                     if (!randomsState) {
  147.                         randomsState = true;
  148.                         log.info("Randoms Unable.");
  149.                     }
  150.                 }
  151.             }
  152.         }
  153.         if (!randomsState) {
  154.             return 100;
  155.         }
  156.  
  157.         try {
  158.             if (needToBank) {
  159.                 int ct = 0;
  160.                 boolean banked = false;
  161.                 do {
  162.                     banked = bank();
  163.                     sleep(random(100, 400));
  164.                     ct++;
  165.                 } while (ct < 5 && !banked);
  166.  
  167.                 if (bank.isOpen()) {
  168.                     if (inventory.getCount(cosmicID) > 0
  169.                             && inventory.getCount(madeID) > 0) {
  170.                         bank.close();
  171.                         needToBank = false;
  172.                     }
  173.                     return random(300, 400);
  174.                 }
  175.             }
  176.             if (bank.isOpen()) {
  177.                 bank.close();
  178.                 sleep(random(350, 450));
  179.             }
  180.  
  181.             return random(20, 30);
  182.         } catch (Exception e) {
  183.             e.printStackTrace();
  184.         }
  185.         return 1;
  186.     }
  187.  
  188.     public boolean handleEnchant() {
  189.         antiBan();
  190.         status = ("Enchanting");
  191.         int ct = 0;
  192.         sleep(random(200, 300));
  193.         magic.castSpell(child);
  194.         ct = 0;
  195.         while (ct < 15 && (game.getCurrentTab() != Game.TAB_INVENTORY)) {
  196.             ct++;
  197.             sleep(random(150, 200));
  198.         }
  199.         if (!inventory.contains(cosmicID)) {
  200.             log("You have ran out of cosmic runes!  Stopping script...");
  201.             stopScript(true);
  202.             return false;
  203.         }
  204.  
  205.         if (needToBank = needMadeID(false)) {
  206.             return true;
  207.         }
  208.         needToBank = needMadeID(true);
  209.         if (!inventory.contains(madeID)) {
  210.             mouse.click(true);
  211.             return true;
  212.         }
  213.         if (!inventory.contains(madeID)) {
  214.             mouse.click(true);
  215.             return true;
  216.         }
  217.         ct = 0;
  218.         while (ct < 10 && !inventory.getItem(madeID).doAction("Cast")) {
  219.             sleep(random(1, 5));
  220.             ct++;
  221.         }
  222.         ct = 0;
  223.         while (ct < 75 && (game.getCurrentTab() != Game.TAB_MAGIC)) {
  224.             ct++;
  225.             sleep(random(150, 200));
  226.         }
  227.         return true;
  228.     }
  229.  
  230.     public boolean bank() {
  231.         antiBan();
  232.         status = ("Banking");
  233.         int ct = 0;
  234.         try {
  235.             if (!bank.isOpen() && !inventory.contains(madeID)) {
  236.                 sleep(random(500, 800));
  237.                 if (bank.open())
  238.                     status = ("Bank Is Open...");
  239.                 sleep(random(300, 500));
  240.                 while (!bank.isOpen() && !inventory.contains(madeID)) {
  241.                     sleep(180);
  242.                     ct++;
  243.                     if (ct > 30)
  244.                         return false;
  245.                 }
  246.             }
  247.         } catch (final Exception e) {
  248.         }
  249.  
  250.         if (bank.isOpen()) {
  251.             status = ("Empting Inventory");
  252.             if (bank.depositAllExcept(cosmicID))
  253.                 ;
  254.             sleep(random(700, 800));
  255.             if (bank.getCount(madeID) > 0) {
  256.                 sleep(random(600, 800));
  257.                 if (inventory.getCount(madeID) == 0) {
  258.                     sleep(random(600, 800));
  259.                     status = ("Getting " + madeID + "...");
  260.                     if (bank.withdraw(madeID, 0)) {
  261.                         sleep(random(400, 500));
  262.                         bank.close();
  263.                     }
  264.                 }
  265.             } else {
  266.                 bank.close();
  267.                 sleep(random(10000, 12000));
  268.                 status = ("Logging out in 10 sec");
  269.                 game.logout(true);
  270.             }
  271.         }
  272.         needToBank = true;
  273.         return false;
  274.     }
  275.  
  276.     public boolean needMadeID(boolean castActive) {
  277.         int cosmicIDnum = inventory.getCount(cosmicID);
  278.         int madeIDnum = inventory.getCount(madeID);
  279.         if (castActive) {
  280.             if (madeIDnum < 1 || cosmicIDnum < 1) {
  281.                 return true;
  282.             }
  283.         }
  284.         return false;
  285.     }
  286.  
  287.     private final Color color1 = new Color(0, 150, 150, 200);
  288.     private final Color color2 = new Color(0, 0, 0);
  289.     private final Color color3 = new Color(51, 204, 0);
  290.  
  291.     private final BasicStroke stroke1 = new BasicStroke(1);
  292.  
  293.     private final Font font1 = new Font("SansSerif", 1, 10);
  294.  
  295.     boolean show = true;
  296.  
  297.     public void onRepaint(final Graphics g1) {
  298.         if (game.isLoggedIn()) {
  299.             final long runTime = System.currentTimeMillis() - scriptStartTime;
  300.             final int seconds = (int) ((runTime / 1000) % 60);
  301.             final int minutes = (int) ((runTime / 1000) / 60) % 60;
  302.             final int hours = (int) (((runTime / 1000) / 60) / 60) % 60;
  303.             int levelsGained = skills.getCurrentLevel(Skills.MAGIC) - startLVL;
  304.             int castsPerHour = 0;
  305.             int expGained = skills.getCurrentExp(Skills.MAGIC) - startXP;
  306.             int expPerHour = 0;
  307.             if (expGained > 0 && seconds > 0) {
  308.                 expPerHour = (int) (3600 * expGained / seconds);
  309.             }
  310.             if (casts > 0 && seconds > 0) {
  311.                 castsPerHour = (int) (3600 * casts / seconds);
  312.             }
  313.             Graphics2D g = (Graphics2D) g1;
  314.             if (show) {
  315.                 g.setColor(color1);
  316.                 g.fillRect(2, 3, 173, 146);
  317.                 g.setColor(color2);
  318.                 g.setStroke(stroke1);
  319.                 g.drawRect(2, 3, 173, 146);
  320.                 g.setColor(color1);
  321.                 g.fillRect(4, 5, 51, 18);
  322.                 g.setColor(color2);
  323.                 g.drawRect(4, 5, 51, 18);
  324.                 g.setFont(font1);
  325.                 g.drawString("Hide", 20, 18);
  326.                 g.drawString("Shadow Enchanter", 65, 18);
  327.                 g.drawString("Exp. earned: " + k.format(expGained / 1000D)
  328.                         + "K | Per hour: " + k.format(expPerHour / 1000D), 5,
  329.                         50);
  330.                 g.drawString("Casts: " + casts + "K | Per hour: "
  331.                         + castsPerHour, 5, 70);
  332.                 g.setColor(color3);
  333.                 g.fillRect(7, 131, skills.getPercentToNextLevel(Skills.MAGIC),
  334.                         12);
  335.                 g.setColor(color2);
  336.                 g.drawString("Level: " + skills.getCurrentLevel(Skills.MAGIC)
  337.                         + " | Earned: " + levelsGained, 5, 90);
  338.                 g.drawString("Time running: " + timer.toElapsedString(), 5, 110);
  339.                 g.drawRect(6, 129, 165, 15);
  340.                 g.drawString(skills.getPercentToNextLevel(Skills.MAGIC)
  341.                         + "% to " + (skills.getCurrentLevel(Skills.MAGIC) + 1),
  342.                         62, 140);
  343.             } else {
  344.                 g.setColor(color1);
  345.                 g.fillRect(4, 5, 51, 18);
  346.                 g.setColor(color2);
  347.                 g.drawRect(4, 5, 51, 18);
  348.                 g.setFont(font1);
  349.                 g.drawString("Show", 20, 18);
  350.             }
  351.         }
  352.     }
  353.  
  354.     public void antiBan() {
  355.         switch (random(0, 450)) {
  356.         case 2:
  357.             if (game.getCurrentTab() != Game.TAB_FRIENDS) {
  358.                 status = ("Friend Check");
  359.                 game.openTab(Game.TAB_FRIENDS);
  360.                 sleep(random(640, 920));
  361.             } else {
  362.                 if (game.getCurrentTab() == Game.TAB_STATS) {
  363.                     status = ("HitPoint Check");
  364.                     game.openTab(Game.TAB_STATS);
  365.                     sleep(random(350, 780));
  366.                     mouse.move(636, 244, 5, 5);
  367.                     sleep(random(400, 700));
  368.                 }
  369.             }
  370.             break;
  371.         case 3:
  372.             if (game.getCurrentTab() != Game.TAB_STATS) {
  373.                 status = ("Attack Power Check");
  374.                 game.openTab(Game.TAB_STATS);
  375.                 sleep(random(500, 800));
  376.                 mouse.move(576, 245, 5, 5);
  377.                 sleep(random(800, 1200));
  378.             } else {
  379.                 if (game.getCurrentTab() == Game.TAB_STATS) {
  380.                     status = ("Defence Check");
  381.                     game.openTab(Game.TAB_STATS);
  382.                     sleep(random(700, 900));
  383.                     mouse.move(570, 313, 5, 5);
  384.                     sleep(random(800, 1200));
  385.                 }
  386.             }
  387.             break;
  388.         case 4:
  389.             if (game.getCurrentTab() == Game.TAB_INVENTORY) {
  390.                 status = ("AntiBan");
  391.                 game.openTab(Game.TAB_STATS);
  392.                 sleep(random(300, 700));
  393.                 mouse.move(680, 280, 5, 5);
  394.                 sleep(random(500, 800));
  395.                 game.openTab(Game.TAB_INVENTORY);
  396.                 sleep(random(300, 600));
  397.                 mouse.move(582, 229, 5, 5);
  398.                 sleep(random(700, 1000));
  399.             } else {
  400.                 if (game.getCurrentTab() == Game.TAB_STATS) {
  401.                     status = ("Stat Smith Check");
  402.                     game.openTab(Game.TAB_STATS);
  403.                     sleep(random(500, 700));
  404.                     mouse.move(680, 280, 5, 5);
  405.                     sleep(random(800, 1000));
  406.                 }
  407.             }
  408.             break;
  409.         case 5:
  410.             status = ("Equipment Check");
  411.             mouse.move(random(0, 800), random(0, 800));
  412.             sleep(random(300, 500));
  413.             mouse.move(748, 847, 5, 5);
  414.             sleep(random(500, 700));
  415.             mouse.click(true);
  416.             sleep(random(800, 1000));
  417.             game.openTab(Game.TAB_EQUIPMENT);
  418.             sleep(random(800, 1000));
  419.             break;
  420.         }
  421.     }
  422.  
  423.     public class GUI extends JPanel {
  424.         private static final long serialVersionUID = 1L;
  425.  
  426.         public GUI() {
  427.             initComponents();
  428.         }
  429.  
  430.         private void button1ActionPerformed(ActionEvent e) {
  431.             String jewel = comboBox1.getSelectedItem().toString();
  432.             String speed = comboBox2.getSelectedItem().toString();
  433.             if (jewel.equals("Ring of Recoil")) {
  434.                 madeID = 1637;
  435.                 chantedName = "Ring of Recoil";
  436.                 child = 29;
  437.             } else if (jewel.equals("Ring of Duelling")) {
  438.                 madeID = 1639;
  439.                 chantedName = "Ring of Duelling";
  440.                 child = 41;
  441.             } else if (jewel.equals("Ring of Forging")) {
  442.                 madeID = 1641;
  443.                 chantedName = "Ring of Forging";
  444.                 child = 53;
  445.             } else if (jewel.equals("Ring of Life")) {
  446.                 madeID = 1643;
  447.                 chantedName = "Ring of Life";
  448.                 child = 61;
  449.             } else if (jewel.equals("Ring of Wealth")) {
  450.                 madeID = 1645;
  451.                 chantedName = "Ring of Wealth";
  452.                 child = 76;
  453.             } else if (jewel.equals("Games Necklace")) {
  454.                 madeID = 1656;
  455.                 chantedName = "Games Necklace";
  456.                 child = 29;
  457.             } else if (jewel.equals("Necklace of Binding")) {
  458.                 madeID = 1658;
  459.                 chantedName = "Necklace of Binding";
  460.                 child = 41;
  461.             } else if (jewel.equals("Digsite Pendant")) {
  462.                 madeID = 1660;
  463.                 chantedName = "Digsite Pendant";
  464.                 child = 53;
  465.             } else if (jewel.equals("Phoenix Necklace")) {
  466.                 madeID = 1662;
  467.                 chantedName = "Phoenix Necklace";
  468.                 child = 61;
  469.             } else if (jewel.equals("Skills Necklace")) {
  470.                 madeID = 1664;
  471.                 chantedName = "Skills Necklace";
  472.                 child = 76;
  473.             } else if (jewel.equals("Amulet of Magic")) {
  474.                 madeID = 1694;
  475.                 chantedName = "Amulet of Magic";
  476.                 child = 29;
  477.             } else if (jewel.equals("Amulet of Defence")) {
  478.                 madeID = 1696;
  479.                 chantedName = "Amulet of Defence";
  480.                 child = 41;
  481.             } else if (jewel.equals("Amulet of Strength")) {
  482.                 madeID = 1698;
  483.                 chantedName = "Amulet of Strength";
  484.                 child = 53;
  485.             } else if (jewel.equals("Amulet of Power")) {
  486.                 madeID = 1700;
  487.                 chantedName = "Amulet of Power";
  488.                 child = 61;
  489.             } else if (jewel.equals("Amulet of Glory")) {
  490.                 madeID = 1702;
  491.                 chantedName = "Amulet of Glory";
  492.                 child = 76;
  493.             } else if (jewel.equals("Bracelet of Clay")) {
  494.                 madeID = 11072;
  495.                 chantedName = "Bracelet of Clay";
  496.                 child = 29;
  497.             } else if (jewel.equals("Castlewars Bracelet")) {
  498.                 madeID = 11076;
  499.                 chantedName = "Castlewars Bracelet";
  500.                 child = 41;
  501.             } else if (jewel.equals("Inoculation Brace")) {
  502.                 madeID = 11085;
  503.                 chantedName = "Inoculation Brace";
  504.                 child = 53;
  505.             } else if (jewel.equals("Forinthry Bracelet")) {
  506.                 madeID = 11092;
  507.                 chantedName = "Forinthry Bracelet";
  508.                 child = 61;
  509.             } else if (jewel.equals("Combat Bracelet")) {
  510.                 madeID = 11115;
  511.                 chantedName = "Combat Bracelet";
  512.                 child = 76;
  513.             } else if (jewel.equals("Onyx Ring")) {
  514.                 madeID = 0;
  515.                 chantedName = "";
  516.                 child = 88;
  517.             }
  518.             if (speed.equals("Extreme")) {
  519.                 mspeed = 3;
  520.             } else if (speed.equals("Fast")) {
  521.                 mspeed = 5;
  522.             } else if (speed.equals("Human")) {
  523.                 mspeed = 7;
  524.             } else if (speed.equals("Slow")) {
  525.                 mspeed = 9;
  526.             } else if (speed.equals("Turtle")) {
  527.                 mspeed = 11;
  528.             }
  529.             guiWait = false;
  530.             guiExit = true;
  531.             frame1.dispose();
  532.         }
  533.  
  534.         private void initComponents() {
  535.             frame1 = new JFrame();
  536.             label1 = new JLabel();
  537.             label2 = new JLabel();
  538.             comboBox1 = new JComboBox();
  539.             label3 = new JLabel();
  540.             comboBox2 = new JComboBox();
  541.             button1 = new JButton();
  542.  
  543.             // ======== frame1 ========
  544.             {
  545.                 frame1.setVisible(true);
  546.                 frame1.setTitle("Shadow Enchanter GUI");
  547.                 Container frame1ContentPane = frame1.getContentPane();
  548.                 frame1ContentPane.setLayout(null);
  549.                 frame1.setAlwaysOnTop(true);
  550.                 frame1.setResizable(false);
  551.                 frame1.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  552.  
  553.                 // ---- label1 ----
  554.                 label1.setText("Shadow Enchanter");
  555.                 label1.setHorizontalAlignment(SwingConstants.CENTER);
  556.                 label1.setForeground(Color.red);
  557.                 label1.setFont(new Font("Tw Cen MT", Font.PLAIN, 16));
  558.                 frame1ContentPane.add(label1);
  559.                 label1.setBounds(0, 0, 220, 25);
  560.  
  561.                 // ---- label2 ----
  562.                 label2.setText("Enchant:");
  563.                 label2.setHorizontalAlignment(SwingConstants.CENTER);
  564.                 frame1ContentPane.add(label2);
  565.                 label2.setBounds(50, 50, 120, label2.getPreferredSize().height);
  566.  
  567.                 // ---- comboBox1 ----
  568.                 comboBox1.setModel(new DefaultComboBoxModel(new String[] {
  569.                         "Ring of Recoil", "Ring of Dueling", "Ring of Forging",
  570.                         "Ring of Life", "Ring of Wealth", "Onyx Ring",
  571.                         "Games Necklace", "Necklace of Binding",
  572.                         "Digsite Pendant", "Phoenix Necklace",
  573.                         "Skills Necklace", "Amulet of Magic",
  574.                         "Amulet of Defense", "Amulet of Strength",
  575.                         "Amulet of Power", "Amulet of Glory",
  576.                         "Bracelet of Clay", "Castlewars Bracelet",
  577.                         "Inoculation Bracelet", "Forinthry Bracelet",
  578.                         "Combat Bracelet" }));
  579.                 frame1ContentPane.add(comboBox1);
  580.                 comboBox1.setBounds(50, 69, 120,
  581.                         comboBox1.getPreferredSize().height);
  582.  
  583.                 // ---- label3 ----
  584.                 label3.setText("Mouse:");
  585.                 label3.setHorizontalAlignment(SwingConstants.CENTER);
  586.                 frame1ContentPane.add(label3);
  587.                 label3.setBounds(50, 119, 120, label3.getPreferredSize().height);
  588.  
  589.                 // ---- comboBox2 ----
  590.                 comboBox2.setModel(new DefaultComboBoxModel(new String[] {
  591.                         "Extreme", "Fast", "Human", "Slow", "Turtle" }));
  592.                 frame1ContentPane.add(comboBox2);
  593.                 comboBox2.setBounds(50, 138, 120,
  594.                         comboBox2.getPreferredSize().height);
  595.  
  596.                 // ---- button1 ----
  597.                 button1.setText("Start");
  598.                 button1.addActionListener(new ActionListener() {
  599.                     public void actionPerformed(ActionEvent e) {
  600.                         button1ActionPerformed(e);
  601.                     }
  602.                 });
  603.                 frame1ContentPane.add(button1);
  604.                 button1.setBounds(75, 188, 70,
  605.                         button1.getPreferredSize().height);
  606.  
  607.                 {
  608.                     Dimension preferredSize = new Dimension();
  609.                     for (int i = 0; i < frame1ContentPane.getComponentCount(); i++) {
  610.                         Rectangle bounds = frame1ContentPane.getComponent(i)
  611.                                 .getBounds();
  612.                         preferredSize.width = Math.max(bounds.x + bounds.width,
  613.                                 preferredSize.width);
  614.                         preferredSize.height = Math.max(bounds.y
  615.                                 + bounds.height, preferredSize.height);
  616.                     }
  617.                     Insets insets = frame1ContentPane.getInsets();
  618.                     preferredSize.width += insets.right;
  619.                     preferredSize.height += insets.bottom;
  620.                     frame1ContentPane.setMinimumSize(preferredSize);
  621.                     frame1ContentPane.setPreferredSize(preferredSize);
  622.                 }
  623.                 frame1.pack();
  624.                 frame1.setLocationRelativeTo(frame1.getOwner());
  625.             }
  626.         }
  627.  
  628.         private JFrame frame1;
  629.         private JLabel label1;
  630.         private JLabel label2;
  631.         private JComboBox comboBox1;
  632.         private JLabel label3;
  633.         private JComboBox comboBox2;
  634.         private JButton button1;
  635.     }
  636.  
  637.     @Override
  638.     public void mouseClicked(MouseEvent arg0) {
  639.         Rectangle r = new Rectangle(4, 5, 51, 18);
  640.         if (r.contains(arg0.getPoint())) {
  641.             show = !show;
  642.         }
  643.     }
  644.  
  645.     @Override
  646.     public void mouseEntered(MouseEvent arg0) {
  647.         // TODO Auto-generated method stub
  648.  
  649.     }
  650.  
  651.     @Override
  652.     public void mouseExited(MouseEvent arg0) {
  653.         // TODO Auto-generated method stub
  654.  
  655.     }
  656.  
  657.     @Override
  658.     public void mousePressed(MouseEvent arg0) {
  659.         // TODO Auto-generated method stub
  660.  
  661.     }
  662.  
  663.     @Override
  664.     public void mouseReleased(MouseEvent arg0) {
  665.         // TODO Auto-generated method stub
  666.  
  667.     }
  668. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement