Exemple #1
0
  /** Get ready for a new game, given a letter list specification of the Boggle board. */
  public void newGame() {
    myBoard = BoggleBoardFactory.getBoard(myBoardSize);
    mySeconds = 0;
    myProgress.setValue(0);

    // set up views for new game

    if (myBoardSize == 4) {
      if (myBoardPanel != myBoardPanel4) {
        myBoardPanel = myBoardPanel4;
        getContentPane().remove(myBoardPanel5);
        getContentPane().add(myBoardPanel, BorderLayout.CENTER);
      }
    } else {
      if (myBoardPanel != myBoardPanel5) {
        myBoardPanel = myBoardPanel5;
        getContentPane().remove(myBoardPanel4);
        getContentPane().add(myBoardPanel, BorderLayout.CENTER);
      }
    }

    myBoardPanel.newGame();
    humanArea.setReady();
    computerArea.setReady();
    myBoardPanel.unHighlightAllDice();
    wordEntryField.setReady();
    ((JPanel) getContentPane()).revalidate();
    repaint();
    myTimer.start();
  }
 public void actionPerformed(ActionEvent e) {
   if (isVisible()) {
     repaint();
   } else {
     animator.stop();
   }
 }
Exemple #3
0
 public void gameOver() {
   myTimer.stop();
   mySeconds = myGameLength; // ensure over
   myProgress.setValue(myGameLength);
   repaint();
   wordEntryField.setUnready();
   computerPlay();
 }
Exemple #4
0
 public void setVisible(boolean bShow, String title) {
   if (bShow) {
     String strDir = "";
     String strFreq = "";
     String strTraynum = "";
     m_strHelpFile = getHelpFile(title);
     String strSampleName = getSampleName(title);
     String frameBounds = getFrameBounds(title);
     StringTokenizer tok = new QuotedStringTokenizer(title);
     if (tok.hasMoreTokens()) strDir = tok.nextToken();
     if (tok.hasMoreTokens()) strFreq = tok.nextToken();
     if (tok.hasMoreTokens()) strTraynum = tok.nextToken();
     else {
       try {
         Integer.parseInt(strDir);
         // if strdir is number, then strdir is empty, and the
         // strfreq is the number
         strTraynum = strFreq;
         strFreq = strDir;
         strDir = "";
       } catch (Exception e) {
       }
     }
     try {
       setTitle(gettitle(strFreq));
       m_lblSampleName.setText("3");
       boolean bVast = isVast(strTraynum);
       CardLayout layout = (CardLayout) m_pnlSampleName.getLayout();
       if (!bVast) {
         if (strSampleName == null) {
           strSampleName = getSampleName(strDir, strTraynum);
         }
         m_lblSampleName.setText(strSampleName);
         layout.show(m_pnlSampleName, OTHER);
       } else {
         m_strDir = strDir;
         setTrays();
         layout.show(m_pnlSampleName, VAST);
         m_trayTimer.start();
       }
       boolean bSample = bVast || !strSampleName.trim().equals("");
       m_pnlSampleName.setVisible(bSample);
       m_lblLogin.setForeground(getBackground());
       m_lblLogin.setVisible(false);
       m_passwordField.setText("");
       m_passwordField.setCaretPosition(0);
     } catch (Exception e) {
       Messages.writeStackTrace(e);
     }
     setBounds(frameBounds);
     ExpPanel exp = Util.getActiveView();
     if (exp != null) exp.waitLogin(true);
   }
   writePersistence();
   setVisible(bShow);
 }
Exemple #5
0
 public void actionPerformed(ActionEvent e) {
   UServerStatus status = fServer.nextStatus();
   switch (status.getState()) {
     case UServerStatus.AFTER_SETTLEMENT:
       fUpdateTimer.stop();
       break;
     case UServerStatus.ACCEPT_ORDERS:
       fServer.recieveOrdersFromLocalAgents();
       break;
   }
   fGui.gUpdate();
 }
 public Screen() {
   myWave = new Wave();
   tt = new RadiationTower(500, 600);
   y = new RadiationTower(1000, 600);
   x = new Automaton_1000(600, 500);
   theMinion = new Red(new ImageIcon("MINIONPURPLEFRONT.gif"));
   theWave = myWave.getWave();
   mm = new Minion(new ImageIcon("MINIONFRONT.gif"));
   // b = new Bullet(mm, tt);
   t = new javax.swing.Timer(10, new Listener()); // adjust speed by changing the int parameter
   t
       .start(); // by altering when you call this method you can choose the start of the minion
                 // pathing!
   // t.stop(); how to stop the javax.swing.Timer
   //         a = new javax.swing.Timer(10, new BulletListener());
   //         a.start();
   thread.start();
 }
  public void actionPerformed(ActionEvent e) {
    Object o = e.getSource();

    for (JRadioButton u : ub) {
      if (o == u) {
        mapTM.setUnitType(u.getText());
        System.out.println("Set unit type - " + u.getText());
        return;
      }
    }

    if (o == timer) {

      /*
      mmLabel.setText("Main Menu ("+(cdTime--)+")");

      if(cdTime == 0){
      	timer.stop();
      	gsButton.setText("Game Start");
      	mmLabel.setText("Main Menu");

      	ArrayList<Building> bArr = new ArrayList<Building>();

      	String temp = "Elixir Collector-24,8-960|Elixir Collector-31,8-960|Gold Mine-17,10-960|Elixir Collector-25,21-960|Elixir Collector-11,22-960";
      	String[] bs = temp.split("\\|");
      	for(String b : bs){
      		String[] bParts = b.split("-");
      		String[] cParts = bParts[1].split(",");
      		int x = Integer.parseInt(cParts[0].trim());
      		int y = Integer.parseInt(cParts[1].trim());

      		Building tb = new Building(bParts[0], new Coordinate(x,y));
      		tb.setHp(Integer.parseInt(bParts[2].trim()));

      		bArr.add(tb);
      	}



      	mapTM.setBuildings(bArr);
      	switchCards("TM");
      }
      */

      return;
    }

    if (o == gsButton) {

      if (timer.isRunning()) {
        // timer.stop();
        gsButton.setText("Game Start");
        mmLabel.setText("Main Menu");
        // sends the leave command
        client.sendUDP("leave~" + unameUDP);
        return;
      }
      // sends the joinlobby command
      client.sendUDP("joinlobby~" + unameUDP);
      // gsButton.setText("Game Stop");
      String serverResp = client.receiveUDP();

      if (serverResp.trim().equals("false")) {

        // place false handler here

      } else {

        String[] enemies = serverResp.trim().split(",");
        ArrayList<Building> bArr = new ArrayList<Building>();
        String mapConfig = getBaseConfig(enemies[0]);
        String[] bs = mapConfig.split("\\|");
        for (String b : bs) {

          String[] bParts = b.split("-");
          String[] cParts = bParts[1].split(",");
          int x = Integer.parseInt(cParts[0].trim());
          int y = Integer.parseInt(cParts[1].trim());

          Building tb = new Building(bParts[0], new Coordinate(x, y));
          tb.setHp(Integer.parseInt(bParts[2].trim()));
          bArr.add(tb);
        }

        mapTM.setBuildings(bArr);
        switchCards("TM");
      }

      // System.out.println(serverResp);
      // cdTime = 10;
      // timer.start();
      return;
    }

    if (o == logout) {
      client.sendMessage(new ChatMessage(ChatMessage.LOGOUT, ""));
      chatArea.setText("");

      switchCards("Login");
      return;
    }

    if (o == cmButton) {
      String baseConfig = getBaseConfig();
      System.out.println("base config: " + baseConfig);

      for (int i = 0; i < mapSize; i++) {
        for (int j = 0; j < mapSize; j++) {
          tiles[i][j].setValue("");
        }
      }

      if (!baseConfig.equals("")) {

        String[] bs = baseConfig.split("\\|");
        for (String b : bs) {
          String[] bParts = b.split("-");
          String[] cParts = bParts[1].split(",");
          int x = Integer.parseInt(cParts[0].trim());
          int y = Integer.parseInt(cParts[1].trim());

          int index = 0;
          for (int i = 0; i < bb.size(); i++) {
            if (bb.get(i).getText().split("-")[0].trim().equals(bParts[0])) {
              index = i;
              break;
            }
          }
          insertBuilding(y, x, index);
        }
      }

      switchCards("CM");

      return;
    }

    if (o == tmButton) {

      ArrayList<Building> bArr = new ArrayList<Building>();

      for (int i = 0; i < 40; i++) {
        for (int j = 0; j < 40; j++) {
          if (tiles[i][j].getValue().equals("") || tiles[i][j].getValue().contains("-")) {
            continue;
          }
          // weird part here
          bArr.add(new Building(tiles[i][j].getValue(), new Coordinate(j, i)));
        }
      }

      mapTM.setBuildings(bArr);

      switchCards("TM");
      return;
    }

    // if it the who is in button
    if (o == whoIsIn) {
      client.sendMessage(new ChatMessage(ChatMessage.WHOISIN, ""));
      return;
    }

    if (o == cmBack) {
      ArrayList<Building> bArr = new ArrayList<Building>();
      for (int i = 0; i < 40; i++) {
        for (int j = 0; j < 40; j++) {
          if (tiles[i][j].getValue().equals("") || tiles[i][j].getValue().contains("-")) {
            continue;
          }
          // weird part here
          bArr.add(new Building(tiles[i][j].getValue(), new Coordinate(j, i)));
        }
      }

      String temp = "mapdata~" + unameUDP + "~";
      int tileCount = 40;
      int dim = 600;
      int tileDim = (int) (dim / tileCount);
      int counter = 0;
      for (Building b : bArr) {
        int x, y, hp;
        x = b.getPos().getX() / tileDim;
        y = b.getPos().getY() / tileDim;
        hp = b.getHp();
        temp += b.getName() + "-" + x + "," + y + "-" + hp + "|";
        counter += 1;
      }
      if (counter > 0) {
        temp = temp.substring(0, temp.length() - 1); // removes the last '|'
      } else {
        temp += "none";
      }

      client.sendUDP(temp); // allows saving of the current state of the map into the user's account

      switchCards("Menu");

      return;
    }
    if (o == tmBack) {
      switchCards("Menu");

      return;
    }

    for (int i = 0; i < 40; i++) {
      for (int j = 0; j < 40; j++) {
        if (o == tiles[i][j]) {
          for (int k = 0; k < bb.size(); k++) {
            if (bb.get(k).isSelected()) {
              if (bb.get(k).getText().equals("Remove Building")) {
                removeBuilding(i, j);
                return;
              }

              insertBuilding(i, j, k);
              // JOptionPane.showMessageDialog(null, bb.get(k).getText());
              return;
            }
          }

          // JOptionPane.showMessageDialog(null, "i-"+i+" j-"+j);
          return;
        }
      }
    }

    // ok it is coming from the JTextField
    if (connected) {
      // just have to send the message
      client.sendMessage(new ChatMessage(ChatMessage.MESSAGE, chatField.getText()));
      chatField.setText("");
      return;
    }

    if (o == login) {
      // ok it is a connection request
      String username = usernameField.getText().trim();
      String password = passwordField.getText().trim();
      // empty username ignore it
      if (username.length() == 0) return;
      // empty serverAddress ignore it
      String server = tfServer.getText().trim();
      if (server.length() == 0) return;
      // empty or invalid port numer, ignore it
      String portNumber = tfPort.getText().trim();
      if (portNumber.length() == 0) return;
      int port = 0;
      try {
        port = Integer.parseInt(portNumber);
      } catch (Exception en) {
        return; // nothing I can do if port number is not valid
      }

      // try creating a new Client with GUI
      client = new Client(server, port, username, password, this);
      // test if we can start the Client
      if (!client.start()) return;

      unameUDP = username;

      switchCards("Menu");
      // fetching of the base_config string from the database

      chatField.setText("");
      chatArea.setText("");
    }
  }
Exemple #8
0
  /**
   * Save the data to the file. Read the data from the file, and copy everything to the
   * stringbuffer. The lines in the file are of the form:
   * auditDir:system:/vnmr/part11/auditTrails:system file:standard:text:yes Based on these formats,
   * get the value of either the directory or the checkbox from the corresponding components, and
   * replace that value in the stringbuffer.
   */
  protected void saveData() {
    BufferedReader reader = WFileUtil.openReadFile(m_strPath);
    String strLine = null;
    StringBuffer sbData = new StringBuffer();
    if (reader == null) return;

    int nLineInd = 0;
    try {
      while ((strLine = reader.readLine()) != null) {
        // if the line starts with a comment from sccs, add '#' to it,
        // to make it a comment
        if (strLine.startsWith("%") || strLine.startsWith("@")) strLine = "# " + strLine;

        if (strLine.startsWith("#")) {
          sbData.append(strLine + "\n");
          continue;
        }
        StringTokenizer sTok = new StringTokenizer(strLine, File.pathSeparator);
        boolean bFile = false;
        boolean bLineEnd = false;
        boolean bDir = false;

        for (int i = 0; sTok.hasMoreTokens(); i++) {
          String strValue = sTok.nextToken();
          if (i == 0) {
            bFile = strValue.equalsIgnoreCase("file") ? true : false;
            bDir = false;
            if (strValue.equalsIgnoreCase("dir")) bDir = true;
          } else {
            // Case => file:standard:procpar:yes
            // skip over 'standard', 'procpar',
            // and get the value 'yes' or 'no' from the checkbox
            if (bFile) {
              if (i == 3) {
                String strNewValue = getValue(nLineInd);
                if (strNewValue != null) strValue = strNewValue;
                bLineEnd = true;
              } else bLineEnd = false;
            } else if (bDir) {
              bLineEnd = false;
              if (i == 3) bLineEnd = true;
            }
            // Case => part11Dir:/vnmr/part11/data 0r
            // Case => dataType:FDA
            // skip over 'part11Dir'
            // and get the value of the directory from the textfield,
            // or from the combobox
            else {
              if (i == 1) {
                String strNewValue = getValue(nLineInd);
                if (strNewValue != null) strValue = strNewValue;
                bLineEnd = true;
              } else bLineEnd = false;
            }
          }
          // copy the value to the stringbuffer
          sbData.append(strValue);
          if (!bLineEnd) sbData.append(File.pathSeparator);
        }
        nLineInd++;
        sbData.append("\n");
      }
      // write the data to the file
      reader.close();
      BufferedWriter writer = WFileUtil.openWriteFile(m_strPath);
      WFileUtil.writeAndClose(writer, sbData);
      m_objTimer =
          new javax.swing.Timer(
              200,
              new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                  VItemAreaIF.firePropertyChng(Global.PART11_CONFIG_FILE, "all", "");
                  m_objTimer.stop();
                }
              });
      m_objTimer.start();
    } catch (Exception e) {
      Messages.writeStackTrace(e);
      // e.printStackTrace();
      Messages.postDebug(e.toString());
    }
  }
 public void go() {
   animator = new javax.swing.Timer(22 + 22 + 22, this);
   animator.start();
 }
Exemple #10
0
 public UServerManager() {
   try {
     ULogoWindow logow = new ULogoWindow();
     logow.setVisible(true);
     Thread.sleep(2500);
     logow.dispose();
   } catch (Exception ex) {
     ex.printStackTrace();
   }
   fParam.setConnectionType(UParameters.CONNECTION_TYPE_NETWORK);
   fParamDialog = new UServerManagerParamDialog();
   fParamDialog.setLocationRelativeTo((Frame) null);
   fParamDialog.setVisible(true);
   if (!fParamDialog.getStatus()) {
     System.exit(0);
     // 以下の部分はサーバの初期化による出力を拾えないための方策.
     // 非常にまずいが仕方ない.標準出力タブは必ず入れる.
   }
   System.setOut(UParameters.fPrintStream);
   fUpdateTimer = new javax.swing.Timer(fInterval * 1000, this);
   fUpdateTimer.setInitialDelay(0);
   fServer =
       new UMartNetwork(
           fParam.getMemberLog(),
           fParam.getPriceInfoDB(),
           fParam.getStartPoint(),
           fParam.getSeed(),
           fParam.getDays(),
           fParam.getBoardPerDay(),
           fParamNet.getPort());
   if (fParam.isLogCreate()) {
     try {
       fServer.initLog();
     } catch (IOException ioex) {
       JOptionPane.showMessageDialog(
           null,
           fRb.getString("ERROR_CANNOT_CREATE_LOGS"),
           fRb.getString("ERROR_DIALOG_TITLE"),
           JOptionPane.ERROR_MESSAGE);
       System.exit(5);
     } catch (Exception ex) {
       StringWriter sw = new StringWriter();
       PrintWriter pw = new PrintWriter(sw);
       ex.printStackTrace(pw);
       JOptionPane.showMessageDialog(
           null,
           fRb.getString("ERROR_FATAL") + "\n" + sw.toString(),
           fRb.getString("ERROR_DIALOG_TITLE"),
           JOptionPane.ERROR_MESSAGE);
       System.exit(5);
     }
   }
   fServer.startLoginManager();
   initAgents(fParam.getMachineAgentArray());
   fGui = new UServerManagerMainWindow(this, fParam.getTabs());
   fParam.setMainComponet(fGui);
   fGui.setTimer(fUpdateTimer);
   fGui.mainImpl();
   ActionListener guiUpdater =
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           fGui.gUpdate();
         }
       };
   fGuiUpdateTimer = new javax.swing.Timer(TIMER_INTERVAL * 1000, guiUpdater);
   fGuiUpdateTimer.start();
   // 1日目の1回目の注文期間に進めておく
   fUpdateTimer.setRepeats(false);
   fUpdateTimer.start();
 }
Exemple #11
0
  protected void enterLogin() {
    char[] password = m_passwordField.getPassword();
    String strUser = (String) m_cmbUser.getSelectedItem();
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    boolean blogin = WUserUtil.isOperatorNameok(strUser, false);
    if (blogin) {
      blogin = vnmrjPassword(strUser, password);
      if (!blogin) blogin = unixPassword(strUser, password);
    }
    if (blogin) {
      m_lblLogin.setForeground(Color.black);
      m_lblLogin.setText("Login Successful");
      m_lblLogin.setVisible(true);
      // Get the Email column string for access to the operator data
      String emStr = vnmr.util.Util.getLabel("_admin_Email");
      String stremail = WUserUtil.getOperatordata(strUser, emStr);

      // Get the Panel Level column string for access to the operator data
      String plStr = vnmr.util.Util.getLabel("_admin_Panel_Level");
      String strPanel = WUserUtil.getOperatordata(strUser, plStr);

      if (stremail == null || stremail.equals("null")) stremail = "";
      try {
        Integer.parseInt(strPanel);
      } catch (Exception e) {
        strPanel = WGlobal.PANELLEVEL;
      }
      m_trayTimer.stop();
      Messages.postDebug(" Login: "******"appdir('reset','")
                .append(strUser)
                .append("','")
                .append(stremail)
                .append("',")
                .append(strPanel)
                .append(")")
                .toString());
        exp.sendToVnmr("vnmrjcmd('util', 'bgReady')\n");
      }
      setVisible(false);

      // Save the current position and size of this panel in case it
      // was changed
      Dimension size = getSize();
      width = size.width;
      height = size.height;
      position = getLocation();
      writePersistence();

      // Call the macro to update this operator's
      // ExperimentSelector_operatorName.xml file
      // from the protocols themselves.  This macro will
      // cause an update of the ES when it is finished

      // Util.getAppIF().sendToVnmr("updateExpSelector");

      // I am not sure why we need to force updates since updateExpSelector
      // should have caused an update by writing to ES_op.xml file.
      // However, it works better if we do the force update.
      // ExpSelector.setForceUpdate(true);
    } else {
      m_lblLogin.setForeground(DisplayOptions.getColor("Error"));
      // m_lblLogin.setText("<HTML>Incorrect username/password <p> Please try again </HTML>");
      m_lblLogin.setVisible(true);
    }
    setCursor(Cursor.getDefaultCursor());
  }