Gui_WinLose.java :  » Game » magicwars » mw » client » dialogs » jframe » Java Open Source

Java Open Source » Game » magicwars 
magicwars » mw » client » dialogs » jframe » Gui_WinLose.java
package mw.client.dialogs.jframe;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;
import java.rmi.RemoteException;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import mw.client.managers.ConnectionManager;
import mw.client.managers.DialogManager;
import mw.client.managers.GameManager;
import mw.client.managers.ProfileManager;
import mw.client.managers.SettingsManager;
import mw.client.managers.StackManager;
import mw.client.utils.cache.SaveObjectUtil;
import mw.mtgforge.Constant;
import mw.mtgforge.WinLose;

import org.apache.log4j.Logger;

public class Gui_WinLose extends JFrame {

    private static final Logger log = Logger.getLogger(Gui_WinLose.class);

    private JLabel titleLabel = new JLabel();
    private JButton continueButton = new JButton();
    private JButton restartButton = new JButton();
    private JButton quitButton = new JButton();
    private JLabel statsLabel = new JLabel();
    private JPanel jPanel2 = new JPanel();

    public static void main(String[] args) {
        Constant.Runtime.GameType[0] = Constant.GameType.Sealed;

        Constant.Runtime.WinLose.addWin();
        Constant.Runtime.WinLose.addLose();

        // setup limited deck

        /***********************************************************************
         * Deck deck = new Deck(Constant.GameType.Sealed); CardList pack = new
         * CardList(BoosterPack.getBoosterPack(1).toArray());
         * 
         * for(int i = 0; i < pack.size(); i++) if((i%2) == 0)
         * deck.addSideboard(pack.get(i).getName()); else
         * deck.addMain(pack.get(i).getName());
         * 
         * Constant.Runtime.HumanDeck[0] = deck; //end - setup limited deck
         */

        new Gui_WinLose();
    }

    public Gui_WinLose() {
        try {
            jbInit();
        } catch (Exception e) {
            e.printStackTrace();
        }

        //setup();

        Dimension screen = this.getToolkit().getScreenSize();
        setBounds(screen.width / 3, 100, // position
                215, 370); // size
        //show();
    }

    public void setup() {
        //WinLose winLose = Constant.Runtime.WinLose;
        WinLose winLoose = null;

        try {
            winLoose = ConnectionManager.getRMIConnection().getWinLose(ProfileManager.getMyId());
            SaveObjectUtil.saveObject(winLoose, ProfileManager.getMyId(), "winlose");
        } catch (Exception e) {
            log.error(e);
        }

        if (winLoose == null) {
            JOptionPane.showMessageDialog(null, "WinLose info is null", "Server", JOptionPane.ERROR_MESSAGE);
            return;
        }

        // 3 is the match length, 3 is the number of games
        // disable buttons if match is up, or human player won 2 or lost 2 games
        // already
        if ((winLoose.countWinLose() == 3) || (winLoose.getWin() == 2) || (winLoose.getLose() == 2)) {
            // editDeckButton.setEnabled(false);
            continueButton.setEnabled(false);
        } else {
            continueButton.setEnabled(true);
          //continueButton.setEnabled(false);
        }

        // show Wins and Loses
        statsLabel.setText("Won: " + winLoose.getWin() + ", Lost: " + winLoose.getLose());

        // show "You Won" or "You Lost"
        if (winLoose.didWinRecently()) {
            titleLabel.setText("You Won");
        } else {
            titleLabel.setText("You Lost");
        }

    }// setup();

    private void jbInit() throws Exception {
        titleLabel.setFont(new java.awt.Font("Dialog", 0, 26));
        titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
        titleLabel.setText("You Won");
        titleLabel.setBounds(new Rectangle(-4, 0, 198, 60));
        this.getContentPane().setLayout(null);
        continueButton.setBounds(new Rectangle(22, 21, 123, 30));
        continueButton.setText("Continue Match");
        continueButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                continueButton_actionPerformed(e);
            }
        });
        continueButton.setEnabled(false);
        restartButton.setBounds(new Rectangle(22, 90, 123, 30));
        restartButton.setText("Restart Match");
        restartButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                restartButton_actionPerformed(e);
            }
        });
        restartButton.setEnabled(false);
        quitButton.setBounds(new Rectangle(22, 158, 123, 30));
        quitButton.setText("Quit Match");
        quitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                quitButton_actionPerformed(e);
            }
        });
        statsLabel.setFont(new java.awt.Font("Dialog", 0, 16));
        statsLabel.setHorizontalAlignment(SwingConstants.CENTER);
        statsLabel.setText("Wins 2, Lost 1");
        statsLabel.setBounds(new Rectangle(12, 59, 170, 30));
        jPanel2.setBorder(BorderFactory.createLineBorder(Color.black));
        jPanel2.setBounds(new Rectangle(20, 104, 166, 217));
        jPanel2.setLayout(null);
        this.addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                this_windowClosing(e);
            }
        });
        this.getContentPane().add(statsLabel, null);
        this.getContentPane().add(jPanel2, null);
        jPanel2.add(continueButton, null);
        jPanel2.add(quitButton, null);
        jPanel2.add(restartButton, null);
        this.getContentPane().add(titleLabel, null);
        
        setTitle("Info");
    }

    void editDeckButton_actionPerformed(ActionEvent e) {
        /***********************************************************************
         * Command exit = new Command() { public void execute() { new
         * Gui_WinLose(); } }; Gui_DeckEditor editor = new Gui_DeckEditor();
         * 
         * editor.show(exit);
         * 
         * dispose();
         */
    }// editDeckButton_actionPerformed()

    void continueButton_actionPerformed(ActionEvent e) {

      GameManager.getClient().hideGameTable();
      SettingsManager.getManager().setGameContinued(true);
      GameManager.getClient().reloadMWServerListener();
      DialogManager.getManager().fadeOut();
      StackManager.getManager().clearStack();
     
        dispose();
    }

    void restartButton_actionPerformed(ActionEvent e) {
        //Constant.Runtime.WinLose.reset();
        //AllZone.GameAction.newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0]);
        //AllZone.Display.show();

        dispose();
    }

    void quitButton_actionPerformed(ActionEvent e) {
 
        try {
            if (ConnectionManager.getRMIConnection() != null) {
                ConnectionManager.getRMIConnection().quitTheGame(ProfileManager.getMyId());
            }
        } catch (RemoteException re) {
            log.error(e);
        }
        
        GameManager.getClient().hideGameTable();       
      
        dispose();
        
        System.exit(0);
    }

    void this_windowClosing(WindowEvent e) {
        quitButton_actionPerformed(null);
    }

    /**
     * Default UID 
     */
    private static final long serialVersionUID = 1L;
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.