From ff535ea614ff963a8d202a9df74adbeb3f2cb459 Mon Sep 17 00:00:00 2001
From: Kovax <Kovax@Kovax-PC>
Date: Wed, 13 Nov 2013 18:32:03 +0100
Subject: [PATCH] Menuzeleles javitva2

---
 src/GUI/game/Controller.java            |  28 ++++--
 src/GUI/game/Game.java                  |  17 +++-
 src/GUI/game/View.java                  |  13 ++-
 src/GUI/menu/Controller.java            |  14 ++-
 src/GUI/menu/View.java                  |   1 +
 src/GUI/window/GUIMSG.java              |  52 -----------
 src/GUI/window/Window.java              |   5 +-
 src/GUI/window/WindowChangedAction.java |  24 +++++
 src/Program/Game.java                   | 114 ++++++++++++++++--------
 src/Program/Program.java                |   1 -
 10 files changed, 164 insertions(+), 105 deletions(-)
 delete mode 100644 src/GUI/window/GUIMSG.java
 create mode 100644 src/GUI/window/WindowChangedAction.java

diff --git a/src/GUI/game/Controller.java b/src/GUI/game/Controller.java
index 8f0e7a2..c35d745 100644
--- a/src/GUI/game/Controller.java
+++ b/src/GUI/game/Controller.java
@@ -13,15 +13,33 @@ package GUI.game;
  */
 public class Controller
 {
-    private View view;
+    public View view;
     private Model model;
     
-    public Controller(Model model, View view) 
+    private Boolean isStopButtonPressed = false;
+    
+    Controller() 
+    {
+       
+    }
+    public void registerView(View view)
+    {
+        this.view = view;
+    }
+    public void registerModel(Model model)
     {
-        this.view        = view;
-        this.model       = model;
+        this.model = model;
+    }
+    public int getButtonState()
+    {
+        if( isStopButtonPressed )
+            return 1;
+        return -1;
         
-        view.draw();
+    }
+    public void resetButtonState()
+    {
+        this.isStopButtonPressed = false;
     }
 
     
diff --git a/src/GUI/game/Game.java b/src/GUI/game/Game.java
index 8965457..3daddc6 100644
--- a/src/GUI/game/Game.java
+++ b/src/GUI/game/Game.java
@@ -10,8 +10,17 @@ package GUI.game;
  *
  * @author Kovax
  */
-public class Game {
-    View view = new View();
-    Model model = new Model();
-    Controller game = new Controller(model,view);
+public class Game 
+{
+    public Controller controller;
+    
+    public Game()
+    {
+        Model gameModel = new Model();
+        Controller game = new Controller();
+        View gameView = new View(game,gameModel);
+        
+        this.controller = game;
+    }
+   
 }
diff --git a/src/GUI/game/View.java b/src/GUI/game/View.java
index ba69015..e364aa0 100644
--- a/src/GUI/game/View.java
+++ b/src/GUI/game/View.java
@@ -6,6 +6,7 @@
 
 package GUI.game;
 
+import GUI.Window.Window;
 import java.awt.GridLayout;
 import javax.swing.JButton;
 import javax.swing.JFrame;
@@ -15,7 +16,11 @@ import javax.swing.JPanel;
  *
  * @author Kovax
  */
-public class View extends JPanel {
+public class View extends Window
+{   
+    private Controller controller;
+    private Model model;
+    
     private JButton[][] squares;
     private JFrame frame;
     
@@ -26,6 +31,12 @@ public class View extends JPanel {
         squares = new JButton[6][6];
     
     }
+
+    View(Controller game, Model gameModel) 
+    {
+        this.model = gameModel;
+        this.controller = game;
+    }
     public void draw()
     {
         this.build();
diff --git a/src/GUI/menu/Controller.java b/src/GUI/menu/Controller.java
index 7378b00..9137f76 100644
--- a/src/GUI/menu/Controller.java
+++ b/src/GUI/menu/Controller.java
@@ -6,7 +6,6 @@
 
 package GUI.menu;
 
-import GUI.window.GUIMSG;
 
 /**
  *
@@ -16,7 +15,7 @@ public class Controller
 {
     private Boolean isNewGameButtonPressed = false;
     
-    private View view;
+    public View view;
     private Model model;
 
     
@@ -39,9 +38,16 @@ public class Controller
         isNewGameButtonPressed = true;
         //throw new GUIMSG("kakispite");
     }
-    public Boolean getButtonState()
+    public void resetButtonState()
     {
-        return isNewGameButtonPressed;
+        this.isNewGameButtonPressed = false;
+    }
+    public int getButtonState()
+    {
+        if( isNewGameButtonPressed )
+            return 1;
+        return -1;
+        
     }
     
     
diff --git a/src/GUI/menu/View.java b/src/GUI/menu/View.java
index 573a26a..81567f1 100644
--- a/src/GUI/menu/View.java
+++ b/src/GUI/menu/View.java
@@ -167,6 +167,7 @@ public class View extends Window
 
     private void newGameBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newGameBTNActionPerformed
         controller.newGameButtonPressed();
+        
     }//GEN-LAST:event_newGameBTNActionPerformed
 
     private void settingsBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_settingsBTNActionPerformed
diff --git a/src/GUI/window/GUIMSG.java b/src/GUI/window/GUIMSG.java
deleted file mode 100644
index 320d1f3..0000000
--- a/src/GUI/window/GUIMSG.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.window;
-
-/**
- *
- * @author Kovax
- */
-public class GUIMSG extends Throwable
-{
-    String msg_str;
-    int msg_int;
-    
-    
-    public GUIMSG()
-    {
-        
-        msg_str = null;
-        msg_int = 0;
-                
-    }
-
-    public GUIMSG(String test) {
-        this.msg_str = test;
-    }
-    
-    public void setMsg(String msg_str)
-    {
-        this.msg_str = msg_str;
-    }
-    public void setMsg(int msg_int)
-    {
-        this.msg_int = msg_int;
-    }
-    @Override
-    public String toString()
-    {
-        if( msg_str != null )
-            return msg_str;
-        else
-            return Integer.toString(msg_int);
-    }
-    
-    public Integer toInteger()
-    {
-        return msg_int;
-    }
-}
diff --git a/src/GUI/window/Window.java b/src/GUI/window/Window.java
index 86a440c..9cf2ea0 100644
--- a/src/GUI/window/Window.java
+++ b/src/GUI/window/Window.java
@@ -47,6 +47,9 @@ public class Window extends JPanel {
     public void setWindosWidth  (int windowWidth )      { this.windowWidth = windowWidth; }
     public void setWindowName   ( String windowName )   { this.windowName = windowName; }
     
-    
+    public void close()
+    {
+        this.frame.dispose();
+    }
     
 }
diff --git a/src/GUI/window/WindowChangedAction.java b/src/GUI/window/WindowChangedAction.java
new file mode 100644
index 0000000..2814881
--- /dev/null
+++ b/src/GUI/window/WindowChangedAction.java
@@ -0,0 +1,24 @@
+/*
+ * 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.window;
+
+import java.awt.event.ActionEvent;
+import javax.swing.AbstractAction;
+
+/**
+ *
+ * @author Kovax
+ */
+public class WindowChangedAction extends AbstractAction
+{
+
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+    
+}
diff --git a/src/Program/Game.java b/src/Program/Game.java
index b314c6b..298392c 100644
--- a/src/Program/Game.java
+++ b/src/Program/Game.java
@@ -15,45 +15,85 @@ import GUI.menu.Menu;
 public class Game
 {
     Menu menu;
-    Thread BTNListener;
+    GUI.game.Game game;
     
-            public Game()
-            {
-                Menu menu = new Menu();
-                this.menu =  menu;
-                
-                System.out.println(menuWaitForButton());
+    private int window;
+    
+    public Game()
+    {
+        this.window = 0;
+        
 
+        while( true )
+        {
+            this.windowManager();
+        }
+    }
+    public void windowManager()
+    {
+        while( true )
+        {
+            switch(this.window)
+            {
+                case 0: this.window = this.menuWindow();
+                        break;
+                case 1: this.window = this.gameWindow();
+                        break;
             }
-            
-            public int menuWaitForButton()   
+        }
+    }
+    public int gameWindow()
+    {
+        this.game = new GUI.game.Game();
+        
+        while( true )
+        {
+            if( this.game.controller.getButtonState() != -1 )
+                {
+                    int state = this.game.controller.getButtonState();
+                    this.game.controller.resetButtonState();
+                    this.game.controller.view.close();
+                    this.window = state;
+                    return state;
+                }
+                try
+                {
+                    Thread.sleep(100);
+                }
+                catch(InterruptedException ex )
+                {
+
+                }
+        }
+        
+    }
+    public int menuWindow()   
+    {
+        Menu menu = new Menu();
+        this.menu =  menu;
+        
+        synchronized(menu)
+        {
+            while( true )
             {
-              
-                    synchronized(menu)
-                    {
-                        while( true )
-                        {
-                            if( this.menu.controller.getButtonState() )
-                            {
-                                System.out.println("asdasdsadsasaddas");
-                                return 1;
-                            }
-                                try
-                                {
-                                    Thread.sleep(100);
-                                }
-                                catch(InterruptedException ex )
-                                {
-                                    
-                                }
-                               
-                            
-                        }
-                        
-                    }
-                        
-              
+                if( this.menu.controller.getButtonState() != -1 )
+                {
+                    int state = this.menu.controller.getButtonState();
+                    this.menu.controller.resetButtonState();
+                    this.menu.controller.view.close();
+                    this.window = state;
+                    return state;
+                }
+                try
+                {
+                    Thread.sleep(100);
+                }
+                catch(InterruptedException ex )
+                {
+
+                }
             }
-            
-            
-        }
\ No newline at end of file
+        }
+    }
+                 
+}
\ No newline at end of file
diff --git a/src/Program/Program.java b/src/Program/Program.java
index 3ecac79..d35d204 100644
--- a/src/Program/Program.java
+++ b/src/Program/Program.java
@@ -11,7 +11,6 @@ import GUI.menu.Controller;
 import GUI.menu.Menu;
 import GUI.menu.Model;
 import GUI.menu.View;
-import GUI.window.GUIMSG;
 import java.util.ArrayList;
 
 /**
-- 
GitLab