Skip to content
Snippets Groups Projects
View.java 2.81 KiB
Newer Older
  • Learn to ignore specific revisions
  • Kovax's avatar
    v2
    Kovax committed
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package GUI.game;
    
    
    Kovax's avatar
    Kovax committed
    import GUI.Window.Window;
    
    Dániel's avatar
    Dániel committed
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    
    Kovax's avatar
    v2
    Kovax committed
    import java.awt.GridLayout;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    
    Dániel's avatar
    Dániel committed
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    
    Kovax's avatar
    v2
    Kovax committed
    
    /**
     *
     * @author Kovax
     */
    
    Kovax's avatar
    Kovax committed
    public class View extends Window
    {   
        private Controller controller;
        private Model model;
    
    Kovax's avatar
    v2
    Kovax committed
        private JFrame frame;
    
    Dániel's avatar
    Dániel committed
        private JLabel timeLeftLabel;
    
    Dániel's avatar
    Dániel committed
        private JPanel buttons;
    
    Dániel's avatar
    Dániel committed
        private int timeLeft;
    
    Kovax's avatar
    v2
    Kovax committed
        
    
    Dániel's avatar
    Dániel committed
        public void timeLeft()
        {
            this.timeLeft++;
            this.timeLeftLabel.setText(Integer.toString(this.timeLeft));
            
        }
    
        public View(Controller game, Model gameModel)
    
    Kovax's avatar
    v2
    Kovax committed
        {
    
    Dániel's avatar
    Dániel committed
            this.timeLeft = 0;
    
            this.model      = gameModel;
            this.controller = game;
            
    
    Dániel's avatar
    Dániel committed
            this.setSize(controller.settings.size*46,controller.settings.size*26);
            //w41 h26
    
            this.setLayout(new GridLayout(controller.settings.size,controller.settings.size));
    
    Kovax's avatar
    Kovax committed
    
    
    Kovax's avatar
    Kovax committed
        }
    
    Kovax's avatar
    v2
    Kovax committed
        public void draw()
        {
    
            model.build();
            for(int i=0;i<controller.settings.size;i++)
            {
                for(JButton actButton : model.squares[i])
                {
                    this.add(actButton);
                }
            }
    
    Kovax's avatar
    v2
    Kovax committed
            if( this.frame != null )
            {
                  frame.dispose();
            }
    
    Dániel's avatar
    Dániel committed
            //Kulso panel
            JPanel panel = new JPanel();
            panel.setLayout(new GridBagLayout());
    
    Kovax's avatar
    v2
    Kovax committed
            
    
    Dániel's avatar
    Dániel committed
            //Frame
    
    Kovax's avatar
    v2
    Kovax committed
            this.frame = new JFrame("Aknakereső");
    
    Dániel's avatar
    Dániel committed
            frame.setSize(controller.settings.size*46,(controller.settings.size+4)*26);
    
    Kovax's avatar
    v2
    Kovax committed
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
    
    Dániel's avatar
    Dániel committed
            GridBagConstraints c = new GridBagConstraints();
            
            
            JPanel upper = new JPanel();
            upper.setSize(controller.settings.size*41,100);
    
    Dániel's avatar
    Dániel committed
              
            this.timeLeftLabel = new JLabel();
    
    Dániel's avatar
    Dániel committed
            JLabel points = new JLabel();
            JButton stopButton = new JButton();
            
    
    Dániel's avatar
    Dániel committed
            
    
    Dániel's avatar
    Dániel committed
            points.setText("points");
            stopButton.setText("buton");
            
    
    Dániel's avatar
    Dániel committed
           
    
    Dániel's avatar
    Dániel committed
            c.fill = GridBagConstraints.EAST;
            c.gridx = 0;
            c.gridy = 0;
            
    
    Dániel's avatar
    Dániel committed
            upper.add(this.timeLeftLabel); 
    
    Dániel's avatar
    Dániel committed
            upper.add(stopButton);
            upper.add(points);
            
            panel.add(upper,c);
            
            JPanel buttons = new JPanel();
            buttons.add(this);
            c.fill = GridBagConstraints.HORIZONTAL;
            c.gridx = 0;
            c.gridy = 1;
    
    Dániel's avatar
    Dániel committed
        
            panel.add(buttons,c);      
    
    Dániel's avatar
    Dániel committed
            frame.add(panel);
    
    Kovax's avatar
    v2
    Kovax committed
        }
    
    Kovax's avatar
    v2
    Kovax committed
    }