Advertisement
Guest User

Untitled

a guest
Mar 14th, 2014
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 33.48 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package javaapplication3;
  7.  
  8. import java.awt.Color;
  9. import java.awt.Cursor;
  10. import java.awt.Dimension;
  11. import java.awt.GraphicsEnvironment;
  12. import java.awt.Point;
  13. import java.awt.Rectangle;
  14. import java.awt.Toolkit;
  15. import java.awt.event.ActionEvent;
  16. import java.awt.event.ActionListener;
  17. import java.awt.event.MouseEvent;
  18. import java.awt.event.MouseListener;
  19. import java.awt.event.MouseMotionListener;
  20. import javax.swing.JFrame;
  21. import javax.swing.JPanel;
  22. import javax.swing.JTextField;
  23. import javax.swing.Timer;
  24.  
  25. /**
  26.  *
  27.  * @author Suporte01
  28.  */
  29. public class NewJFrame extends javax.swing.JFrame implements MouseMotionListener, MouseListener {
  30.  
  31.     /**
  32.      * |--------------------------------------------------------------------------
  33.      * | Resizableframe vars
  34.      * |--------------------------------------------------------------------------
  35.      */
  36.     private static final long serialVersionUID = 1L;
  37.     private Point start_drag;
  38.     private Point start_loc;
  39.     private Point precedent_loc;
  40.     private int precedent_width;
  41.     private int precedent_height;
  42.     Toolkit toolkit = Toolkit.getDefaultToolkit();
  43.     private int minWidth;
  44.     private int minHeight;
  45.     private Point initialLocation;
  46.     int cursorArea = 5;
  47.     Rectangle screen = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
  48.     private int DIFF_MIN_WIDTH = 30;
  49.     private int DIFF_MIN_HEIGHT = 30;
  50.  
  51.     /**
  52.      * |--------------------------------------------------------------------------
  53.      * | Tempos
  54.      * |--------------------------------------------------------------------------
  55.      */
  56.     private static Contador tempoBlueBGolem;
  57.     private static Contador tempoBlueLizard;
  58.     private static Contador tempoBlueWi;
  59.     private static Contador tempoBlueDGolem;
  60.     private static Contador tempoBlueWolf;
  61.     private static Contador tempoBlueWr;
  62.     private static Contador tempoBaron;
  63.     private static Contador tempoDragon;
  64.  
  65.     /**
  66.      * |--------------------------------------------------------------------------
  67.      * | Action Listeners
  68.      * |--------------------------------------------------------------------------
  69.      */
  70.     public static ActionListener alblueBGolem = new ActionListener() {
  71.         public void actionPerformed(ActionEvent evt) {
  72.             count(blueBGolem, timerBlueBGolem, tempoBlueBGolem, 1);
  73.         }
  74.     };
  75.     public static ActionListener alblueLizard = new ActionListener() {
  76.         public void actionPerformed(ActionEvent evt) {
  77.             count(blueLizard, timerBlueLizard, tempoBlueLizard, 1);
  78.         }
  79.     };
  80.     public static ActionListener alblueWi = new ActionListener() {
  81.         public void actionPerformed(ActionEvent evt) {
  82.             count(blueWi, timerBlueWi, tempoBlueWi, 0);
  83.         }
  84.     };
  85.     public static ActionListener alblueDGolem = new ActionListener() {
  86.         public void actionPerformed(ActionEvent evt) {
  87.             count(blueDGolem, timerBlueDGolem, tempoBlueDGolem, 0);
  88.         }
  89.     };
  90.     public static ActionListener alblueWolf = new ActionListener() {
  91.         public void actionPerformed(ActionEvent evt) {
  92.             count(blueWolf, timerBlueWolf, tempoBlueWolf, 0);
  93.         }
  94.     };
  95.     public static ActionListener alblueWr = new ActionListener() {
  96.         public void actionPerformed(ActionEvent evt) {
  97.             count(blueWr, timerBlueWr, tempoBlueWr, 0);
  98.         }
  99.     };
  100.     public static ActionListener alDragon = new ActionListener() {
  101.         public void actionPerformed(ActionEvent evt) {
  102.             count(Dragon, timerDragon, tempoDragon, 2);
  103.         }
  104.     };
  105.     public static ActionListener alBaron = new ActionListener() {
  106.         public void actionPerformed(ActionEvent evt) {
  107.             count(Baron, timerBaron, tempoBaron, 3);
  108.         }
  109.     };
  110.  
  111.     /**
  112.      * |--------------------------------------------------------------------------
  113.      * | Timers
  114.      * |--------------------------------------------------------------------------
  115.      */
  116.     private static Timer timerBlueBGolem = new Timer(1000, alblueBGolem);
  117.     private static Timer timerBlueLizard = new Timer(1000, alblueLizard);
  118.     private static Timer timerBlueWi = new Timer(1000, alblueWi);
  119.     private static Timer timerBlueDGolem = new Timer(1000, alblueDGolem);
  120.     private static Timer timerBlueWolf = new Timer(1000, alblueWolf);
  121.     private static Timer timerBlueWr = new Timer(1000, alblueWr);
  122.     private static Timer timerBaron = new Timer(1000, alBaron);
  123.     private static Timer timerDragon = new Timer(1000, alDragon);
  124.  
  125.     ;      
  126.      
  127.     /**
  128.      * Creates new form NewJFrame
  129.      */
  130.     public NewJFrame(Dimension initialDimension, Point initialLocation) {
  131.         this.initialLocation = initialLocation;
  132.         minWidth = (int) initialDimension.getWidth();
  133.         minHeight = (int) initialDimension.getHeight();
  134.         Init();
  135.         initComponents();
  136.         setBackground(new Color(1.0f, 1.0f, 1.0f, 0f));
  137.         Move.setBackground(new Color(1.0f, 1.0f, 1.0f, 0f));
  138.     }
  139.  
  140.     private void Init() {
  141.         tempoBlueBGolem = new Contador(300);
  142.         tempoBlueLizard = new Contador(300);
  143.         tempoBlueWi = new Contador(50);
  144.         tempoBlueDGolem = new Contador(50);
  145.         tempoBlueWolf = new Contador(50);
  146.         tempoBlueWr = new Contador(50);
  147.         tempoBaron = new Contador(420);
  148.         tempoDragon = new Contador(360);
  149.  
  150.         addMouseMotionListener(this);
  151.         addMouseListener(this);
  152.         this.setSize(minWidth, minHeight);
  153.  
  154.         minWidth -= DIFF_MIN_WIDTH;
  155.         minHeight -= DIFF_MIN_HEIGHT;
  156.  
  157.         setLocation(initialLocation);
  158.     }
  159.  
  160.     /**
  161.      * This method is called from within the constructor to initialize the form.
  162.      * WARNING: Do NOT modify this code. The content of this method is always
  163.      * regenerated by the Form Editor.
  164.      */
  165.     @SuppressWarnings("unchecked")
  166.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  167.     private void initComponents() {
  168.  
  169.         Painel = new javax.swing.JPanel();
  170.         blueBGolem = new javax.swing.JTextField();
  171.         blueBGolemStart = new javax.swing.JButton();
  172.         blueLizardStart = new javax.swing.JButton();
  173.         blueWiStart = new javax.swing.JButton();
  174.         blueDGolemStart = new javax.swing.JButton();
  175.         blueWolfStart = new javax.swing.JButton();
  176.         blueWrStart = new javax.swing.JButton();
  177.         DragonStart = new javax.swing.JButton();
  178.         BaronStart = new javax.swing.JButton();
  179.         jButton7 = new javax.swing.JButton();
  180.         Move = new javax.swing.JPanel();
  181.         jLabel1 = new javax.swing.JLabel();
  182.         jButton9 = new javax.swing.JButton();
  183.         jButton1 = new javax.swing.JButton();
  184.         jTextField1 = new javax.swing.JTextField();
  185.  
  186.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  187.         setAlwaysOnTop(true);
  188.         setUndecorated(true);
  189.  
  190.         Painel.setBackground(new java.awt.Color(112, 112, 112));
  191.         Painel.setOpaque(false);
  192.         Painel.setLayout(null);
  193.  
  194.         blueBGolem.setEditable(false);
  195.         blueBGolem.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  196.         blueBGolem.setForeground(new java.awt.Color(255, 255, 255));
  197.         blueBGolem.setHorizontalAlignment(javax.swing.JTextField.CENTER);
  198.         blueBGolem.setText("5:00");
  199.         blueBGolem.setOpaque(false);
  200.         blueBGolem.addActionListener(new java.awt.event.ActionListener() {
  201.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  202.                 blueBGolemActionPerformed(evt);
  203.             }
  204.         });
  205.         Painel.add(blueBGolem);
  206.         blueBGolem.setBounds(0, 30, 70, 20);
  207.  
  208.         blueBGolemStart.setIcon(new javax.swing.ImageIcon(getClass().getResource("/javaapplication3/bluegolem.jpg"))); // NOI18N
  209.         blueBGolemStart.setBorderPainted(false);
  210.         blueBGolemStart.setContentAreaFilled(false);
  211.         blueBGolemStart.setFocusPainted(false);
  212.         blueBGolemStart.setFocusable(false);
  213.         blueBGolemStart.setMaximumSize(new java.awt.Dimension(75, 25));
  214.         blueBGolemStart.setMinimumSize(new java.awt.Dimension(75, 25));
  215.         blueBGolemStart.addActionListener(new java.awt.event.ActionListener() {
  216.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  217.                 blueBGolemStartActionPerformed(evt);
  218.             }
  219.         });
  220.         Painel.add(blueBGolemStart);
  221.         blueBGolemStart.setBounds(0, 0, 73, 23);
  222.  
  223.         blueLizardStart.setIcon(new javax.swing.ImageIcon(getClass().getResource("/javaapplication3/lizard.jpg"))); // NOI18N
  224.         blueLizardStart.setBorderPainted(false);
  225.         blueLizardStart.setContentAreaFilled(false);
  226.         blueLizardStart.setFocusPainted(false);
  227.         blueLizardStart.setFocusable(false);
  228.         blueLizardStart.setMaximumSize(new java.awt.Dimension(75, 25));
  229.         blueLizardStart.setMinimumSize(new java.awt.Dimension(75, 25));
  230.         blueLizardStart.addActionListener(new java.awt.event.ActionListener() {
  231.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  232.                 blueLizardStartActionPerformed(evt);
  233.             }
  234.         });
  235.         Painel.add(blueLizardStart);
  236.         blueLizardStart.setBounds(70, 0, 73, 23);
  237.  
  238.         blueWiStart.setIcon(new javax.swing.ImageIcon(getClass().getResource("/javaapplication3/wi.jpg"))); // NOI18N
  239.         blueWiStart.setBorderPainted(false);
  240.         blueWiStart.setContentAreaFilled(false);
  241.         blueWiStart.setFocusPainted(false);
  242.         blueWiStart.setFocusable(false);
  243.         blueWiStart.setMaximumSize(new java.awt.Dimension(75, 25));
  244.         blueWiStart.setMinimumSize(new java.awt.Dimension(75, 25));
  245.         blueWiStart.addActionListener(new java.awt.event.ActionListener() {
  246.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  247.                 blueWiStartActionPerformed(evt);
  248.             }
  249.         });
  250.         Painel.add(blueWiStart);
  251.         blueWiStart.setBounds(140, 0, 73, 23);
  252.  
  253.         blueDGolemStart.setIcon(new javax.swing.ImageIcon(getClass().getResource("/javaapplication3/golem.jpg"))); // NOI18N
  254.         blueDGolemStart.setBorderPainted(false);
  255.         blueDGolemStart.setContentAreaFilled(false);
  256.         blueDGolemStart.setFocusPainted(false);
  257.         blueDGolemStart.setFocusable(false);
  258.         blueDGolemStart.setMaximumSize(new java.awt.Dimension(75, 25));
  259.         blueDGolemStart.setMinimumSize(new java.awt.Dimension(75, 25));
  260.         blueDGolemStart.addActionListener(new java.awt.event.ActionListener() {
  261.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  262.                 blueDGolemStartActionPerformed(evt);
  263.             }
  264.         });
  265.         Painel.add(blueDGolemStart);
  266.         blueDGolemStart.setBounds(210, 0, 73, 23);
  267.  
  268.         blueWolfStart.setIcon(new javax.swing.ImageIcon(getClass().getResource("/javaapplication3/wolf.jpg"))); // NOI18N
  269.         blueWolfStart.setBorderPainted(false);
  270.         blueWolfStart.setContentAreaFilled(false);
  271.         blueWolfStart.setFocusPainted(false);
  272.         blueWolfStart.setFocusable(false);
  273.         blueWolfStart.setMaximumSize(new java.awt.Dimension(75, 25));
  274.         blueWolfStart.setMinimumSize(new java.awt.Dimension(75, 25));
  275.         blueWolfStart.addActionListener(new java.awt.event.ActionListener() {
  276.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  277.                 blueWolfStartActionPerformed(evt);
  278.             }
  279.         });
  280.         Painel.add(blueWolfStart);
  281.         blueWolfStart.setBounds(280, 0, 73, 23);
  282.  
  283.         blueWrStart.setIcon(new javax.swing.ImageIcon(getClass().getResource("/javaapplication3/wr.jpg"))); // NOI18N
  284.         blueWrStart.setBorderPainted(false);
  285.         blueWrStart.setContentAreaFilled(false);
  286.         blueWrStart.setFocusPainted(false);
  287.         blueWrStart.setFocusable(false);
  288.         blueWrStart.setMaximumSize(new java.awt.Dimension(75, 25));
  289.         blueWrStart.setMinimumSize(new java.awt.Dimension(75, 25));
  290.         blueWrStart.addActionListener(new java.awt.event.ActionListener() {
  291.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  292.                 blueWrStartActionPerformed(evt);
  293.             }
  294.         });
  295.         Painel.add(blueWrStart);
  296.         blueWrStart.setBounds(350, 0, 73, 23);
  297.  
  298.         DragonStart.setIcon(new javax.swing.ImageIcon(getClass().getResource("/javaapplication3/dragon.jpg"))); // NOI18N
  299.         DragonStart.setBorderPainted(false);
  300.         DragonStart.setContentAreaFilled(false);
  301.         DragonStart.setFocusPainted(false);
  302.         DragonStart.setFocusable(false);
  303.         DragonStart.setMaximumSize(new java.awt.Dimension(75, 25));
  304.         DragonStart.setMinimumSize(new java.awt.Dimension(75, 25));
  305.         DragonStart.addActionListener(new java.awt.event.ActionListener() {
  306.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  307.                 DragonStartActionPerformed(evt);
  308.             }
  309.         });
  310.         Painel.add(DragonStart);
  311.         DragonStart.setBounds(420, 0, 73, 23);
  312.  
  313.         BaronStart.setIcon(new javax.swing.ImageIcon(getClass().getResource("/javaapplication3/baron.jpg"))); // NOI18N
  314.         BaronStart.setBorderPainted(false);
  315.         BaronStart.setContentAreaFilled(false);
  316.         BaronStart.setMaximumSize(new java.awt.Dimension(75, 25));
  317.         BaronStart.setMinimumSize(new java.awt.Dimension(75, 25));
  318.         BaronStart.addActionListener(new java.awt.event.ActionListener() {
  319.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  320.                 BaronStartActionPerformed(evt);
  321.             }
  322.         });
  323.         Painel.add(BaronStart);
  324.         BaronStart.setBounds(490, 0, 73, 23);
  325.  
  326.         jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/javaapplication3/reset.png"))); // NOI18N
  327.         jButton7.setBorderPainted(false);
  328.         jButton7.setContentAreaFilled(false);
  329.         jButton7.setFocusPainted(false);
  330.         jButton7.setFocusable(false);
  331.         jButton7.setMaximumSize(new java.awt.Dimension(75, 25));
  332.         jButton7.setMinimumSize(new java.awt.Dimension(75, 25));
  333.         jButton7.addActionListener(new java.awt.event.ActionListener() {
  334.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  335.                 jButton7ActionPerformed(evt);
  336.             }
  337.         });
  338.         Painel.add(jButton7);
  339.         jButton7.setBounds(620, 30, 73, 23);
  340.  
  341.         jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/javaapplication3/move.png"))); // NOI18N
  342.  
  343.         javax.swing.GroupLayout MoveLayout = new javax.swing.GroupLayout(Move);
  344.         Move.setLayout(MoveLayout);
  345.         MoveLayout.setHorizontalGroup(
  346.             MoveLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  347.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, MoveLayout.createSequentialGroup()
  348.                 .addGap(0, 0, Short.MAX_VALUE)
  349.                 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
  350.         );
  351.         MoveLayout.setVerticalGroup(
  352.             MoveLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  353.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, MoveLayout.createSequentialGroup()
  354.                 .addGap(0, 0, Short.MAX_VALUE)
  355.                 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
  356.         );
  357.  
  358.         Painel.add(Move);
  359.         Move.setBounds(570, 0, 50, 30);
  360.  
  361.         jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/javaapplication3/spawn.png"))); // NOI18N
  362.         jButton9.setBorderPainted(false);
  363.         jButton9.setContentAreaFilled(false);
  364.         jButton9.setFocusPainted(false);
  365.         jButton9.setFocusable(false);
  366.         jButton9.setMaximumSize(new java.awt.Dimension(75, 25));
  367.         jButton9.setMinimumSize(new java.awt.Dimension(75, 25));
  368.         Painel.add(jButton9);
  369.         jButton9.setBounds(550, 30, 73, 23);
  370.  
  371.         jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/javaapplication3/fechar.png"))); // NOI18N
  372.         jButton1.setBorderPainted(false);
  373.         jButton1.setContentAreaFilled(false);
  374.         jButton1.setFocusPainted(false);
  375.         jButton1.setFocusable(false);
  376.         jButton1.setMaximumSize(new java.awt.Dimension(75, 25));
  377.         jButton1.setMinimumSize(new java.awt.Dimension(75, 25));
  378.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  379.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  380.                 jButton1ActionPerformed(evt);
  381.             }
  382.         });
  383.         Painel.add(jButton1);
  384.         jButton1.setBounds(630, 0, 50, 30);
  385.  
  386.         jTextField1.setText("jTextField1");
  387.         Painel.add(jTextField1);
  388.         jTextField1.setBounds(430, 30, 59, 20);
  389.  
  390.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  391.         getContentPane().setLayout(layout);
  392.         layout.setHorizontalGroup(
  393.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  394.             .addComponent(Painel, javax.swing.GroupLayout.DEFAULT_SIZE, 685, Short.MAX_VALUE)
  395.         );
  396.         layout.setVerticalGroup(
  397.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  398.             .addComponent(Painel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
  399.         );
  400.  
  401.         pack();
  402.     }// </editor-fold>                        
  403.  
  404.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  405.         System.exit(0);
  406.     }                                        
  407.  
  408.     private void blueBGolemStartActionPerformed(java.awt.event.ActionEvent evt) {                                                
  409.         //timerBlueBGolem.start();
  410.         blueBGolem.setText("ooi");
  411.     }                                              
  412.  
  413.     private void blueLizardStartActionPerformed(java.awt.event.ActionEvent evt) {                                                
  414.         timerBlueLizard.start();
  415.     }                                              
  416.  
  417.     private void blueWiStartActionPerformed(java.awt.event.ActionEvent evt) {                                            
  418.         timerBlueWi.start();
  419.     }                                          
  420.  
  421.     private void blueDGolemStartActionPerformed(java.awt.event.ActionEvent evt) {                                                
  422.         timerBlueDGolem.start();
  423.     }                                              
  424.  
  425.     private void blueWolfStartActionPerformed(java.awt.event.ActionEvent evt) {                                              
  426.         timerBlueWolf.start();
  427.     }                                            
  428.  
  429.     private void blueWrStartActionPerformed(java.awt.event.ActionEvent evt) {                                            
  430.         timerBlueWr.start();
  431.     }                                          
  432.  
  433.     private void DragonStartActionPerformed(java.awt.event.ActionEvent evt) {                                            
  434.         //timerDragon.start();
  435.         jTextField1.setText("oooi");
  436.     }                                          
  437.  
  438.     private void BaronStartActionPerformed(java.awt.event.ActionEvent evt) {                                          
  439.         timerBaron.start();
  440.     }                                          
  441.  
  442.     private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  443.         timerBlueBGolem.stop();
  444.         timerBlueLizard.stop();
  445.         timerBlueWi.stop();
  446.         timerBlueDGolem.stop();
  447.         timerBlueWolf.stop();
  448.         timerBlueWr.stop();
  449.         timerBaron.stop();
  450.         timerDragon.stop();
  451.         tempoBlueBGolem.set(115);
  452.         tempoBlueLizard.set(115);
  453.         tempoBlueWi.set(115);
  454.         tempoBlueDGolem.set(115);
  455.         tempoBlueWolf.set(115);
  456.         tempoBlueWr.set(115);
  457.         tempoDragon.set(300);
  458.         tempoBaron.set(720);
  459.     }                                        
  460.  
  461.     private void blueBGolemActionPerformed(java.awt.event.ActionEvent evt) {                                          
  462.         // TODO add your handling code here:
  463.     }                                          
  464.  
  465.     public static Point getScreenLocation(MouseEvent e, JFrame frame) {
  466.         Point cursor = e.getPoint();
  467.         Point view_location = frame.getLocationOnScreen();
  468.         return new Point((int) (view_location.getX() + cursor.getX()),
  469.                 (int) (view_location.getY() + cursor.getY()));
  470.     }
  471.  
  472.     @Override
  473.     public void mouseDragged(MouseEvent e) {
  474.         moveOrFullResizeFrame(e);
  475.     }
  476.  
  477.     @Override
  478.     public void mouseMoved(MouseEvent e) {
  479.         Point cursorLocation = e.getPoint();
  480.         int xPos = cursorLocation.x;
  481.         int yPos = cursorLocation.y;
  482.  
  483.         if (xPos >= cursorArea && xPos <= getWidth() - cursorArea && yPos >= getHeight() - cursorArea) {
  484.             setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
  485.         } else if (xPos >= getWidth() - cursorArea && yPos >= cursorArea && yPos <= getHeight() - cursorArea) {
  486.             setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
  487.         } else if (xPos <= cursorArea && yPos >= cursorArea && yPos <= getHeight() - cursorArea) {
  488.             setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
  489.         } else if (xPos >= cursorArea && xPos <= getWidth() - cursorArea && yPos <= cursorArea) {
  490.             setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));
  491.         } else if (xPos <= cursorArea && yPos <= cursorArea) {
  492.             setCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));
  493.         } else if (xPos >= getWidth() - cursorArea && yPos <= cursorArea) {
  494.             setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
  495.         } else if (xPos >= getWidth() - cursorArea && yPos >= getHeight() - cursorArea) {
  496.             setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
  497.         } else if (xPos <= cursorArea && yPos >= getHeight() - cursorArea) {
  498.             setCursor(Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR));
  499.         } else {
  500.             setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  501.         }
  502.     }
  503.  
  504.     @Override
  505.     public void mouseClicked(MouseEvent e) {
  506.         Object sourceObject = e.getSource();
  507.         if (sourceObject instanceof JPanel) {
  508.             if (e.getClickCount() == 2) {
  509.                 if (getCursor().equals(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR))) {
  510.                     headerDoubleClickResize();
  511.                 }
  512.             }
  513.         }
  514.     }
  515.  
  516.     private void moveOrFullResizeFrame(MouseEvent e) {
  517.         Object sourceObject = e.getSource();
  518.         Point current = getScreenLocation(e, this);
  519.         Point offset = new Point((int) current.getX() - (int) start_drag.getX(), (int) current.getY() - (int) start_drag.getY());
  520.  
  521.         if (sourceObject instanceof JPanel
  522.                 && getCursor().equals(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR))) {
  523.             setLocation((int) (start_loc.getX() + offset.getX()), (int) (start_loc.getY() + offset.getY()));
  524.         } else if (!getCursor().equals(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR))) {
  525.             int oldLocationX = (int) getLocation().getX();
  526.             int oldLocationY = (int) getLocation().getY();
  527.             int newLocationX = (int) (this.start_loc.getX() + offset.getX());
  528.             int newLocationY = (int) (this.start_loc.getY() + offset.getY());
  529.             boolean N_Resize = getCursor().equals(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));
  530.             boolean NE_Resize = getCursor().equals(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
  531.             boolean NW_Resize = getCursor().equals(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));
  532.             boolean E_Resize = getCursor().equals(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
  533.             boolean W_Resize = getCursor().equals(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
  534.             boolean S_Resize = getCursor().equals(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
  535.             boolean SW_Resize = getCursor().equals(Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR));
  536.             boolean setLocation = false;
  537.             int newWidth = e.getX();
  538.             int newHeight = e.getY();
  539.  
  540.             if (NE_Resize) {
  541.                 newHeight = getHeight() - (newLocationY - oldLocationY);
  542.                 newLocationX = (int) getLocation().getX();
  543.                 setLocation = true;
  544.             } else if (E_Resize) {
  545.                 newHeight = getHeight();
  546.             } else if (S_Resize) {
  547.                 newWidth = getWidth();
  548.             } else if (N_Resize) {
  549.                 newLocationX = (int) getLocation().getX();
  550.                 newWidth = getWidth();
  551.                 newHeight = getHeight() - (newLocationY - oldLocationY);
  552.                 setLocation = true;
  553.             } else if (NW_Resize) {
  554.                 newWidth = getWidth() - (newLocationX - oldLocationX);
  555.                 newHeight = getHeight() - (newLocationY - oldLocationY);
  556.                 setLocation = true;
  557.             } else if (NE_Resize) {
  558.                 newHeight = getHeight() - (newLocationY - oldLocationY);
  559.                 newLocationX = (int) getLocation().getX();
  560.             } else if (SW_Resize) {
  561.                 newWidth = getWidth() - (newLocationX - oldLocationX);
  562.                 newLocationY = (int) getLocation().getY();
  563.                 setLocation = true;
  564.             }
  565.             if (W_Resize) {
  566.                 newWidth = getWidth() - (newLocationX - oldLocationX);
  567.                 newLocationY = (int) getLocation().getY();
  568.                 newHeight = getHeight();
  569.                 setLocation = true;
  570.             }
  571.  
  572.             if (newWidth >= (int) toolkit.getScreenSize().getWidth() || newWidth <= minWidth) {
  573.                 newLocationX = oldLocationX;
  574.                 newWidth = getWidth();
  575.             }
  576.  
  577.             if (newHeight >= (int) toolkit.getScreenSize().getHeight() - 30 || newHeight <= minHeight) {
  578.                 newLocationY = oldLocationY;
  579.                 newHeight = getHeight();
  580.             }
  581.  
  582.             if (newWidth != getWidth() || newHeight != getHeight()) {
  583.                 this.setSize(newWidth, newHeight);
  584.  
  585.                 if (setLocation) {
  586.                     this.setLocation(newLocationX, newLocationY);
  587.                 }
  588.             }
  589.         }
  590.     }
  591.  
  592.     private void headerDoubleClickResize() {
  593.         if (getWidth() < screen.getWidth() || getHeight() < screen.getHeight()) {
  594.             this.setSize((int) screen.getWidth(), (int) screen.getHeight());
  595.             Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  596.             Dimension frameSize = this.getSize();
  597.             this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
  598.  
  599.         } else {
  600.             this.setSize(precedent_width, precedent_height);
  601.             this.setLocation(precedent_loc);
  602.         }
  603.     }
  604.  
  605.     @Override
  606.     public void mousePressed(MouseEvent e) {
  607.         this.start_drag = getScreenLocation(e, this);
  608.         this.start_loc = this.getLocation();
  609.  
  610.         if (getWidth() < screen.getWidth() || getHeight() < screen.getHeight()) {
  611.             precedent_loc = this.getLocation();
  612.             precedent_width = getWidth();
  613.             precedent_height = getHeight();
  614.         }
  615.     }
  616.  
  617.     @Override
  618.     public void mouseEntered(MouseEvent e) {
  619.     }
  620.  
  621.     @Override
  622.     public void mouseExited(MouseEvent e) {
  623.     }
  624.  
  625.     @Override
  626.     public void mouseReleased(MouseEvent e) {
  627.     }
  628.  
  629.     public class Contador {
  630.  
  631.         private int i = 0;
  632.  
  633.         public Contador(int i) {
  634.             this.i = i;
  635.         }
  636.  
  637.         public void count() {
  638.             i--;
  639.         }
  640.  
  641.         public int get() {
  642.             return i;
  643.         }
  644.  
  645.         public void set(int i) {
  646.             this.i = i;
  647.         }
  648.     }
  649.  
  650.     public static void count(JTextField Field, Timer cTimer, Contador Tempo, int Type) {
  651.         int min, seg;
  652.         min = (int) Math.ceil(Tempo.get() / 60);
  653.         seg = Tempo.get() - (min * 60);
  654.         if (Tempo.get() != 0) {
  655.             if (Field.getDisabledTextColor() == Color.GREEN) {
  656.                 Field.setDisabledTextColor(Color.WHITE);
  657.             }
  658.             if ((Tempo.get() / 60) > 0) {
  659.                 if (seg < 10) {
  660.                     Field.setText(String.valueOf(min) + ":0" + String.valueOf(seg));
  661.                 } else {
  662.                     Field.setText(String.valueOf(min) + ":" + String.valueOf(seg));
  663.                 }
  664.             } else {
  665.                 if (seg < 10) {
  666.                     Field.setText("0:0" + String.valueOf(seg));
  667.                 } else {
  668.                     Field.setText("0:" + String.valueOf(seg));
  669.                 }
  670.             }
  671.             Tempo.count();
  672.         } else {
  673.             switch (Type) {
  674.                 case 0:
  675.                     Tempo.set(50);
  676.                     break;
  677.                 case 1:
  678.                     Tempo.set(300);
  679.                     break;
  680.                 case 2:
  681.                     Tempo.set(360);
  682.                     break;
  683.                 case 3:
  684.                     Tempo.set(420);
  685.                     break;
  686.             }
  687.             Field.setText("UP");
  688.             Field.setDisabledTextColor(Color.GREEN);
  689.             cTimer.stop();
  690.         }
  691.     }
  692.  
  693.     /**
  694.      * @param args the command line arguments
  695.      */
  696.     public static void main(String args[]) {
  697.         /* Set the Nimbus look and feel */
  698.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  699.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  700.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  701.          */
  702.         try {
  703.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  704.                 if ("Windows".equals(info.getName())) {
  705.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  706.                     break;
  707.                 }
  708.             }
  709.         } catch (ClassNotFoundException ex) {
  710.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  711.         } catch (InstantiationException ex) {
  712.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  713.         } catch (IllegalAccessException ex) {
  714.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  715.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  716.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  717.         }
  718.         //</editor-fold>
  719.  
  720.         /* Create and display the form */
  721.         java.awt.EventQueue.invokeLater(new Runnable() {
  722.             public void run() {
  723.                 Toolkit toolkit = Toolkit.getDefaultToolkit();
  724.                 int frameWidth = 685;
  725.                 int frameHeight = 23;
  726.  
  727.                 Point initialLocation = new Point((int) toolkit.getScreenSize().getWidth() / 2 - frameWidth / 2,
  728.                         (int) toolkit.getScreenSize().getHeight() / 2 - frameHeight / 2);
  729.                 Dimension initialDimension = new Dimension(frameWidth, frameHeight);
  730.                 NewJFrame fullResizibleFrame = new NewJFrame(initialDimension, initialLocation);
  731.  
  732.                 int frameWidth2 = 685;
  733.                 int frameHeight2 = 23;
  734.  
  735.                 Move.setPreferredSize(new Dimension(frameWidth, 20));
  736.                 Move.addMouseListener(fullResizibleFrame);
  737.                 Move.addMouseMotionListener(fullResizibleFrame);
  738.  
  739.                 Point initialLocation2 = new Point((int) toolkit.getScreenSize().getWidth() / 2 - frameWidth / 2,
  740.                         (int) toolkit.getScreenSize().getHeight() / 2 - frameHeight / 2);
  741.                 Dimension initialDimension2 = new Dimension(frameWidth2, frameHeight2);
  742.                 NewJFrame fullResizibleFrame2 = new NewJFrame(initialDimension2, initialLocation2);
  743.  
  744.                 final JPanel minimap = (JPanel) fullResizibleFrame2.getContentPane();
  745.  
  746.                 fullResizibleFrame.setVisible(true);
  747.             }
  748.         });
  749.     }
  750.  
  751.     // Variables declaration - do not modify                    
  752.     private javax.swing.JButton BaronStart;
  753.     private javax.swing.JButton DragonStart;
  754.     private static javax.swing.JPanel Move;
  755.     private javax.swing.JPanel Painel;
  756.     public javax.swing.JTextField blueBGolem;
  757.     private javax.swing.JButton blueBGolemStart;
  758.     private javax.swing.JButton blueDGolemStart;
  759.     private javax.swing.JButton blueLizardStart;
  760.     private javax.swing.JButton blueWiStart;
  761.     private javax.swing.JButton blueWolfStart;
  762.     private javax.swing.JButton blueWrStart;
  763.     private javax.swing.JButton jButton1;
  764.     private javax.swing.JButton jButton7;
  765.     private javax.swing.JButton jButton9;
  766.     private javax.swing.JLabel jLabel1;
  767.     private static javax.swing.JTextField jTextField1;
  768.     // End of variables declaration                  
  769. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement