Advertisement
Guest User

DGnomeAgil.java

a guest
Jul 4th, 2016
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 20.96 KB | None | 0 0
  1. package scripts;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Color;
  5. import java.awt.Container;
  6. import java.awt.Desktop;
  7. import java.awt.Font;
  8. import java.awt.Graphics;
  9. import java.awt.Graphics2D;
  10. import java.awt.GridBagConstraints;
  11. import java.awt.GridBagLayout;
  12. import java.awt.Image;
  13. import java.awt.Insets;
  14. import java.awt.RenderingHints;
  15. import java.awt.event.ActionEvent;
  16. import java.io.IOException;
  17. import java.net.MalformedURLException;
  18. import java.net.URI;
  19. import java.net.URISyntaxException;
  20. import java.net.URL;
  21. import java.util.ArrayList;
  22.  
  23. import javax.imageio.ImageIO;
  24. import javax.swing.DefaultComboBoxModel;
  25. import javax.swing.GroupLayout;
  26. import javax.swing.JButton;
  27. import javax.swing.JCheckBox;
  28. import javax.swing.JComboBox;
  29. import javax.swing.JFrame;
  30. import javax.swing.JLabel;
  31. import javax.swing.JMenu;
  32. import javax.swing.JMenuBar;
  33. import javax.swing.JMenuItem;
  34. import javax.swing.JPanel;
  35. import javax.swing.LayoutStyle;
  36. import javax.swing.border.EmptyBorder;
  37.  
  38. import org.tribot.api.DynamicClicking;
  39. import org.tribot.api.General;
  40. import org.tribot.api.input.Mouse;
  41. import org.tribot.api2007.Camera;
  42. import org.tribot.api2007.Login;
  43. import org.tribot.api2007.Objects;
  44. import org.tribot.api2007.Player;
  45. import org.tribot.api2007.Skills;
  46. import org.tribot.api2007.Skills.SKILLS;
  47. import org.tribot.api2007.types.RSObject;
  48. import org.tribot.api2007.types.RSTile;
  49. import org.tribot.script.Script;
  50. import org.tribot.script.ScriptManifest;
  51. import org.tribot.script.interfaces.Painting;
  52.  
  53. import scripts.DTools.DAntiban;
  54. import scripts.DTools.Newsloader;
  55.  
  56. @ScriptManifest(authors = { "TheD" }, category = "TheDScripts", name = "DGnomeAgility", description = "Start the script anywhere on the route, the script will pick up!")
  57. public class DGnomeAgil extends Script implements Painting
  58. {
  59.  
  60.     private State scriptState = State.NOTHING;
  61.     private boolean GUIWait = true;
  62.     private boolean use_abcv2 = false;
  63.     private GUI g = new GUI();
  64.     private long Start_XP = Skills.getXP(SKILLS.AGILITY);
  65.     private final long startTime = System.currentTimeMillis();
  66.     private int laps_ran = 0;
  67.     private final Font font2 = new Font("Arial", Font.BOLD, 14);
  68.     private final Font font3 = new Font("Arial", 1, 16);
  69.     private long startNewsTime = System.currentTimeMillis();
  70.     private ArrayList<String> latestNews = new ArrayList<String>();
  71.     private boolean count_lap = false;
  72.    
  73.     private boolean end_after_time = false;
  74.     private int end_hour = 0;
  75.     private int end_minute = 0;
  76.     private int end_second = General.random(1, 59);
  77.    
  78.     private enum State {
  79.         NOTHING,WALK_LOG,CLIMB_NET,CLIMB_TREE_UP,WALK_ROPE,CLIMB_DOWN,CLIMB_NET_2,SQUEEZE_PIPE
  80.     }
  81.    
  82.     private State getState()
  83.     {
  84.        
  85.         if(end_after_time)
  86.         {
  87.             if((hours == end_hour && minutes >= end_minute && seconds >= end_second) || (hours >= end_hour && minutes > end_minute) || (hours > end_hour))
  88.             {
  89.                 System.out.println("Ending script...");
  90.                 while(Login.getLoginState() == Login.STATE.INGAME)
  91.                 {
  92.                     Login.logout();
  93.                     sleep(500,5000);
  94.                     if(Login.getLoginState() != Login.STATE.INGAME) break;
  95.                 }
  96.                 System.out.println("Logged out & Ended script...");
  97.                 this.stopScript();
  98.             }
  99.         }
  100.        
  101.         RSTile pos = Player.getPosition();
  102.         if(pos.getY() > 3433 && !Player.isMoving() && Player.getAnimation() < 1)
  103.         return State.WALK_LOG;
  104.         if(pos.getX() == 2474 && Player.isMoving() && pos.getY() > 3429 && pos.getY() < 3436)
  105.         {   setCameraAngle(0); return State.NOTHING;}
  106.         if(pos.getY() > 3424 && pos.getY() < 3433 && pos.getX() < 2478 && !Player.isMoving() && Player.getAnimation() < 1)
  107.         return State.CLIMB_NET;
  108.         if(pos.getX() > 2470 && pos.getX() < 2477 && pos.getY() > 3421 && pos.getY() < 3425  && !Player.isMoving() && Player.getAnimation() < 1)
  109.         return State.CLIMB_TREE_UP;
  110.         if(pos.getX() > 2471 && pos.getX() < 2478 && pos.getY() > 3417 && pos.getY() < 3422 && !Player.isMoving() && Player.getAnimation() < 1)
  111.         return State.WALK_ROPE;
  112.         if(pos.getX() > 2482 && pos.getX() < 2489 && pos.getY() > 3417 && pos.getY() < 3422 && !Player.isMoving() && Player.getAnimation() < 1 && Player.getPosition().getPlane() != 0)
  113.         return State.CLIMB_DOWN;
  114.         if(((pos.getX() != 2483 || pos.getX() != 2482) && pos.getY() != 3420) && pos.getX() > 2482 && pos.getX() < 2489 && pos.getY() > 3417 && pos.getY() < 3422 && Player.isMoving()   && Player.getPosition().getPlane() != 0)
  115.         setCameraAngle(2);
  116.         if(pos.getY() == 3420 && Player.isMoving() && pos.getX() < 2483 && pos.getX() >  2478)
  117.         {   setCameraAngle(1); return State.NOTHING;}
  118.         if(pos.getX() > 2481 && pos.getX() < 2490 && pos.getY() > 3413 && pos.getY() < 3426 && !Player.isMoving() && Player.getAnimation() < 1 && Player.getPosition().getPlane() == 0)
  119.         return State.CLIMB_NET_2;
  120.         if(pos.getX() > 2481 && pos.getX() < 2491 && pos.getY() > 3425 && pos.getY() < 3434 && pos.getY() != 3433 && !Player.isMoving() && Player.getAnimation() < 1)
  121.         return State.SQUEEZE_PIPE;
  122.         if(pos.getX() == 2484 && pos.getY() > 3430 && pos.getY() < 3437 && Player.isMoving())
  123.         { setCameraAngle(3); return State.NOTHING;}
  124.         return State.NOTHING;
  125.     }
  126.     @Override
  127.     public void run()  
  128.     {
  129.         DAntiban.setPrintDebug(true);
  130.         Mouse.setSpeed(General.random(160, 170));
  131.         g.setVisible(true);
  132.         latestNews = Newsloader.getNews();
  133.         while(GUIWait == true)
  134.         {
  135.             sleep(500);
  136.             if(!GUIWait) continue;
  137.         }
  138.         while(true)
  139.         {
  140.             loop();
  141.         }
  142.        
  143.     }
  144.    
  145.     private void setCameraAngle(int id)
  146.     {
  147.         switch(id)
  148.         {
  149.             case 0:
  150.                 if(Camera.getCameraAngle() < 65 || Camera.getCameraAngle() > 75) Camera.setCameraAngle(General.random(67, 73));
  151.                 if(Camera.getCameraRotation() < 170 || Camera.getCameraRotation() > 190) Camera.setCameraRotation(General.random(175, 185));
  152.             break;
  153.            
  154.             case 1:
  155.                 if(Camera.getCameraAngle() < 95) Camera.setCameraAngle(100);
  156.                 if(Camera.getCameraRotation() < 260 || Camera.getCameraRotation() > 280) Camera.setCameraRotation(General.random(265, 275));
  157.             break;
  158.            
  159.             case 2:
  160.                 if(Camera.getCameraAngle() < 35 || Camera.getCameraAngle() > 45) Camera.setCameraAngle(General.random(35, 45));
  161.                 if(Camera.getCameraRotation() < -10 || Camera.getCameraRotation() > 10) Camera.setCameraRotation(General.random(-5, 5));
  162.             break;
  163.            
  164.             case 3:
  165.                 if(Camera.getCameraAngle() < 95) Camera.setCameraAngle(100);
  166.                 if(Camera.getCameraRotation() < -10 || Camera.getCameraRotation() > 10) Camera.setCameraRotation(General.random(-5, 5));
  167.             break;
  168.         }
  169.     }
  170.     void loop()
  171.     {
  172.         scriptState = getState();
  173.         DAntiban.activateRun();
  174.         DAntiban.timedActions();
  175.         switch(scriptState)
  176.         {
  177.         case WALK_LOG:
  178.             RSObject[] log = Objects.getAt(new RSTile(2474,3435,0));
  179.             if(log[0] != null && !log[0].isOnScreen())
  180.             DAntiban.goToAnticipated(new RSTile(2474,3437,0));
  181.             DynamicClicking.clickRSObject(log[0], "Walk-across");
  182.             goSleep(1800);
  183.             break;
  184.            
  185.         case CLIMB_NET:
  186.             RSObject[] net_one = Objects.findNearest(8,"Obstacle net");
  187.             RSObject to_use = null;
  188.             if(net_one.length > 0) to_use = DAntiban.selectNextTarget(net_one);
  189.             if(to_use != null) DynamicClicking.clickRSObject(to_use, "Climb-over");
  190.             count_lap = true;
  191.             goSleep(1000);
  192.             break;
  193.            
  194.         case CLIMB_TREE_UP:
  195.             RSObject[] tree_up = Objects.getAt(new RSTile(2473,3422,1));
  196.             if(tree_up.length > 0) DynamicClicking.clickRSObject(tree_up[0], "Climb");
  197.             goSleep(1000);
  198.             break;
  199.            
  200.         case WALK_ROPE:
  201.             RSObject[] rope = Objects.getAt(new RSTile(2478,3420,2));
  202.             if(rope[0] != null && rope.length > 0)  DynamicClicking.clickRSObject(rope[0], "Walk-on");
  203.             goSleep(2000);
  204.             break;
  205.            
  206.         case CLIMB_DOWN:
  207.             RSObject[] tree_down = Objects.getAt(new RSTile(2486,3419,2));
  208.             if(tree_down.length > 0) DynamicClicking.clickRSObject(tree_down[0], "Climb-down");
  209.             goSleep(1000);
  210.             break;
  211.            
  212.         case CLIMB_NET_2:
  213.             RSObject[] net_two = Objects.findNearest(9, "Obstacle net");
  214.             RSObject net_to_use = null;
  215.             if(net_two.length > 0)
  216.                 {
  217.                 net_to_use = DAntiban.selectNextTarget(net_two);
  218.                     if(!net_to_use.getPosition().isOnScreen()) DAntiban.goToAnticipated(new RSTile(2485,3423,0));
  219.                     DynamicClicking.clickRSObject(net_two[0], "Climb-over");
  220.                 }
  221.             goSleep(1000);
  222.             break;
  223.            
  224.         case SQUEEZE_PIPE:
  225.             RSObject[] pipe = Objects.findNearest(10, "Obstacle pipe");
  226.             RSObject pipe_to_use = null;
  227.             if(pipe.length > 0)
  228.                 {
  229.                     pipe_to_use = DAntiban.selectNextTarget(pipe);
  230.                     if(pipe_to_use != null)
  231.                     {
  232.                         DynamicClicking.clickRSObject(pipe_to_use, "Squeeze-through");
  233.                         if(count_lap) laps_ran++;
  234.                     }
  235.                 }
  236.             goSleep(2000);
  237.             break;
  238.         }
  239.     }
  240.     /**
  241.      * @param max_duration is the maximum estimated time to finish what we are doing
  242.      */
  243.     private void goSleep(int max_duration)
  244.     {
  245.         if(use_abcv2)
  246.         {
  247.             DAntiban.generateTrackers(max_duration);
  248.             DAntiban.sleepReactionTime();
  249.             DAntiban.timedActions();
  250.         }
  251.         else
  252.         {
  253.             DAntiban.smartSleep(max_duration);
  254.             DAntiban.timedActions();
  255.         }
  256.     }
  257.    
  258.     int newsToShow = 0;
  259.    
  260.     private void getnewsdata()
  261.     {
  262.         int newsTimer = (int) (System.currentTimeMillis() - startNewsTime) / 1000;
  263.         if(newsTimer > 8)
  264.         {
  265.             startNewsTime = System.currentTimeMillis();
  266.             if(newsToShow == (latestNews.size() -1)) newsToShow = 0;
  267.             else if(newsToShow < (latestNews.size())) newsToShow++;
  268.            
  269.         }
  270.        
  271.     }
  272.    
  273.     long curr_xp = 0;
  274.     int timeRan = 0;
  275.     double multiplier = 0;
  276.     int laps_PH = 0;
  277.     int hours = 0;
  278.     int minutes = 0;
  279.     int seconds = 0;
  280.    
  281.     private void calculatePaint()
  282.     {
  283.         curr_xp = Skills.getXP(SKILLS.AGILITY) - Start_XP;
  284.         timeRan = (int) (System.currentTimeMillis() - startTime);
  285.         multiplier = timeRan / 3600000D;
  286.         laps_PH = (int) (laps_ran / multiplier);
  287.         hours = timeRan / 3600000;
  288.         timeRan = timeRan - (hours*3600000);
  289.         minutes = timeRan / 60000;
  290.         timeRan = timeRan - (minutes*60000);
  291.         seconds = timeRan / 1000;
  292.         timeRan = timeRan - (seconds*1000);
  293.     }
  294.    
  295.     private Image getImage(String url)
  296.     {
  297.         try
  298.         {
  299.             return ImageIO.read(new URL(url));
  300.         }
  301.         catch(IOException e)
  302.         {
  303.             return null;
  304.         }
  305.     }
  306.    
  307.    
  308.     private final Image dchickenspaintimg = getImage("http://d-scripting.com/DEssentials/paint/dgnomeagilitypaint.png");
  309.     private final RenderingHints aa = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  310.     private final Color darkred = new Color(193,48,38);
  311.     int paintOffset = 320;
  312.    
  313.     @Override
  314.     public void onPaint(Graphics g)
  315.     {
  316.         getnewsdata();
  317.         calculatePaint();
  318.         Graphics2D g2 = (Graphics2D)g;
  319.         g2.setRenderingHints(aa);
  320.         g2.drawImage(dchickenspaintimg, 0, paintOffset, null);
  321.          g.setColor(Color.CYAN);
  322.          g.setFont(font3);
  323.         if(newsToShow < (latestNews.size())) g.drawString("NEWS: "+ latestNews.get(newsToShow), 40,40);
  324.         g.setColor(darkred);
  325.         g.setFont(font2);
  326.         g.drawString("time ran: "+ hours + ":" + minutes + ":" + seconds, 5,paintOffset+60);
  327.         g.drawString("xp gained: "+ curr_xp, 5,paintOffset+75);
  328.         g.drawString("Laps ran "+ laps_ran +" Laps P/H: "+laps_PH, 5,paintOffset+90);
  329.         g.drawString("Using ABCv2: "+use_abcv2, 5,paintOffset+105);
  330.         g.drawString("Debug : "+scriptState, 5,paintOffset+120);
  331.         if(end_after_time) g.drawString("Ending script when we ran "+(end_hour)+":"+(end_minute)+":"+(end_second)+" (HH:MM:SS)", 5,paintOffset+135);
  332.         if(!end_after_time) g.drawString("Not using End-timer", 5,paintOffset+135);
  333.         g.drawString("Version: 1.01", 5,paintOffset+160);
  334.        
  335.     }
  336.    
  337.     public class GUI extends JFrame {
  338.         public GUI() {
  339.             initComponents();
  340.         }
  341.  
  342.         private void thedtribotActionPerformed(ActionEvent e) {
  343.             openSite("https://tribot.org/forums/profile/8498-thed/");
  344.         }
  345.  
  346.         private void dscriptingcomActionPerformed(ActionEvent e) {
  347.             openSite("http://d-scripting.com");
  348.         }
  349.  
  350.         private void moredscriptsActionPerformed(ActionEvent e) {
  351.             openSite("http://d-scripting.com/more");
  352.         }
  353.  
  354.         private void okButtonActionPerformed(ActionEvent e) {
  355.             GUIWait = false;
  356.             use_abcv2 = abcv2reactions.isSelected();
  357.            
  358.             String whenToQuit = endscriptTimer.getSelectedItem().toString();
  359.             if(whenToQuit.startsWith("0."))
  360.             {
  361.                 end_after_time = false;
  362.             }
  363.             if(whenToQuit.startsWith("1."))
  364.             {
  365.                 end_after_time = true;
  366.                 end_hour = 1;
  367.                 end_minute = General.random(1, 59);
  368.             }
  369.             if(whenToQuit.startsWith("2."))
  370.             {
  371.                 end_after_time = true;
  372.                 end_hour = 2;
  373.                 end_minute = General.random(1, 59);
  374.             }
  375.             if(whenToQuit.startsWith("3."))
  376.             {
  377.                 end_after_time = true;
  378.                 end_hour = 3;
  379.                 end_minute = General.random(1, 59);
  380.             }
  381.             if(whenToQuit.startsWith("4."))
  382.             {
  383.                 end_after_time = true;
  384.                 end_hour = 4;
  385.                 end_minute = General.random(1, 59);
  386.             }
  387.             if(whenToQuit.startsWith("5."))
  388.             {
  389.                 end_after_time = true;
  390.                 end_hour = 5;
  391.                 end_minute = General.random(1, 59);
  392.             }
  393.             if(whenToQuit.startsWith("6."))
  394.             {
  395.                 end_after_time = true;
  396.                 end_hour = 6;
  397.                 end_minute = General.random(1, 59);
  398.             }
  399.             if(whenToQuit.startsWith("7."))
  400.             {
  401.                 end_after_time = true;
  402.                 end_hour = 7;
  403.                 end_minute = General.random(1, 59);
  404.             }
  405.             if(whenToQuit.startsWith("8."))
  406.             {
  407.                 end_after_time = true;
  408.                 end_hour = 8;
  409.                 end_minute = General.random(1, 59);
  410.             }
  411.             if(whenToQuit.startsWith("9."))
  412.             {
  413.                 end_after_time = true;
  414.                 end_hour = 9;
  415.                 end_minute = General.random(1, 59);
  416.             }
  417.             if(whenToQuit.startsWith("10."))
  418.             {
  419.                 end_after_time = true;
  420.                 end_hour = 10;
  421.                 end_minute = General.random(1, 59);
  422.             }
  423.             if(whenToQuit.startsWith("11."))
  424.             {
  425.                 end_after_time = true;
  426.                 end_hour = 11;
  427.                 end_minute = General.random(1, 59);
  428.             }
  429.             if(whenToQuit.startsWith("12."))
  430.             {
  431.                 end_after_time = true;
  432.                 end_hour = 12;
  433.                 end_minute = General.random(1, 59);
  434.             }
  435.            
  436.            
  437.             g.dispose();
  438.         }
  439.  
  440.         private void initComponents() {
  441.             //Init TheD
  442.             menuBar1 = new JMenuBar();
  443.             menu1 = new JMenu();
  444.             thedtribot = new JMenuItem();
  445.             dscriptingcom = new JMenuItem();
  446.             moredscripts = new JMenuItem();
  447.             dialogPane = new JPanel();
  448.             contentPanel = new JPanel();
  449.             label1 = new JLabel();
  450.             label2 = new JLabel();
  451.             abcv2reactions = new JCheckBox();
  452.             label3 = new JLabel();
  453.             endscriptTimer = new JComboBox<>();
  454.             label5 = new JLabel();
  455.             buttonBar = new JPanel();
  456.             okButton = new JButton();
  457.  
  458.             //======== this ========
  459.             setTitle("DScripts by TheD");
  460.             setAlwaysOnTop(true);
  461.             setResizable(false);
  462.             Container contentPane = getContentPane();
  463.             contentPane.setLayout(new BorderLayout());
  464.  
  465.             //======== menuBar1 ========
  466.             {
  467.  
  468.                 //======== menu1 ========
  469.                 {
  470.                     menu1.setText("General");
  471.  
  472.                     //---- thedtribot ----
  473.                     thedtribot.setText("TheD TRiBot Profile");
  474.                     thedtribot.addActionListener(e -> thedtribotActionPerformed(e));
  475.                     menu1.add(thedtribot);
  476.  
  477.                     //---- dscriptingcom ----
  478.                     dscriptingcom.setText("D-Scripting.com");
  479.                     dscriptingcom.addActionListener(e -> dscriptingcomActionPerformed(e));
  480.                     menu1.add(dscriptingcom);
  481.  
  482.                     //---- moredscripts ----
  483.                     moredscripts.setText("More DScripts");
  484.                     moredscripts.addActionListener(e -> moredscriptsActionPerformed(e));
  485.                     menu1.add(moredscripts);
  486.                 }
  487.                 menuBar1.add(menu1);
  488.             }
  489.             setJMenuBar(menuBar1);
  490.  
  491.             //======== dialogPane ========
  492.             {
  493.                 dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
  494.  
  495.                 // DScripting
  496.                 dialogPane.setBorder(new javax.swing.border.CompoundBorder(
  497.                     new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
  498.                         "DScripting Limited", javax.swing.border.TitledBorder.CENTER,
  499.                         javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 12),
  500.                         java.awt.Color.red), dialogPane.getBorder())); dialogPane.addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});
  501.  
  502.                 dialogPane.setLayout(new BorderLayout());
  503.  
  504.                 //======== contentPanel ========
  505.                 {
  506.  
  507.                     //---- label1 ----
  508.                     label1.setText("DGnomeAgility");
  509.                     label1.setFont(new Font("Tahoma", Font.PLAIN, 48));
  510.  
  511.                     //---- label2 ----
  512.                     label2.setText("Simple gnome agility course script, start anywhere on the route.");
  513.                     label2.setFont(new Font("Tahoma", Font.PLAIN, 12));
  514.  
  515.                     //---- abcv2reactions ----
  516.                     abcv2reactions.setText("Use ABCv2 Reaction times");
  517.                     abcv2reactions.setFont(new Font("Tahoma", Font.PLAIN, 12));
  518.  
  519.                     //---- label3 ----
  520.                     label3.setText("ABCv2 Reaction times make you slower, but it's safer to bot using it.");
  521.                     label3.setFont(new Font("Tahoma", Font.PLAIN, 12));
  522.  
  523.                     //---- endscriptTimer ----
  524.                     endscriptTimer.setFont(new Font("Tahoma", Font.PLAIN, 14));
  525.                     endscriptTimer.setModel(new DefaultComboBoxModel<>(new String[] {
  526.                         "0. Never",
  527.                         "1. 1 hour",
  528.                         "2. 2 hours",
  529.                         "3. 3 hours",
  530.                         "4. 4 hours",
  531.                         "5. 5 hours",
  532.                         "6. 6 hours",
  533.                         "7. 7 hours",
  534.                         "8. 8 hours",
  535.                         "9. 9 hours",
  536.                         "10. 10 hours",
  537.                         "11. 11 hours",
  538.                         "12. 12 hours"
  539.                     }));
  540.  
  541.                     //---- label5 ----
  542.                     label5.setText("End script after:");
  543.                     label5.setFont(new Font("Tahoma", Font.PLAIN, 14));
  544.  
  545.                     GroupLayout contentPanelLayout = new GroupLayout(contentPanel);
  546.                     contentPanel.setLayout(contentPanelLayout);
  547.                     contentPanelLayout.setHorizontalGroup(
  548.                         contentPanelLayout.createParallelGroup()
  549.                             .addGroup(contentPanelLayout.createSequentialGroup()
  550.                                 .addComponent(label1)
  551.                                 .addGap(0, 148, Short.MAX_VALUE))
  552.                             .addGroup(contentPanelLayout.createSequentialGroup()
  553.                                 .addContainerGap()
  554.                                 .addGroup(contentPanelLayout.createParallelGroup()
  555.                                     .addComponent(label2)
  556.                                     .addComponent(abcv2reactions)
  557.                                     .addComponent(label3)
  558.                                     .addGroup(contentPanelLayout.createSequentialGroup()
  559.                                         .addComponent(label5)
  560.                                         .addGap(45, 45, 45)
  561.                                         .addComponent(endscriptTimer, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
  562.                                 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  563.                     );
  564.                     contentPanelLayout.setVerticalGroup(
  565.                         contentPanelLayout.createParallelGroup()
  566.                             .addGroup(contentPanelLayout.createSequentialGroup()
  567.                                 .addComponent(label1)
  568.                                 .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  569.                                 .addComponent(label2)
  570.                                 .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
  571.                                 .addComponent(abcv2reactions)
  572.                                 .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
  573.                                 .addComponent(label3)
  574.                                 .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  575.                                 .addGroup(contentPanelLayout.createParallelGroup()
  576.                                     .addGroup(contentPanelLayout.createSequentialGroup()
  577.                                         .addGap(3, 3, 3)
  578.                                         .addComponent(label5))
  579.                                     .addComponent(endscriptTimer, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
  580.                                 .addGap(0, 24, Short.MAX_VALUE))
  581.                     );
  582.                 }
  583.                 dialogPane.add(contentPanel, BorderLayout.CENTER);
  584.  
  585.                 //======== buttonBar ========
  586.                 {
  587.                     buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
  588.                     buttonBar.setLayout(new GridBagLayout());
  589.                     ((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 80};
  590.                     ((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0};
  591.  
  592.                     //---- okButton ----
  593.                     okButton.setText("Start Script");
  594.                     okButton.addActionListener(e -> okButtonActionPerformed(e));
  595.                     buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
  596.                         GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  597.                         new Insets(0, 0, 0, 0), 0, 0));
  598.                 }
  599.                 dialogPane.add(buttonBar, BorderLayout.SOUTH);
  600.             }
  601.             contentPane.add(dialogPane, BorderLayout.CENTER);
  602.             pack();
  603.             setLocationRelativeTo(getOwner());
  604.             //End of component initialization
  605.         }
  606.  
  607.         private JMenuBar menuBar1;
  608.         private JMenu menu1;
  609.         private JMenuItem thedtribot;
  610.         private JMenuItem dscriptingcom;
  611.         private JMenuItem moredscripts;
  612.         private JPanel dialogPane;
  613.         private JPanel contentPanel;
  614.         private JLabel label1;
  615.         private JLabel label2;
  616.         private JCheckBox abcv2reactions;
  617.         private JLabel label3;
  618.         private JComboBox<String> endscriptTimer;
  619.         private JLabel label5;
  620.         private JPanel buttonBar;
  621.         private JButton okButton;
  622.         // end of gui
  623.     }
  624.  
  625.  
  626.     void openSite(String url)
  627.     {
  628.         System.out.println("Open site");
  629.          URL a = null;
  630.             try {
  631.                 a = new URL(url);
  632.             } catch (MalformedURLException e1) {
  633.                 System.out.println("ERROR OPENING URL");
  634.                 e1.printStackTrace();
  635.             }
  636.             openWebpage(a);
  637.     }  
  638.      
  639.         public void openWebpage(URI uri) {
  640.             System.out.println("Open webpage");
  641.             if(Desktop.isDesktopSupported())
  642.             {
  643.                 Desktop desktop = Desktop.getDesktop();
  644.                 if (desktop != null) {
  645.                 try {
  646.                         desktop.browse(uri);
  647.                     } catch (Exception e) {
  648.                         e.printStackTrace();
  649.                     }
  650.                 }
  651.             }
  652.         }
  653.  
  654.         public void openWebpage(URL url) {
  655.             try {
  656.                 openWebpage(url.toURI());
  657.             } catch (URISyntaxException e) {
  658.                 e.printStackTrace();
  659.             }
  660.         }
  661. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement