Package Controllers.NewCard

Source Code of Controllers.NewCard.NewCardController

/**********************************************************************
    Virtual Cache is a program which helps to manage personal finances
    Copyright (C) 2013  by Rovinskiy Nikolay

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
***********************************************************************/
package Controllers.NewCard;

import Controllers.Main.MainWindowController;
import Interfaces.NewCard;
import Messages.OKMessage;
import Utils.Card;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Enumeration;

/**
*
* @author nrovinskiy
*/
public class NewCardController extends NewCard
{
    private MainWindowController mwcHost;
    private Card crdNew;
    public NewCardController(MainWindowController host)
    {
        super(host);
        mwcHost=host;
        crdNew=null;
        this.setLocation(host.getLocation().x+50, host.getLocation().y+100);
        btnOK.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
               Enumeration<Card> enCards=mwcHost.getProfile().getCards();
               while(enCards.hasMoreElements())
               {
                   if(enCards.nextElement().getName().trim().equals(txtName.getText().trim()))
                   {
                       OKMessage okm=new OKMessage(mwcHost, "The card with name "+txtName.getText().trim()+" already exists!");
                       okm.setVisible(true);
                       okm=null;
                       return;
                   }
               }
               if(txtName.getText().trim().length()==0)
               {
                   OKMessage okm=new OKMessage(mwcHost, "The \"Name\" and \"Initial amount of money\" fields are obligatory!");
                   okm.setVisible(true);
                   okm=null;
               }
               else
               {
                   try
                   {
                       crdNew=new Card(txtName.getText(), Double.parseDouble(txtValue.getText()), mwcHost.getProfile());
                       mwcHost.getProfile().addCard(crdNew);
                       mwcHost.LoadCard(crdNew, true);
                       mwcHost.UpdateCardNumbers(false);
                       dispose();
                   }
                   catch(NumberFormatException ex)
                   {
                       OKMessage okm=new OKMessage(mwcHost, "The field \"Initial amount of money\" contains invalid characters!");
                       okm.setVisible(true);
                       okm=null;
                   }
               }
            }
        });
    }

}
TOP

Related Classes of Controllers.NewCard.NewCardController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.