/**
   * Method declaration
   *
   * @param s
   */
  private void addToRecent(String s) {

    for (int i = 0; i < iMaxRecent; i++) {
      if (s.equals(sRecent[i])) {
        return;
      }
    }

    if (sRecent[iRecent] != null) {
      mRecent.remove(iRecent);
    }

    sRecent[iRecent] = s;

    if (s.length() > 43) {
      s = s.substring(0, 40) + "...";
    }

    MenuItem item = new MenuItem(s);

    item.setActionCommand("#" + iRecent);
    item.addActionListener(this);
    mRecent.insert(item, iRecent);

    iRecent = (iRecent + 1) % iMaxRecent;
  }
Example #2
0
  @Test
  public void testSetGetName() {

    Menu testMenu = new Menu(12345);
    testMenu.setName("Denny's Menu");

    assertEquals("Denny's Menu", testMenu.getName());
  }
Example #3
0
  @Test
  public void testSetGetEvent() {

    Menu testMenu = new Menu(67890);
    testMenu.setEvent("Easter Dinner");

    assertEquals("Easter Dinner", testMenu.getEvent());
  }
Example #4
0
 public void ramasserObjet() {
   boolean vide = true;
   try {
     ResultSet rset =
         stmt.executeQuery(
             "select idObjet from objet where positionX="
                 + positionX
                 + " and positionY="
                 + positionY);
     Hashtable<String, String> tabObj = new Hashtable<String, String>();
     while (rset.next()) {
       vide = false;
       String idObj = rset.getString("idObjet");
       System.out.println(idObj);
       tabObj.put(idObj, idObj);
     }
     rset.close();
     if (!vide) {
       System.out.println("Quel objet voulez vous ramasser ? : ");
       String obj = IO.lireChaine();
       if (tabObj.containsKey(obj)) {
         proc = conn.prepareCall("{call rammasser(?,?)}");
         proc.setInt(1, idTroll);
         proc.setString(2, obj);
         proc.executeUpdate();
         proc.close();
         rset = stmt.executeQuery("select typeObjet from objet where idObjet='" + obj + "'");
         rset.first();
         String type = rset.getString("typeObjet");
         if (type.equals("potion")) {
           menu.supprimerPopo(obj);
         } else {
           menu.supprimerObjet(obj);
         }
         rset = stmt.executeQuery("select paRestants from troll where idTroll=" + idTroll);
         int ancVal = 0;
         while (rset.next()) {
           ancVal = rset.getInt("paRestants");
         }
         stmt.executeUpdate(
             "update troll SET paRestants = " + (ancVal - 1) + " where idTroll=" + idTroll);
         paRestants = paRestants - 1;
       } else {
         System.out.println("Cet objet ne se trouve pas sur votre case !");
       }
     } else {
       System.out.println("Il n'y a aucun objet sur votre case");
     }
   } catch (SQLException E) {
     System.err.println("SQLException: " + E.getMessage());
     System.err.println("SQLState:     " + E.getSQLState());
   }
 }
  /**
   * Method declaration
   *
   * @param f
   * @param m
   */
  void addMenuItems(Menu f, String m[]) {

    for (int i = 0; i < m.length; i++) {
      MenuItem item = new MenuItem(m[i].substring(1));
      char c = m[i].charAt(0);

      if (c != '-') {
        item.setShortcut(new MenuShortcut(c));
      }

      item.addActionListener(this);
      f.add(item);
    }
  }