Exemple #1
0
  public void showAllRecordForm() {
    fmAllRecords = new Form("All records");
    try {
      RecordEnumeration recEnum = rs.enumerateRecords(null, null, false);
      while (recEnum.hasNextElement()) {
        try {
          // System.out.println(new String(recEnum.nextRecord()));
          String name = "Nenacetl jsem";
          int number = 0;
          try {
            byte[] record = recEnum.nextRecord();
            ByteArrayInputStream buffer = new ByteArrayInputStream(record);
            DataInputStream dis = new DataInputStream(buffer);
            name = dis.readUTF();
            number = dis.readInt();
            dis.close();
          } catch (Exception e) {
          }

          fmAllRecords.append(name + " " + String.valueOf(number) + "\n");
        } catch (Exception e) {
          System.out.println(e.getMessage());
        }

        //
      }
    } catch (Exception ex) {
      System.out.println(ex.getMessage());
    }
    fmAllRecords.addCommand(cmdMenu);
    fmAllRecords.setCommandListener(this);
    dsp.setCurrent(fmAllRecords);
  }
 /**
  * Muestra un mensaje de aviso del tipo que se le especifique
  *
  * @param tipo Es el tipo de mensaje a mostrar.<br>
  *     0 representa una excepción genérica<br>
  *     1 representa un intento de conexión fallido debido a que el servidor no ha aceptado nuestra
  *     petición<br>
  *     2 representa un error al escoger el dispositivo con el que conectarnos.
  * @param d Display sobre el que mostrar el mensaje
  * @param ex Es la excepción que ha provocado el mensaje de error (en caso de que se muestre un
  *     mensaje debido a una excepción)
  */
 public void mostrarAlarma(int tipo, Display d, Exception ex) {
   Alert alerta = null;
   if (tipo == 0) {
     alerta =
         new Alert(
             "ERROR EN LA APLICACION",
             "Se ha producido el siguiente error en la aplicación:\n" + ex.getMessage(),
             null,
             AlertType.ERROR);
   } else if (tipo == 1) {
     alerta =
         new Alert(
             "PETICIÓN RECHAZADA",
             "El usuario el que queria recibir cartas ha rechazado su conexión",
             null,
             AlertType.INFO);
   } else if (tipo == 2) {
     alerta =
         new Alert(
             "IMPLOSIBLE CONEXIÓN",
             "Este dispositivo no ofrece la posibilidad de intercambiar cartas con usted",
             null,
             AlertType.INFO);
   }
   alerta.setTimeout(Alert.FOREVER);
   display.setCurrent(alerta, this);
 }
Exemple #3
0
  public void paint(Graphics g) {
    int w = getWidth();
    int h = getHeight();

    try {
      g.drawImage(img, w / 2, h / 2, Graphics.VCENTER | Graphics.HCENTER);
    } catch (Exception e) {
      g.drawString(e.getMessage(), w / 2, h / 2, Graphics.BASELINE | Graphics.HCENTER);
    }
  }
 public LoginExample() {
   form = new Form("Sign in");
   userName = new TextField("LoginID:", "", 30, TextField.ANY);
   password = new TextField("Password:"******"", 30, TextField.PASSWORD);
   cancel = new Command("Cancel", Command.CANCEL, 2);
   login = new Command("Login", Command.OK, 2);
   try {
     img = Image.createImage("/logo.png");
     imge = Image.createImage("/front_left1_bad.png");
     img2 = Image.createImage("/Congratulations-1.png");
   } catch (Exception e) {
     System.out.println(e.getMessage());
   }
 }
Exemple #5
0
  private String getContent(String url) {
    HttpConnection httemp = null;
    InputStream istemp = null;
    String content = "";

    try {
      httemp = (HttpConnection) Connector.open(url);
      httemp.setRequestProperty("Connection", "cl" + "ose");
      if (HttpConnection.HTTP_OK != httemp.getResponseCode()) {
        throw new IOException();
      }

      istemp = httemp.openInputStream();
      int length = (int) httemp.getLength();
      if (-1 != length) {
        byte[] bytes = new byte[length];
        istemp.read(bytes);
        content = new String(bytes);

      } else {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        while (true) {
          int ch = istemp.read();
          if (-1 == ch) break;
          bytes.write(ch);
        }
        content = new String(bytes.toByteArray());
        bytes.close();
      }

    } catch (Exception e) {
      content = "Error: " + e.getMessage();
    }
    try {
      httemp.close();
      istemp.close();
    } catch (Exception e) {
    }
    return StringConvertor.removeCr(content);
  }
Exemple #6
0
    /**
     * Get the list of suites for the user to install. The suites that are listed are the links on a
     * web page that end with .jad.
     */
    public void run() {
      StreamConnection conn = null;
      InputStreamReader in = null;
      String errorMessage;
      long startTime;

      startTime = System.currentTimeMillis();

      try {
        parent.displayProgressForm(
            Resource.getString(ResourceConstants.AMS_DISC_APP_GET_INSTALL_LIST),
            "",
            url,
            0,
            Resource.getString(ResourceConstants.AMS_GRA_INTLR_CONN_GAUGE_LABEL));
        conn = (StreamConnection) Connector.open(url, Connector.READ);
        in = new InputStreamReader(conn.openInputStream());
        try {
          parent.updateProgressForm(
              "", 0, Resource.getString(ResourceConstants.AMS_DISC_APP_GAUGE_LABEL_DOWNLOAD));

          parent.installList = SuiteDownloadInfo.getDownloadInfoFromPage(in);

          if (parent.installList.size() > 0) {
            parent.installListBox =
                new List(
                    Resource.getString(ResourceConstants.AMS_DISC_APP_SELECT_INSTALL),
                    Choice.IMPLICIT);

            // Add each suite
            for (int i = 0; i < parent.installList.size(); i++) {
              SuiteDownloadInfo suite = (SuiteDownloadInfo) installList.elementAt(i);
              parent.installListBox.append(suite.label, (Image) null);
            }

            parent.installListBox.addCommand(parent.backCmd);
            parent.installListBox.addCommand(parent.installCmd);
            parent.installListBox.setCommandListener(parent);

            /*
             * We need to prevent "flashing" on fast development
             * platforms.
             */
            while (System.currentTimeMillis() - parent.lastDisplayChange
                < GraphicalInstaller.ALERT_TIMEOUT) ;

            parent.display.setCurrent(parent.installListBox);
            return;
          }

          errorMessage = Resource.getString(ResourceConstants.AMS_DISC_APP_CHECK_URL_MSG);
        } catch (IllegalArgumentException ex) {
          errorMessage = Resource.getString(ResourceConstants.AMS_DISC_APP_URL_FORMAT_MSG);
        } catch (Exception ex) {
          errorMessage = ex.getMessage();
        }
      } catch (Exception ex) {
        errorMessage = Resource.getString(ResourceConstants.AMS_DISC_APP_CONN_FAILED_MSG);
      } finally {
        if (parent.progressForm != null) {
          // end the background thread of progress gauge.
          Gauge progressGauge = (Gauge) parent.progressForm.get(parent.progressGaugeIndex);
          progressGauge.setValue(Gauge.CONTINUOUS_IDLE);
        }

        try {
          conn.close();
          in.close();
        } catch (Exception e) {
          if (Logging.REPORT_LEVEL <= Logging.WARNING) {
            Logging.report(Logging.WARNING, LogChannels.LC_AMS, "close threw an Exception");
          }
        }
      }

      Alert a =
          new Alert(
              Resource.getString(ResourceConstants.ERROR), errorMessage, null, AlertType.ERROR);
      a.setTimeout(Alert.FOREVER);
      parent.display.setCurrent(a, parent.urlTextBox);
    }