/** closes the window on game end */
 @Override
 public void dispose() {
   if (inventoryWin != null && inventoryWin.isVisible()) {
     inventoryWin.dispose();
   }
   if (characterWindow != null && characterWindow.isVisible()) {
     characterWindow.dispose();
   }
   mainWindow.dispose();
 }
 @Override
 public int loop() {
   if (window.isVisible()) {
     return 1000;
   }
   return -1;
 }
Exemple #3
0
  // The main method which starts the program. Goes in a loop while the window is still open and
  // while in the loop it displays certain JPanels depending on the variable mode
  public static void main(String[] args) {
    // Creates a Bomberman object
    Bomberman bomberman = new Bomberman();

    // Loads all the images and sprites
    bomberman.load();

    // Loops while the window is open
    while (window.isVisible()) {
      // Depending on mode, a certain JPanel will be made visible by calling a method
      switch (mode) {
        case 1:
          bomberman.options();
          break;
        case 2:
          bomberman.rules();
          break;
        case 3:
          bomberman.controls();
          break;
        case 4:
          bomberman.credits();
          break;
        case 5:
          if (game) bomberman.newGame();
          break;
      }
    }
  }
 public void refresh() {
   if (frame.isVisible()) {
     repaint();
     refreshRequested = true;
     lastupdate = new Date().getTime();
   }
 }
Exemple #5
0
  private void run() throws UnknownHostException {
    while (true) {
      try {
        serverSocket = new DatagramSocket(new Random().nextInt(1000) + 8000);
        break;
      } catch (SocketException e) {
        e.printStackTrace();
      }
    }
    portListener = new PortListener();
    portListener.start();
    periodicConnectionCheck = new PeriodicConnectionCheck();
    periodicConnectionCheck.start();
    parent = new JFrame("Chat");
    parent.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    parent.setMinimumSize(new Dimension(300, 400));
    parent.setLocationRelativeTo(null);
    this.gui = new GUI();
    parent.getContentPane().add(this.gui, BorderLayout.CENTER);
    parent.pack();
    parent.setVisible(true);

    showLoginDialog();

    while (parent.isVisible()) {
      try {
        Thread.sleep(100);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }
  @Override
  public void run() {
    Thread videoDecoder = new Thread(new VideoDecoder(this));
    videoDecoder.start();
    long lastFrameWrite = System.nanoTime() - NANOSECONDS_PER_FRAME;
    long timeNow = 0;

    try {
      while ((!videoDecoded || !imgBuffer.isEmpty()) && frame.isVisible()) {
        timeNow = System.nanoTime();
        if (timeNow - lastFrameWrite >= NANOSECONDS_PER_FRAME) {
          lastFrameWrite = timeNow;
          BufferedImage img = imgBuffer.take();
          g.drawImage(img, 0, 0, frame.getWidth(), frame.getHeight(), null);

          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          ImageIO.write(img, "jpg", bos);
          proxy.receiveImage(ByteBuffer.wrap(bos.toByteArray()));
        }
      }
    } catch (IOException | InterruptedException e) {
      // other user has disconnected, stop sending video
    }

    imgBuffer.clear();
    frame.setVisible(false);
    try {
      proxy.setFrameVisible(true, false);
    } catch (IOException e) {
      System.err.println("The other user has disconnected, stopping video.");
    }
  }
  /* (non-Javadoc)
   * @see de.tum.in.jrealityplugin.Cindy3DViewer#end()
   */
  @Override
  public void end() {
    updatePoints();
    updateCircles();
    updateLines();
    updatePolygons();

    if (!frame.isVisible()) frame.setVisible(true);
  }
 /** <i>Description:</i> clear buffered image, so we will redraw it */
 public void updateGraph() {
   graphOutline.updateImage();
   if (popupOutline != null) {
     if (popupWindow.isVisible()) {
       popupOutline.updateImage();
       dirtyPopup = false;
     } else {
       dirtyPopup = true;
     }
   }
 }
Exemple #9
0
  public void showDialog() {
    if (notesFrame != null && notesFrame.isVisible()) {
      return;
    }

    notesFrame = new JFrame(FpRes.getString("title.chat.notes"));
    notesFrame.setIconImage(SparkManager.getMainWindow().getIconImage());
    notesFrame.getContentPane().setLayout(new BorderLayout());
    notesFrame.getContentPane().add(new JScrollPane(this), BorderLayout.CENTER);
    notesFrame.pack();
    notesFrame.setSize(500, 400);

    notesFrame.setLocationRelativeTo(SparkManager.getChatManager().getChatContainer());
    notesFrame.setVisible(true);

    textPane.requestFocusInWindow();
  }
  @Override
  public void actionPerformed(ActionEvent e) {
    AbstractButton button = (AbstractButton) e.getSource();
    try {
      if (button == btnQuit) {
        sendCommand(Command.QUIT);
        socket.close();
        socket = null;
        setButtonStatus(false);
      } else if (button == btnConnection) {
        if (socket == null) connect();
        else if (socket.isConnected()) {
          sendCommand(Command.QUIT);
          Thread.sleep(1000);
          socket.close();

          connect();
        }
      } else if (button == btnReset) {
        sendCommand(Command.RESET);
      } else if (button == btnShutdown) {
        sendCommand(Command.DISPOSE);
      } else if (button == btnSpeed1) {
        sendSpeed(1);
      } else if (button == btnSpeed2) {
        sendSpeed(2);
      } else if (button == btnSpeed3) {
        sendSpeed(3);
      } else if (button == btnSpeed4) {
        sendSpeed(4);
      } else if (button == btnSpeed5) {
        sendSpeed(5);
      } else if (button == btnCamera) {
        if (videoFrame == null || !videoFrame.isVisible()) {
          showVideo();
        } else {
          hideVideo();
        }
      } else if (commandMap.containsKey(button)) {
        sendCommand(commandMap.get(button));
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
 public void showOutlineWindow() {
   JFrame frame = getPopupWindow();
   if (frame.isVisible()) {
     if (popupBound != null) {
       frame.setBounds(popupBound);
     }
     frame.setExtendedState(popupState);
     frame.toFront();
   } else {
     frame.setLocationRelativeTo(SwingUtilities.getRoot(this));
     frame.setVisible(true);
   }
   if (dirtyPopup) {
     popupOutline.setImage(graphOutline.getImage());
     popupOutline.updateImage();
     dirtyPopup = false;
   }
 }
    protected boolean isMatching(JFrame component) {
      String name = component.getName();
      if (name == null) return false;

      boolean isAGraphWindow = name.startsWith("Viewport Window");
      if (!isAGraphWindow) return false;

      if (!component.isVisible()) return false;

      if (currentIndex == nThToFind) {
        currentIndex++;

        return true;
      }

      currentIndex++;

      return false;
    }
  /**
   * This method should be called whenever a new set of histogram values is to be displayed (i.e.
   * when a different image gets focus).
   *
   * @param histogramData
   */
  public void setHistogramData(final HistogramDataGroup histogramData) {
    double[] minMaxView;
    double[] minMaxLUT;
    synchronized (_synchObject) {
      _histogramDataGroup = histogramData;
      _histogramDataGroup.setListener(new HistogramDataListener());
      minMaxView = _histogramDataGroup.getMinMaxView();
      minMaxLUT = _histogramDataGroup.getMinMaxLUT();
    }

    //		IJ.log("----");
    //		IJ.log("setHistogramData");
    //		IJ.log("view " + minMaxView[0] + " "  + minMaxView[1] + " lut " + minMaxLUT[0] + " " +
    // minMaxLUT[1]);
    //		IJ.log("----");

    if (null != _frame) {
      if (_frame.isVisible()) {
        _frame.setVisible(true);
      }
      _frame.setTitle(histogramData.getTitle());

      _histogramPanel.setStatistics(histogramData.getStatistics(WIDTH));

      final boolean autoRange = histogramData.getAutoRange();
      if (autoRange) {
        // turn cursors off
        _histogramPanel.setCursors(null, null);
      } else {
        // set cursors to edges
        _histogramPanel.setCursors(INSET, INSET + WIDTH - 1);
      }
      _uiPanel.setAutoRange(autoRange);
      _uiPanel.setExcludePixels(histogramData.getExcludePixels());
      _uiPanel.setCombineChannels(histogramData.getCombineChannels());
      _uiPanel.setDisplayChannels(histogramData.getDisplayChannels());
      _uiPanel.enableChannels(histogramData.hasChannels());
      _uiPanel.setMinMaxLUT(minMaxLUT[0], minMaxLUT[1]);

      _colorBarPanel.setMinMax(minMaxView[0], minMaxView[1], minMaxLUT[0], minMaxLUT[1]);
    }
  }
 public void run() {
   try {
     while (true) {
       Thread.sleep(250);
       long now = new Date().getTime();
       if (refreshRequested && ((now - lastupdate) > 1000)) {
         if (frame.isVisible()) {
           Point location = frame.getLocation();
           frame.setVisible(false);
           updateBackground();
           frame.setVisible(true);
           frame.setLocation(location);
           refresh();
         }
         lastupdate = now;
         refreshRequested = false;
       }
     }
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
Exemple #15
0
  /**
   * Solves this TSPLIB instance while displaying a GUI showing the optimization progress.
   *
   * @param instance the TSPLIB instance to solve
   */
  public static void solve(TSPInstance instance) {
    TSPPanel panel = new TSPPanel(instance);
    panel.setAutoRepaint(false);

    // create other components on the display
    StringBuilder progress = new StringBuilder();
    JTextArea progressText = new JTextArea();

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setTopComponent(panel);
    splitPane.setBottomComponent(new JScrollPane(progressText));
    splitPane.setDividerLocation(300);
    splitPane.setResizeWeight(1.0);

    // display the panel on a window
    JFrame frame = new JFrame(instance.getName());
    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(splitPane, BorderLayout.CENTER);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setSize(500, 400);
    frame.setLocationRelativeTo(null);
    frame.setIconImages(Settings.getIconImages());
    frame.setVisible(true);

    // create the optimization problem and evolutionary algorithm
    Problem problem = new TSPProblem(instance);

    Properties properties = new Properties();
    properties.setProperty("swap.rate", "0.7");
    properties.setProperty("insertion.rate", "0.9");
    properties.setProperty("pmx.rate", "0.4");

    Algorithm algorithm =
        AlgorithmFactory.getInstance().getAlgorithm("NSGAII", properties, problem);

    int iteration = 0;

    // now run the evolutionary algorithm
    while (frame.isVisible()) {
      algorithm.step();
      iteration++;

      // clear existing tours in display
      panel.clearTours();

      // display population with light gray lines
      if (algorithm instanceof EvolutionaryAlgorithm) {
        EvolutionaryAlgorithm ea = (EvolutionaryAlgorithm) algorithm;

        for (Solution solution : ea.getPopulation()) {
          panel.displayTour(toTour(solution), lightGray);
        }
      }

      // display current optimal solutions with red line
      Tour best = toTour(algorithm.getResult().get(0));
      panel.displayTour(best, Color.RED, new BasicStroke(2.0f));
      progress.insert(0, "Iteration " + iteration + ": " + best.distance(instance) + "\n");
      progressText.setText(progress.toString());

      // repaint the TSP display
      panel.repaint();
    }
  }
 @Override
 public void publish(LogRecord record) {
   if (!frame.isVisible()) return;
   super.publish(record);
   flush();
 }
Exemple #17
0
 /**
  * Provides information on visibility of the Canvas.
  *
  * @return true if canvas is visible, false otherwise
  */
 public boolean isVisible() {
   return frame.isVisible();
 }
  protected void runTestGL(
      final GLCapabilities caps,
      final FrameLayout frameLayout,
      final boolean twoCanvas,
      final boolean resizeByComp)
      throws InterruptedException, InvocationTargetException {
    final JFrame frame = new JFrame("Bug816: " + this.getTestMethodName());
    Assert.assertNotNull(frame);
    final Container framePane = frame.getContentPane();

    final GLCanvas glCanvas1 = new GLCanvas(caps);
    Assert.assertNotNull(glCanvas1);
    final GLCanvas glCanvas2;
    if (twoCanvas) {
      glCanvas2 = new GLCanvas(caps);
      Assert.assertNotNull(glCanvas2);
    } else {
      glCanvas2 = null;
    }

    final Dimension glcDim = new Dimension(width / 2, height);
    final Dimension frameDim = new Dimension(twoCanvas ? width + 64 : width / 2 + 64, height + 64);

    setComponentSize(null, glCanvas1, glcDim, glCanvas2, glcDim);

    switch (frameLayout) {
      case None:
        {
          framePane.add(glCanvas1);
        }
        break;
      case Flow:
        {
          final Container c = new Container();
          c.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
          c.add(glCanvas1);
          if (twoCanvas) {
            c.add(glCanvas2);
          }
          framePane.add(c);
        }
        break;
      case DoubleBorderCenterSurrounded:
        {
          final Container c = new Container();
          c.setLayout(new BorderLayout());
          c.add(new Button("north"), BorderLayout.NORTH);
          c.add(new Button("south"), BorderLayout.SOUTH);
          c.add(new Button("east"), BorderLayout.EAST);
          c.add(new Button("west"), BorderLayout.WEST);
          if (twoCanvas) {
            final Container c2 = new Container();
            c2.setLayout(new GridLayout(1, 2));
            c2.add(glCanvas1);
            c2.add(glCanvas2);
            c.add(c2, BorderLayout.CENTER);
          } else {
            c.add(glCanvas1, BorderLayout.CENTER);
          }
          framePane.setLayout(new BorderLayout());
          framePane.add(new Button("NORTH"), BorderLayout.NORTH);
          framePane.add(new Button("SOUTH"), BorderLayout.SOUTH);
          framePane.add(new Button("EAST"), BorderLayout.EAST);
          framePane.add(new Button("WEST"), BorderLayout.WEST);
          framePane.add(c, BorderLayout.CENTER);
        }
        break;
      case Box:
        {
          final Container c = new Container();
          c.setLayout(new BoxLayout(c, BoxLayout.X_AXIS));
          c.add(glCanvas1);
          if (twoCanvas) {
            c.add(glCanvas2);
          }
          framePane.add(c);
        }
        break;
      case Split:
        {
          final Dimension sbDim = new Dimension(16, 16);
          final JScrollPane vsp =
              new JScrollPane(
                  ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                  ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
          {
            final JScrollBar vsb = vsp.getVerticalScrollBar();
            vsb.setPreferredSize(sbDim);
            final BoundedRangeModel model = vsb.getModel();
            model.setMinimum(0);
            model.setMaximum(100);
            model.setValue(50);
            model.setExtent(1);
            vsb.setEnabled(true);
          }
          final JScrollPane hsp =
              new JScrollPane(
                  ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
                  ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
          {
            final JScrollBar hsb = hsp.getHorizontalScrollBar();
            hsb.setPreferredSize(sbDim);
            final BoundedRangeModel model = hsb.getModel();
            model.setMinimum(0);
            model.setMaximum(100);
            model.setValue(50);
            model.setExtent(1);
            hsb.setEnabled(true);
          }
          final JSplitPane horizontalSplitPane =
              new JSplitPane(
                  JSplitPane.HORIZONTAL_SPLIT, true, twoCanvas ? glCanvas2 : vsp, glCanvas1);
          horizontalSplitPane.setResizeWeight(0.5);
          final JSplitPane verticalSplitPane =
              new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, horizontalSplitPane, hsp);
          verticalSplitPane.setResizeWeight(0.5);
          framePane.add(verticalSplitPane);
        }
        break;
    }
    final GearsES2 demo1 = new GearsES2(swapInterval);
    glCanvas1.addGLEventListener(demo1);
    if (twoCanvas) {
      final RedSquareES2 demo2 = new RedSquareES2(swapInterval);
      glCanvas2.addGLEventListener(demo2);
    }

    final Animator animator = new Animator();
    animator.add(glCanvas1);
    if (twoCanvas) {
      animator.add(glCanvas2);
    }
    final QuitAdapter quitAdapter = new QuitAdapter();
    new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glCanvas1).addTo(frame);

    javax.swing.SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            if (resizeByComp) {
              frame.pack();
            } else {
              setFrameSize(frame, true, frameDim);
            }
            frame.setVisible(true);
          }
        });
    Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true));
    Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas1, true));
    if (twoCanvas) {
      Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas2, true));
    }

    animator.start();
    Assert.assertTrue(animator.isStarted());
    Assert.assertTrue(animator.isAnimating());

    System.err.println(
        "canvas1 pos/siz: "
            + glCanvas1.getX()
            + "/"
            + glCanvas1.getY()
            + " "
            + glCanvas1.getSurfaceWidth()
            + "x"
            + glCanvas1.getSurfaceHeight());
    if (twoCanvas) {
      System.err.println(
          "canvas2 pos/siz: "
              + glCanvas2.getX()
              + "/"
              + glCanvas2.getY()
              + " "
              + glCanvas2.getSurfaceWidth()
              + "x"
              + glCanvas2.getSurfaceHeight());
    }

    Thread.sleep(Math.max(1000, duration / 2));
    if (null != rwsize) {
      final Dimension compRSizeHalf = new Dimension(rwsize.width / 2, rwsize.height);
      final Dimension frameRSizeHalf =
          new Dimension(twoCanvas ? rwsize.width + 64 : rwsize.width / 2 + 64, rwsize.height + 64);
      if (resizeByComp) {
        setComponentSize(frame, glCanvas1, compRSizeHalf, glCanvas2, compRSizeHalf);
      } else {
        setFrameSize(frame, true, frameRSizeHalf);
      }
      System.err.println(
          "resize canvas1 pos/siz: "
              + glCanvas1.getX()
              + "/"
              + glCanvas1.getY()
              + " "
              + glCanvas1.getSurfaceWidth()
              + "x"
              + glCanvas1.getSurfaceHeight());
      if (twoCanvas) {
        System.err.println(
            "resize canvas2 pos/siz: "
                + glCanvas2.getX()
                + "/"
                + glCanvas2.getY()
                + " "
                + glCanvas2.getSurfaceWidth()
                + "x"
                + glCanvas2.getSurfaceHeight());
      }
    }

    final long t0 = System.currentTimeMillis();
    long t1 = t0;
    while (!quitAdapter.shouldQuit() && t1 - t0 < duration) {
      Thread.sleep(100);
      t1 = System.currentTimeMillis();
    }

    Assert.assertNotNull(frame);
    Assert.assertNotNull(glCanvas1);
    if (twoCanvas) {
      Assert.assertNotNull(glCanvas2);
    } else {
      Assert.assertNull(glCanvas2);
    }

    Assert.assertNotNull(animator);
    animator.stop();
    Assert.assertFalse(animator.isAnimating());
    Assert.assertFalse(animator.isStarted());

    javax.swing.SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            frame.setVisible(false);
          }
        });
    Assert.assertEquals(false, frame.isVisible());
    javax.swing.SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            frame.remove(glCanvas1);
            if (twoCanvas) {
              frame.remove(glCanvas2);
            }
            frame.dispose();
          }
        });
  }
  public boolean compute() throws IOException {
    features = loadFeatureList();
    if (!features.contentEquals("")) {
      features = features.replaceAll(" ", "\n");
      features = features.replaceFirst("unit_duration", "");
      features = features.replaceFirst("unit_logf0delta", "");
      features = features.replaceFirst("unit_logf0", "");
    }

    final JFrame frame = new JFrame("Extra features for training HMMs");
    GridBagLayout gridBagLayout = new GridBagLayout();
    GridBagConstraints gridC = new GridBagConstraints();
    frame.getContentPane().setLayout(gridBagLayout);

    final JEditorPane editPane = new JEditorPane();
    editPane.setPreferredSize(new Dimension(500, 500));
    editPane.setText(features);

    JButton saveButton = new JButton("Save");
    saveButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            setSuccess(true);
            frame.setVisible(false);
          }
        });
    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            setSuccess(false);
            frame.setVisible(false);
          }
        });

    gridC.gridx = 0;
    gridC.gridy = 0;
    // resize scroll pane:
    gridC.weightx = 1;
    gridC.weighty = 1;
    gridC.fill = GridBagConstraints.HORIZONTAL;
    JScrollPane scrollPane = new JScrollPane(editPane);
    scrollPane.setPreferredSize(editPane.getPreferredSize());
    gridBagLayout.setConstraints(scrollPane, gridC);
    frame.getContentPane().add(scrollPane);
    gridC.gridy = 1;
    // do not resize buttons:
    gridC.weightx = 0;
    gridC.weighty = 0;
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout());
    buttonPanel.add(saveButton);
    buttonPanel.add(cancelButton);
    gridBagLayout.setConstraints(buttonPanel, gridC);
    frame.getContentPane().add(buttonPanel);
    frame.pack();
    frame.setVisible(true);

    do {
      try {
        Thread.sleep(10);
      } catch (InterruptedException e) {
      }
    } while (frame.isVisible());
    frame.dispose();

    if (success) {
      try {
        saveFeatures(editPane.getText());
      } catch (Exception ex) {
        ex.printStackTrace();
        throw new Error("Error defining replacements");
      }
    }

    return success;
  }
  /**
   * updates all the drawn objects
   *
   * @param delta time since the last update
   */
  @Override
  public void update(double delta) {

    for (Drawable2D drawable : drawList) {
      drawable.update(delta); // update the drawable

      if (!(drawable.equals(player))) { // if the drawable is not the player

        if (drawable.getClass().equals(Room2D.class)) {
          ExitDirection direction = ((Room2D) drawable).inExitBounds(player.getBounds());
          if (direction != null) { // if the player is in the exit bounds
            Point newPlayerLocation =
                new Point(drawable.getBounds().width / 2, drawable.getBounds().height / 2);
            player.setLocation(newPlayerLocation); // set player to the middle of the room
            notifyInputListeners(
                new InputEvent2D(new Command(CommandWord.go, direction.toString())));
          }
          continue;
        }

        // if the drawable is not the player and collides with the player
        if (collidingWithObject == null) {
          if (player.collidesWith(drawable)) {
            if (drawable.getClass().equals(Monster2D.class)) { // if player collides with a monster
              String monsterName =
                  ((Monster2D) drawable).getName(); // send input messages if it does collide
              notifyInputListeners(new InputEvent2D(new Command(CommandWord.attack, monsterName)));

              collidingWithObject = drawable;
              if (characterWindow != null && characterWindow.isVisible()) {
                characterWindow();
              }
            } else if (drawable
                .getClass()
                .equals(Item2D.class)) { // if player collides with an item
              String itemName = ((Item2D) drawable).getName();
              notifyInputListeners(new InputEvent2D(new Command(CommandWord.take, itemName)));

              collidingWithObject = drawable;
              if (inventoryWin != null && inventoryWin.isVisible()) {
                inventoryWindow();
              }
            }
          }
        } else {
          if (!player.collidesWith(
              collidingWithObject)) { // check if you move out of the colliding objects bounds
            collidingWithObject = null; // we are off the other object, set it to null
          }
        }
      }
    }

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            drawArea.repaint();
            mapArea.repaint();
            textAreaPanel.repaint();
            mainWindow.repaint();
            mainWindow.validate();
          }
        });
  }
 public boolean getStatus() {
   if (frmAddNewContact.isVisible()) return true;
   return false;
 }
  /**
   * converts from actionEvent (from inventory button) to InputEvent2D and notifies
   *
   * @param arg0 the ActionEvent
   */
  @Override
  public void actionPerformed(ActionEvent event) {
    if (event.getSource().getClass().equals(JButton.class)) {
      JButton pressed = (JButton) (event.getSource());
      if (pressed.equals(inventoryButton)) {
        notifyInputListeners(new InputEvent2D(new Command(CommandWord.inventory, null)));
        if (inventoryWin != null
            && inventoryWin
                .isDisplayable()) { // closes window if its already open when you click the button
          inventoryWin.dispose();
        } else {
          inventoryWindow();
        }
      } else if (pressed.equals(characterButton)) {
        notifyInputListeners(new InputEvent2D(new Command(CommandWord.character, null)));
        if (characterWindow != null && characterWindow.isDisplayable()) {
          characterWindow.dispose();
        } else {
          characterWindow();
        }
      } else if (pressed.equals(undoButton)) {
        notifyInputListeners(new InputEvent2D(new Command(CommandWord.undo, null)));
      } else if (pressed.equals(redoButton)) {
        notifyInputListeners(new InputEvent2D(new Command(CommandWord.redo, null)));
      } else if (pressed.equals(helpButton)) {
        notifyInputListeners(new InputEvent2D(new Command(CommandWord.help, null)));
      } else if (pressed.equals(quitButton)) {
        notifyInputListeners(new InputEvent2D(new Command(CommandWord.quit, null)));
      } else if (pressed.equals(saveButton)) {
        notifyInputListeners(new InputEvent2D(new Command(CommandWord.save, null)));
      } else if (pressed.getClass().equals(JButton.class)) { // inventory or character button
        JButton src = (JButton) event.getSource();
        if (src.getText().startsWith("drop")) {
          notifyInputListeners(
              new InputEvent2D(new Command(CommandWord.drop, "" + src.getText().substring(5))));

        } else {
          notifyInputListeners(new InputEvent2D(new Command(CommandWord.use, "" + src.getText())));
        }
        // updates windows
        if (inventoryWin != null && inventoryWin.isVisible()) {
          inventoryWindow();
        }
        if (characterWindow != null && characterWindow.isVisible()) {
          characterWindow();
        }
      }
    }
    if (event.getSource().getClass().equals(JTextField.class)) {
      JTextField source = (JTextField) (event.getSource());

      displayMessage(source.getText());

      String word1 = null;
      String word2 = null;

      Scanner tokenizer = new Scanner(source.getText());
      if (tokenizer.hasNext()) {
        word1 = tokenizer.next(); // get first word
        if (tokenizer.hasNext()) {
          word2 = tokenizer.next(); // get second word
          // note: we just ignore the rest of the input line.
        }
      }
      tokenizer.close();

      Command toNotify = new Command(CommandWord.getCommandFromString(word1), word2);
      notifyInputListeners(new InputEvent2D(toNotify));

      source.setText("");
    }
  }