Package tamagotchi

Source Code of tamagotchi.MainFrame

package tamagotchi;

import tamagotchi.model.GUIModel;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JFrame;

/**
*
* @author mastersnes
*/
public class MainFrame extends JFrame implements Observer {

    private GUIModel guiModel;

    public MainFrame(final GUIModel guiModel) {

        this.guiModel = guiModel;
        guiModel.addObserver(this);
       
        super.setIconImage(guiModel.getIcon());
        super.setContentPane(guiModel.getCurrentPane());

        super.setVisible(true);
        super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        super.setSize(GUIModel.SCREEN_SIZE);
        super.setResizable(false);
        this.setLocationRelativeTo(null);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new MainFrame(new GUIModel());
    }

    @Override
    public void update(final Observable o, final Object arg) {
        guiModel = (GUIModel) o;
        if (guiModel.isExit()) {
            this.dispose();
        } else if (guiModel.isResize()) {
            this.setSize(GUIModel.SCREEN_SIZE);
            this.setLocationRelativeTo(null);

            guiModel.setResize(false);
        } else {
            super.setContentPane(guiModel.getCurrentPane());
            guiModel.getCurrentPane().updateUI();
        }
    }
}
TOP

Related Classes of tamagotchi.MainFrame

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.