public void excluir(Oriundo oriundo) throws SQLException {
   Connection con =
       DriverManager.getConnection(
           new conexao().url,
           new conexao().config.getString("usuario"),
           new conexao().config.getString("senha"));
   PreparedStatement ps = null;
   String sqlExcluir = "DELETE FROM oriundo WHERE codigo=?";
   try {
     ps = con.prepareStatement(sqlExcluir);
     ps.setInt(1, oriundo.getCodigo());
     ps.executeUpdate();
     JOptionPane.showMessageDialog(
         null, "Ecluido Com Sucesso: ", "Mensagem do Sistema - Excluir", 1);
   } catch (NumberFormatException e) {
     JOptionPane.showMessageDialog(
         null, "NumberFormaterExeption Erro: " + e.getMessage(), "ClasseDAO Func.Excluir", 0);
     e.printStackTrace();
   } catch (NullPointerException e) {
     JOptionPane.showMessageDialog(
         null, "NullPointerException Erro: " + e.getMessage(), "ClasseDAO Func. Excluir", 0);
     e.printStackTrace();
   } catch (SQLException e) {
     JOptionPane.showMessageDialog(
         null, "SQLException Erro: " + e.getMessage(), "ClasseDAO Func. Excluir", 0);
     e.printStackTrace();
   } catch (Exception e) {
     JOptionPane.showMessageDialog(
         null, "Exception Erro: " + e.getMessage(), "ClasseDAO Func. Excluir", 0);
     e.printStackTrace();
   } finally {
     ps.close();
     con.close();
   }
 }
Beispiel #2
0
 /**
  * Return a integer parsed from the value associated with the given key, or "def" in key wasn't
  * found.
  */
 public static int parseProperty(Properties preferences, String key, int def) {
   String val = preferences.getProperty(key);
   if (val == null) return def;
   try {
     return Integer.parseInt(val);
   } catch (NumberFormatException nfe) {
     nfe.printStackTrace();
     return def;
   }
 }
Beispiel #3
0
 /** @return the pot */
 public static int getPort() {
   int port = 0;
   try {
     port = Integer.parseInt(pot.getText());
   } catch (NumberFormatException f) {
     f.printStackTrace();
     new WhatIDo("Entrer un port valide", f.toString());
   }
   return port;
 }
 /**
  * Returns the editted value.
  *
  * @return the editted value.
  * @throws TagFormatException if the tag value cannot be retrieved with the expected type.
  */
 public TagValue getTagValue() throws TagFormatException {
   try {
     long numer = Long.parseLong(m_numer.getText());
     long denom = Long.parseLong(m_denom.getText());
     Rational rational = new Rational(numer, denom);
     return new TagValue(m_value.getTag(), rational);
   } catch (NumberFormatException e) {
     e.printStackTrace();
     throw new TagFormatException(
         m_numer.getText() + "/" + m_denom.getText() + " is not a valid rational");
   }
 }
    public void actionPerformed(ActionEvent e) {
      JTextField fieldEdited = (JTextField) e.getSource();
      try {
        systemOrder = Integer.parseInt(fieldEdited.getText());
      } catch (NumberFormatException nfex) {
        System.out.println("Number format exception in getting system order");
        nfex.printStackTrace();
      }

      String updatedStatusText = prepareStatusText();
      statusAreaTop.setText(updatedStatusText);
    }
 public List<Oriundo> listar() throws SQLException {
   List<Oriundo> resultado = new ArrayList<Oriundo>();
   conexao propCon = new conexao();
   Connection con =
       DriverManager.getConnection(
           new conexao().url,
           propCon.config.getString("usuario"),
           propCon.config.getString("senha"));
   PreparedStatement ps = null;
   ResultSet rs = null;
   String sqlListar = "SELECT * FROM oriundo Order by codigo DESC";
   Oriundo oriundo;
   try {
     ps = con.prepareStatement(sqlListar);
     rs = ps.executeQuery();
     // if(rs==null){
     // return null;
     // }
     while (rs.next()) {
       oriundo = new Oriundo();
       oriundo.setCodigo(rs.getInt("codigo"));
       oriundo.setDescricao(rs.getString("descricao"));
       oriundo.setData_cadastro(rs.getDate("data_cadastro"));
       oriundo.setDia_fechamento(rs.getInt("dia_fechamento"));
       oriundo.setDia_pag(rs.getInt("dia_pag"));
       resultado.add(oriundo);
     }
   } catch (NumberFormatException e) {
     JOptionPane.showMessageDialog(
         null, "NumberFormaterExeption Erro: " + e.getMessage(), "ClasseDAO Func.Localizar", 0);
     e.printStackTrace();
   } catch (NullPointerException e) {
     JOptionPane.showMessageDialog(
         null, "NullPointerException Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } catch (SQLException e) {
     JOptionPane.showMessageDialog(
         null, "SQLException Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } catch (Exception e) {
     JOptionPane.showMessageDialog(
         null, "Exception Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } finally {
     ps.close();
     con.close();
   }
   return resultado;
 }
Beispiel #7
0
    @Override
    public void actionPerformed(ActionEvent e) {
      switch (e.getActionCommand()) {
        case "Cancel":
          screen.show("menu");
          break;

        case "Start game":
          Game startGame = null;
          // 1. if tjekker værdien af hvad der er valgt i comboBoxen og sammenligner med de spil som
          // for-loopet kører igennem
          // 2. if gør så hosten ikke kan joine sit eget spil
          for (Game g : games) {
            if (g.getName().equals(screen.getFindGamePanel().getSelectedGame())) {
              if (g.getHost().getId() != currentUser.getId()) startGame = g;
            }
          }
          if (startGame != null) {

            Gamer opponent = new Gamer();
            opponent.setId(currentUser.getId());
            opponent.setControls(screen.getFindGamePanel().getDirectionsTextfield());
            startGame.setOpponent(opponent);
            String joinGamemessage = api.joinGame(startGame);
            String startGamemessage = api.startGame(startGame);
            System.out.println(startGamemessage);
            String winnerName = "";

            for (User u : users) {

              try {

                if (u.getId() == Integer.parseInt(startGamemessage)) {
                  winnerName = u.getUsername();
                }
              } catch (NumberFormatException e1) {
                e1.printStackTrace();
              }
            }

            JOptionPane.showMessageDialog(
                screen, joinGamemessage + ". The winner was:" + winnerName);
          } else {
            JOptionPane.showMessageDialog(screen, "You can't join a game where you're the host");
          }
          break;
      }
    }
 public Oriundo localizar(Integer codigo) throws SQLException {
   Connection con =
       DriverManager.getConnection(
           new conexao().url,
           new conexao().config.getString("usuario"),
           new conexao().config.getString("senha"));
   PreparedStatement ps = null;
   ResultSet rs = null;
   String sqlLocalizar = "SELECT * FROM oriundo WHERE codigo=?";
   Oriundo oriundo = new Oriundo();
   try {
     ps = con.prepareStatement(sqlLocalizar);
     ps.setInt(1, codigo);
     rs = ps.executeQuery();
     // if(!rs.next()){
     // return null;
     // }
     oriundo.setCodigo(rs.getInt("codigo"));
     oriundo.setDescricao(rs.getString("descricao"));
     oriundo.setData_cadastro(rs.getDate("data_cadastro"));
     oriundo.setDia_fechamento(rs.getInt("dia_fechamento"));
     oriundo.setDia_pag(rs.getInt("dia_pag"));
     return oriundo;
   } catch (NumberFormatException e) {
     JOptionPane.showMessageDialog(
         null, "NumberFormaterExeption Erro: " + e.getMessage(), "ClasseDAO Func.Localizar", 0);
     e.printStackTrace();
   } catch (NullPointerException e) {
     JOptionPane.showMessageDialog(
         null, "NullPointerException Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } catch (SQLException e) {
     JOptionPane.showMessageDialog(
         null, "SQLException Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } catch (Exception e) {
     JOptionPane.showMessageDialog(
         null, "Exception Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } finally {
     ps.close();
     con.close();
   }
   return oriundo;
 }
  /** Utility method that will load mortgage data from a file. */
  private void loadMortgages() {
    // create a list of mortgages so we can dynamically add as many as our
    // data file allows. the first entry is always our default
    // "user entered" value so the combo box works consistently...
    final LinkedList mortgages = new LinkedList();
    mortgages.add(LABEL_USER_ENTERED_CHOICE);

    try {
      final InputStream resource =
          getClass().getClassLoader().getResourceAsStream(FILENAME_MORTGAGE_DATA);
      if (resource == null) {
        throw new IOException(FILENAME_MORTGAGE_DATA + " not found");
      }
      final BufferedReader reader = new BufferedReader(new InputStreamReader(resource));

      String line;
      while ((line = reader.readLine()) != null) {
        // split the line of data into tokens separated by commas; if
        // there are two tokens found, we assume we have a valid line
        // of data that can be parsed into rate and term values
        final String[] values = line.split(",");
        if (values.length == 2) {
          final double rate = Double.parseDouble(values[0].trim());
          final int term = Integer.parseInt(values[1].trim());

          // add a new set of mortgage terms to the list; the term
          // must be divided by 12 to convert to the number of years
          mortgages.add(new Mortgage(rate, term / 12));
        }
      }
    } catch (IOException ex) {
      JOptionPane.showMessageDialog(
          getRootPane(), ERR_DATA_FILE_IOERR, ERR_DATA_FILE_ERROR, JOptionPane.ERROR_MESSAGE);
      ex.printStackTrace(System.err);
    } catch (NumberFormatException ex) {
      JOptionPane.showMessageDialog(
          getRootPane(), ERR_DATA_FILE_CORRUPT, ERR_DATA_FILE_ERROR, JOptionPane.ERROR_MESSAGE);
      ex.printStackTrace(System.err);
    }

    fieldMortgageChoices.setModel(new DefaultComboBoxModel(mortgages.toArray()));
  }
Beispiel #10
0
 /**
  * @return a double parsed from the value associated with the given key in the given Properties.
  *     returns "def" in key wasn't found, or if a parsing error occured. If "value" contains a "%"
  *     sign, we use a <code>NumberFormat.getPercentInstance</code> to convert it to a double.
  */
 public static double parseProperty(Properties preferences, String key, double def) {
   NumberFormat formatPercent = NumberFormat.getPercentInstance(Locale.US); // for zoom factor
   String val = preferences.getProperty(key);
   if (val == null) return def;
   if (val.indexOf("%") == -1) { // not in percent format !
     try {
       return Double.parseDouble(val);
     } catch (NumberFormatException nfe) {
       nfe.printStackTrace();
       return def;
     }
   }
   // else it's a percent format -> parse it
   try {
     Number n = formatPercent.parse(val);
     return n.doubleValue();
   } catch (ParseException ex) {
     ex.printStackTrace();
     return def;
   }
 }
 public void atualizar(Oriundo oriundo) throws SQLException {
   Connection con =
       DriverManager.getConnection(
           new conexao().url,
           new conexao().config.getString("usuario"),
           new conexao().config.getString("senha"));
   PreparedStatement ps = null;
   String sqlAtualizar =
       "UPDATE oriundo SET descricao=?, data_cadastro=?, dia_fechamento=?, dia_pag=? WHERE codigo=?";
   try {
     ps = con.prepareStatement(sqlAtualizar);
     ps.setString(1, oriundo.getDescricao());
     ps.setDate(2, oriundo.getData_cadastro());
     ps.setInt(3, oriundo.getDia_fechamento());
     ps.setInt(4, oriundo.getDia_pag());
     ps.setInt(5, oriundo.getCodigo());
     ps.executeUpdate();
     JOptionPane.showMessageDialog(
         null, "Atualizado Com Sucesso: ", "Mensagem do Sistema - Atualizar", 1);
   } catch (NumberFormatException e) {
     JOptionPane.showMessageDialog(
         null, "NumberFormaterExeption Erro: " + e.getMessage(), "ClasseDAO Func.Atualizar", 0);
     e.printStackTrace();
   } catch (NullPointerException e) {
     JOptionPane.showMessageDialog(
         null, "NullPointerException Erro: " + e.getMessage(), "ClasseDAO Func. Atualizar", 0);
     e.printStackTrace();
   } catch (SQLException e) {
     JOptionPane.showMessageDialog(
         null, "SQLException Erro: " + e.getMessage(), "ClasseDAO Func. Atualizar", 0);
     e.printStackTrace();
   } catch (Exception e) {
     JOptionPane.showMessageDialog(
         null, "Exception Erro: " + e.getMessage(), "ClasseDAO Func. Atualizar", 0);
     e.printStackTrace();
   } finally {
     ps.close();
     con.close();
   }
 }
 public void salvar(Oriundo oriundo) throws SQLException {
   Connection con =
       DriverManager.getConnection(
           new conexao().url,
           new conexao().config.getString("usuario"),
           new conexao().config.getString("senha"));
   PreparedStatement ps = null;
   String sqlSalvar =
       "INSERT INTO oriundo (descricao, data_cadastro, dia_fechamento, dia_pag ) VALUES (?, ?, ?, ?)";
   try {
     ps = con.prepareStatement(sqlSalvar);
     ps.setString(1, oriundo.getDescricao());
     ps.setDate(2, oriundo.getData_cadastro());
     ps.setInt(3, oriundo.getDia_fechamento());
     ps.setInt(4, oriundo.getDia_pag());
     ps.executeUpdate();
     // JOptionPane.showMessageDialog(null, "Inserido Com Sucesso: ", "Mensagem do Sistema -
     // Salvar", 1);
   } catch (NumberFormatException e) {
     JOptionPane.showMessageDialog(
         null, "NumberFormaterExeption Erro: " + e.getMessage(), "ClasseDAO Func.Salvar", 0);
     e.printStackTrace();
   } catch (NullPointerException e) {
     JOptionPane.showMessageDialog(
         null, "NullPointerException Erro: " + e.getMessage(), "ClasseDAO Func. Salvar", 0);
     e.printStackTrace();
   } catch (SQLException e) {
     JOptionPane.showMessageDialog(
         null, "SQLException Erro: " + e.getMessage(), "ClasseDAO Func. Salvar", 0);
     e.printStackTrace();
   } catch (Exception e) {
     JOptionPane.showMessageDialog(
         null, "Exception Erro: " + e.getMessage(), "ClasseDAO Func. Salvar", 0);
     e.printStackTrace();
   } finally {
     ps.close();
     con.close();
   }
 }
Beispiel #13
0
 public void actionPerformed(ActionEvent e) {
   Commands c = Commands.valueOf(e.getActionCommand());
   switch (c) {
     case KOPFRADIUS_CHANGE:
       jtf = (JTextField) e.getSource();
       text = jtf.getText();
       if (text.isEmpty()) {
         model.setSize(model.getRadius() * 2);
       }
       try {
         number = Integer.parseInt(text);
       } catch (NumberFormatException ex) {
         ex.printStackTrace();
         number = 0;
         break;
       }
       if (number < 150) {
         model.setSize(150 * 2);
       } else if (number > 2000) {
         model.setSize(2000 * 2);
       } else {
         model.setSize(number * 2);
       }
       eyeSize = model.getEyeRad();
       break;
     case AUGENROLLEN_RECHTS:
       rollright = true;
       model.setRoll(true);
       model.rotateEye(model.getEyeAngel() + 10);
       break;
     case AUGENROLLEN_LINKS:
       rollright = false;
       model.setRoll(false);
       model.rotateEye(model.getEyeAngel() + 10);
       break;
     case SMILE_CHANGE:
       model.changeSmile();
       break;
     case HAPPY:
       model.setSmile(true);
       model.setEyeRad(eyeSize + 15);
       break;
     case SAD:
       model.setSmile(false);
       model.setEyeRad(eyeSize - 15);
       break;
     case PLUS:
       if (model.getRadius() + 10 > 2000) {
         model.setSize(2000 * 2);
       } else {
         model.setSize((model.getRadius() + 10) * 2);
       }
       eyeSize = model.getEyeRad();
       break;
     case MINUS:
       if (model.getRadius() - 10 < 150) {
         model.setSize(150 * 2);
       } else {
         model.setSize((model.getRadius() - 10) * 2);
       }
       eyeSize = model.getEyeRad();
       break;
   }
 }