Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lol.jacklyon3;
- import javax.swing.*;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class Display extends JFrame {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- private JLabel gameTime, baronTime, dragonTime, yourTimes[], enemyTimes[];
- private JButton gameButton, gamePause, dragon, baron, yourButtons[], enemyButtons[];
- private Timers timers;
- public Display() {
- super();
- setTitle("LoLTimer v1.0");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setAlwaysOnTop(true);
- setLayout(new GridLayout(16, 3, 3, 3));
- setSize(300, 500);
- JMenuBar menuBar = new JMenuBar();
- menuBar.setBorderPainted(true);
- JMenu menu = new JMenu("File");
- JMenuItem aboutMenu = new JMenuItem("About");
- aboutMenu.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- JOptionPane.showMessageDialog(null, "Created by Jack Lyon III, 2011", "About", JOptionPane.PLAIN_MESSAGE);
- }
- });
- JMenuItem exitMenu = new JMenuItem("Exit");
- exitMenu.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
- menu.add(aboutMenu);
- menu.add(exitMenu);
- menuBar.add(menu);
- setJMenuBar(menuBar);
- try {
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- } catch(Exception e) {
- System.out.println("Error setting native LAF: " + e);
- }
- /* just all the silly setup stuff */
- this.gameButton = new JButton("Game Start");
- this.gameButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if ( gameButton.getText().equals("Game Start") ) {
- timers.startGameTimer();
- gameButton.setText("Game Reset");
- resetLabels();
- }
- else {
- timers.resetGameTimer();
- resetLabels();
- gameButton.setText("Game Start");
- }
- }
- });
- this.gamePause = new JButton("Pause");
- this.gamePause.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if ( gamePause.getText().equals("Pause") ) {
- gamePause.setText("Unpause");
- }
- else {
- gamePause.setText("Pause");
- }
- timers.togglePaused();
- }
- });
- this.gameTime = new JLabel("--:--", JLabel.CENTER);
- this.yourTimes = new JLabel[5];
- this.enemyTimes = new JLabel[5];
- this.yourButtons = new JButton[5];
- this.enemyButtons = new JButton[5];
- this.baron = new JButton("Start");
- this.baron.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e) {
- timers.startBaron();
- }
- });
- this.dragon = new JButton("Start");
- this.dragon.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e) {
- timers.startDragon();
- }
- });
- this.baronTime = new JLabel("--:--", JLabel.CENTER);
- this.dragonTime = new JLabel("--:--", JLabel.CENTER);
- for ( int i = 0; i < this.yourTimes.length; i++ ) {
- this.yourTimes[i] = new JLabel("--:--", JLabel.CENTER);
- this.enemyTimes[i] = new JLabel("--:--", JLabel.CENTER);
- this.yourButtons[i] = new JButton("Start");
- this.yourButtons[i].setActionCommand(i+"");
- this.yourButtons[i].addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e) {
- timers.startYour(new Integer(e.getActionCommand()));
- }
- });
- this.enemyButtons[i] = new JButton("Start");
- this.enemyButtons[i].setActionCommand(i+"");
- this.enemyButtons[i].addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e) {
- timers.startEnemy(new Integer(e.getActionCommand()));
- }
- });
- }
- add(gameTime);
- add(gameButton);
- add(gamePause);
- add(new JSeparator());
- add(new JSeparator());
- add(new JSeparator());
- add(new JLabel("<html><b>Dragon</b></html>", JLabel.CENTER));
- add(new JLabel(""));
- add(new JLabel("<html><b>Baron</b></html>", JLabel.CENTER));
- add(this.dragonTime);
- add(new JLabel(""));
- add(this.baronTime);
- add(this.dragon);
- add(new JLabel(""));
- add(this.baron);
- add(new JLabel(""));
- add(new JLabel("<html><b>Your</b></html>", JLabel.CENTER));
- add(new JLabel("<html><b>Enemy's</b></html>", JLabel.CENTER));
- add(new JLabel("Blue", JLabel.RIGHT));
- add(this.yourTimes[Timers.BLUE]);
- add(this.enemyTimes[Timers.BLUE]);
- add(new JLabel(""));
- add(this.yourButtons[Timers.BLUE]);
- add(this.enemyButtons[Timers.BLUE]);
- add(new JLabel("Red", JLabel.RIGHT));
- add(this.yourTimes[Timers.RED]);
- add(this.enemyTimes[Timers.RED]);
- add(new JLabel(""));
- add(this.yourButtons[Timers.RED]);
- add(this.enemyButtons[Timers.RED]);
- add(new JLabel("Top Inhib", JLabel.RIGHT));
- add(this.yourTimes[Timers.TOP]);
- add(this.enemyTimes[Timers.TOP]);
- add(new JLabel(""));
- add(this.yourButtons[Timers.TOP]);
- add(this.enemyButtons[Timers.TOP]);
- add(new JLabel("Mid Inhib", JLabel.RIGHT));
- add(this.yourTimes[Timers.MID]);
- add(this.enemyTimes[Timers.MID]);
- add(new JLabel(""));
- add(this.yourButtons[Timers.MID]);
- add(this.enemyButtons[Timers.MID]);
- add(new JLabel("Bot Inhib", JLabel.RIGHT));
- add(this.yourTimes[Timers.BOT]);
- add(this.enemyTimes[Timers.BOT]);
- add(new JLabel(""));
- add(this.yourButtons[Timers.BOT]);
- add(this.enemyButtons[Timers.BOT]);
- this.timers = new Timers(this);
- }
- private void resetLabels() {
- this.gamePause.setText("Pause");
- this.gameTime.setText("--:--");
- this.dragonTime.setText("--:--");
- this.baronTime.setText("--:--");
- for ( int i = 0; i < this.yourTimes.length; i++ ) {
- this.yourTimes[i].setText("--:--");
- this.enemyTimes[i].setText("--:--");
- this.yourButtons[i].setText("Start");
- this.enemyButtons[i].setText("Start");
- }
- }
- private String formattedTime(int time) {
- String result = simpleFormattedTime(time);
- result += " ("+simpleFormattedTime(time+timers.gameTime())+")";
- return result;
- }
- private String simpleFormattedTime(int time) {
- int mins = time / 60;
- int secs = time % 60;
- String result = mins+":";
- if ( secs < 10 ) {
- result += "0";
- }
- result += secs;
- return( result );
- }
- public void updateLabels() {
- //so, get the game time, and the time of all the different buffs
- //then update the labels.
- if ( timers.gameTime() < 0 ) {
- this.gameTime.setText("--:--");
- }
- else {
- this.gameTime.setText(simpleFormattedTime(timers.gameTime()));
- }
- if ( timers.getBaron() < 0 ) {
- baronTime.setText("UP");
- } else {
- baronTime.setText(formattedTime(timers.getBaron()));
- }
- if ( timers.getDragon() < 0 ) {
- dragonTime.setText("UP");
- }
- else {
- dragonTime.setText(formattedTime(timers.getDragon()));
- }
- for ( int i = 0; i < yourTimes.length; i++ ) {
- if ( timers.yourTime(i) < 0 ) {
- yourTimes[i].setText("UP");
- }
- else {
- yourTimes[i].setText(formattedTime(timers.yourTime(i)));
- }
- if ( timers.enemyTime(i) < 0 ) {
- enemyTimes[i].setText("UP");
- }
- else {
- enemyTimes[i].setText(formattedTime(timers.enemyTime(i)));
- }
- }
- }
- public static void main(String[] args) {
- Display d = new Display();
- d.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement