Advertisement
omegazero

LolTimer - Display.java

Dec 4th, 2011
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.25 KB | None | 0 0
  1. package lol.jacklyon3;
  2.  
  3.  
  4. import javax.swing.*;
  5. import java.awt.GridLayout;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8.  
  9. public class Display extends JFrame {
  10.     /**
  11.      *
  12.      */
  13.     private static final long serialVersionUID = 1L;
  14.     private JLabel gameTime, baronTime, dragonTime, yourTimes[], enemyTimes[];
  15.     private JButton gameButton, gamePause, dragon, baron, yourButtons[], enemyButtons[];
  16.     private Timers timers;
  17.     public Display() {
  18.         super();
  19.                
  20.         setTitle("LoLTimer v1.0");
  21.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  22.         setAlwaysOnTop(true);
  23.         setLayout(new GridLayout(16, 3, 3, 3));
  24.         setSize(300, 500);
  25.        
  26.         JMenuBar menuBar = new JMenuBar();
  27.         menuBar.setBorderPainted(true);
  28.         JMenu menu = new JMenu("File");
  29.         JMenuItem aboutMenu = new JMenuItem("About");
  30.         aboutMenu.addActionListener(new ActionListener() {
  31.             public void actionPerformed(ActionEvent e) {
  32.                 JOptionPane.showMessageDialog(null, "Created by Jack Lyon III, 2011", "About", JOptionPane.PLAIN_MESSAGE);
  33.             }          
  34.         });
  35.         JMenuItem exitMenu = new JMenuItem("Exit");
  36.         exitMenu.addActionListener(new ActionListener() {
  37.             public void actionPerformed(ActionEvent e) {
  38.                 System.exit(0);
  39.             }
  40.         });
  41.         menu.add(aboutMenu);
  42.         menu.add(exitMenu);
  43.         menuBar.add(menu);
  44.         setJMenuBar(menuBar);
  45.        
  46.         try {
  47.               UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  48.             } catch(Exception e) {
  49.               System.out.println("Error setting native LAF: " + e);
  50.         }
  51.        
  52.         /* just all the silly setup stuff */
  53.         this.gameButton = new JButton("Game Start");
  54.         this.gameButton.addActionListener(new ActionListener() {
  55.             public void actionPerformed(ActionEvent e) {
  56.                 if ( gameButton.getText().equals("Game Start") ) {
  57.                     timers.startGameTimer();
  58.                     gameButton.setText("Game Reset");
  59.                     resetLabels();
  60.                 }
  61.                 else {
  62.                     timers.resetGameTimer();
  63.                     resetLabels();
  64.                     gameButton.setText("Game Start");
  65.                 }
  66.             }  
  67.         });
  68.         this.gamePause = new JButton("Pause");
  69.         this.gamePause.addActionListener(new ActionListener() {
  70.             public void actionPerformed(ActionEvent e) {
  71.                 if ( gamePause.getText().equals("Pause") ) {
  72.                     gamePause.setText("Unpause");
  73.                 }
  74.                 else {
  75.                     gamePause.setText("Pause");
  76.                 }
  77.                 timers.togglePaused();
  78.             }
  79.         });
  80.         this.gameTime = new JLabel("--:--", JLabel.CENTER);
  81.        
  82.         this.yourTimes = new JLabel[5];
  83.         this.enemyTimes = new JLabel[5];
  84.        
  85.         this.yourButtons = new JButton[5];
  86.         this.enemyButtons = new JButton[5];
  87.        
  88.         this.baron = new JButton("Start");
  89.         this.baron.addActionListener(new ActionListener(){
  90.             public void actionPerformed(ActionEvent e) {
  91.                 timers.startBaron();
  92.             }
  93.         });
  94.        
  95.         this.dragon = new JButton("Start");
  96.         this.dragon.addActionListener(new ActionListener(){
  97.             public void actionPerformed(ActionEvent e) {
  98.                 timers.startDragon();
  99.             }
  100.         });
  101.        
  102.         this.baronTime = new JLabel("--:--", JLabel.CENTER);
  103.         this.dragonTime = new JLabel("--:--", JLabel.CENTER);
  104.         for ( int i = 0; i < this.yourTimes.length; i++ ) {
  105.             this.yourTimes[i] = new JLabel("--:--", JLabel.CENTER);
  106.             this.enemyTimes[i] = new JLabel("--:--", JLabel.CENTER);
  107.             this.yourButtons[i] = new JButton("Start");
  108.             this.yourButtons[i].setActionCommand(i+"");
  109.             this.yourButtons[i].addActionListener(new ActionListener(){
  110.                 public void actionPerformed(ActionEvent e) {
  111.                     timers.startYour(new Integer(e.getActionCommand()));
  112.                 }
  113.             });
  114.            
  115.             this.enemyButtons[i] = new JButton("Start");
  116.             this.enemyButtons[i].setActionCommand(i+"");
  117.             this.enemyButtons[i].addActionListener(new ActionListener(){
  118.                 public void actionPerformed(ActionEvent e) {
  119.                     timers.startEnemy(new Integer(e.getActionCommand()));
  120.                 }
  121.             });
  122.         }
  123.         add(gameTime);
  124.         add(gameButton);
  125.         add(gamePause);
  126.        
  127.         add(new JSeparator());
  128.         add(new JSeparator());
  129.         add(new JSeparator());
  130.        
  131.         add(new JLabel("<html><b>Dragon</b></html>", JLabel.CENTER));
  132.         add(new JLabel(""));
  133.         add(new JLabel("<html><b>Baron</b></html>", JLabel.CENTER));
  134.         add(this.dragonTime);
  135.         add(new JLabel(""));
  136.         add(this.baronTime);
  137.         add(this.dragon);
  138.         add(new JLabel(""));
  139.         add(this.baron);
  140.        
  141.         add(new JLabel(""));
  142.         add(new JLabel("<html><b>Your</b></html>", JLabel.CENTER));
  143.         add(new JLabel("<html><b>Enemy's</b></html>", JLabel.CENTER));
  144.        
  145.         add(new JLabel("Blue", JLabel.RIGHT));
  146.         add(this.yourTimes[Timers.BLUE]);
  147.         add(this.enemyTimes[Timers.BLUE]);
  148.         add(new JLabel(""));
  149.         add(this.yourButtons[Timers.BLUE]);
  150.         add(this.enemyButtons[Timers.BLUE]);
  151.        
  152.         add(new JLabel("Red", JLabel.RIGHT));
  153.         add(this.yourTimes[Timers.RED]);
  154.         add(this.enemyTimes[Timers.RED]);
  155.         add(new JLabel(""));
  156.         add(this.yourButtons[Timers.RED]);
  157.         add(this.enemyButtons[Timers.RED]);
  158.        
  159.         add(new JLabel("Top Inhib", JLabel.RIGHT));
  160.         add(this.yourTimes[Timers.TOP]);
  161.         add(this.enemyTimes[Timers.TOP]);
  162.         add(new JLabel(""));
  163.         add(this.yourButtons[Timers.TOP]);
  164.         add(this.enemyButtons[Timers.TOP]);
  165.        
  166.         add(new JLabel("Mid Inhib", JLabel.RIGHT));
  167.         add(this.yourTimes[Timers.MID]);
  168.         add(this.enemyTimes[Timers.MID]);
  169.         add(new JLabel(""));
  170.         add(this.yourButtons[Timers.MID]);
  171.         add(this.enemyButtons[Timers.MID]);
  172.        
  173.         add(new JLabel("Bot Inhib", JLabel.RIGHT));
  174.         add(this.yourTimes[Timers.BOT]);
  175.         add(this.enemyTimes[Timers.BOT]);
  176.         add(new JLabel(""));
  177.         add(this.yourButtons[Timers.BOT]);
  178.         add(this.enemyButtons[Timers.BOT]);
  179.        
  180.         this.timers = new Timers(this);
  181.     }
  182.    
  183.     private void resetLabels() {
  184.         this.gamePause.setText("Pause");
  185.         this.gameTime.setText("--:--");
  186.         this.dragonTime.setText("--:--");
  187.         this.baronTime.setText("--:--");
  188.         for ( int i = 0; i < this.yourTimes.length; i++ ) {
  189.             this.yourTimes[i].setText("--:--");
  190.             this.enemyTimes[i].setText("--:--");
  191.             this.yourButtons[i].setText("Start");
  192.             this.enemyButtons[i].setText("Start");
  193.         }
  194.     }
  195.    
  196.     private String formattedTime(int time) {
  197.         String result = simpleFormattedTime(time);
  198.         result += " ("+simpleFormattedTime(time+timers.gameTime())+")";
  199.         return result;
  200.     }
  201.    
  202.     private String simpleFormattedTime(int time) {
  203.         int mins = time / 60;
  204.         int secs = time % 60;
  205.         String result = mins+":";
  206.         if ( secs < 10 ) {
  207.             result += "0";
  208.         }
  209.         result += secs;
  210.         return( result );
  211.     }
  212.    
  213.     public void updateLabels() {
  214.         //so, get the game time, and the time of all the different buffs
  215.         //then update the labels.
  216.         if ( timers.gameTime() < 0 ) {
  217.             this.gameTime.setText("--:--");
  218.         }
  219.         else {
  220.             this.gameTime.setText(simpleFormattedTime(timers.gameTime()));
  221.         }
  222.        
  223.         if ( timers.getBaron() < 0 ) {
  224.             baronTime.setText("UP");
  225.         } else  {
  226.             baronTime.setText(formattedTime(timers.getBaron()));
  227.         }
  228.        
  229.         if ( timers.getDragon() < 0 ) {
  230.             dragonTime.setText("UP");
  231.         }
  232.         else {
  233.             dragonTime.setText(formattedTime(timers.getDragon()));
  234.         }
  235.        
  236.         for ( int i = 0; i < yourTimes.length; i++ ) {
  237.             if ( timers.yourTime(i) < 0 ) {
  238.                 yourTimes[i].setText("UP");
  239.             }
  240.             else {
  241.                 yourTimes[i].setText(formattedTime(timers.yourTime(i)));
  242.             }
  243.            
  244.             if ( timers.enemyTime(i) < 0 ) {
  245.                 enemyTimes[i].setText("UP");
  246.             }
  247.             else {
  248.                 enemyTimes[i].setText(formattedTime(timers.enemyTime(i)));
  249.             }
  250.         }
  251.        
  252.     }
  253.    
  254.     public static void main(String[] args) {
  255.         Display d = new Display();
  256.         d.setVisible(true);
  257.     }
  258. }
  259.  
  260.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement