title: Problem with Java, Swing, wait(), notify()
body: <p>I am quiet new to Java and I try to make a simple turn-based game just to gain some experience. I have encounter a problem which I cannot solve on my own, despite I did quiet a lot of google research... Probably I cannot solve it because I don't understand it well enough.</p>
  <p>The problem is I don't know how to make a program making turns for player. I mean I would like to make a few Jbuttons active till one of them is pressed and then do the same for another player. Since program is quiet complicated, I deleted 80% of code which is unrelated to problem and I post the rest of it below.</p>
  <p>The code is divided into classes and I would like to keep it this way due to complicity of a problem (remaining 80% of code). In order to see better what programs do, I made buttons to change colours each time when activated. Unfortunatelly program stops working as soon as it hits notify() method.</p>
  <p>Can anyone help? Thank you in advance.</p>
  <p><strong>Tester:</strong></p>
  <pre><code>package grafika;
  
  import javax.swing.SwingUtilities;
  
  
  public class OknoTester {
      public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
              @Override
              public void run() {
                  Okno main = new Okno();
              }
              
              // ctr + spacja - podpowiedzi w Eclipsie
          });
  
      }
  
  }
  </code></pre>
  <p><strong>Main class</strong></p>
  <pre><code> package grafika;
  
  import java.awt.Dimension;
  import javax.swing.JFrame;
  import javax.swing.JSplitPane;
  
  
  public class Okno {
      private JFrame frame;
              
      public Okno()
      {
          initialize();
      }
  
      
      private void initialize()
      {
          // NEW WINDOW
          frame = new JFrame();
          frame.setTitle(&quot;Gra w statki&quot;);
          frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
          frame.setSize(new Dimension(600,100));
          frame.setLocationRelativeTo(null);
          frame.setResizable(false);
          frame.setVisible(true);
  
          
          // DIVIDE WINDOW
          JSplitPane splitPaneH = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT );
          frame.getContentPane().add(splitPaneH);
          splitPaneH.setDividerSize(0);
          
          
          // INITIALIZATION OF SITES
          Komputer left = new Komputer();
          Komputer right = new Komputer();
          
  
          // SHOWPANELS
          splitPaneH.setLeftComponent(left.Pokaz());
          splitPaneH.setRightComponent(right.Pokaz());
          splitPaneH.setResizeWeight(0.5);
          splitPaneH.setEnabled(false);
          
          // ALLOW TO USE ONE OF LEFT OR RIGHT SET OF BUTTONS
          while(true)
          {
          left.CzytajRuch();
          right.CzytajRuch();
          }
          
          
      }
  
  }
  </code></pre>
  <p><strong>Class with buttons</strong></p>
  <pre><code>package grafika;
  
  import java.awt.Color;
  import java.awt.GridLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import javax.swing.JButton;
  import javax.swing.JPanel;
  
  public class Komputer implements ActionListener{
  
      private JButton b1 = new JButton(&quot;1&quot;);
      private JButton b2 = new JButton(&quot;2&quot;);
      private JPanel panel = new JPanel();
      private Boolean aktywny = false;
      
      
      public void CzytajRuch()
      {
          aktywny = true;
          try {
                  wait();
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
      }
  
      public JPanel Pokaz()
      {
          return panel;
      }
      
  
      public Komputer() {
          
          GridLayout gl = new GridLayout(1,2);
          panel.setLayout(gl);
          panel.add(b1);
          b1.addActionListener(this);
          b2.addActionListener(this);
          panel.add(b2);
  
      }
  
  
      public void actionPerformed(ActionEvent ae) {
          if(aktywny == true)
          {
          JButton pb = (JButton) ae.getSource();
          if (pb == b1)
              b1.setBackground(new Color((int)(Math.random() * 0x1000000)));
          if (pb == b2)
              b2.setBackground(new Color((int)(Math.random() * 0x1000000)));
          aktywny = false;
          notify();
          }
      }
      
  
  }
   
  </code></pre>
  <p>Thank you for your time reading this. I would apprieciate any help.</p>