Exemplo n.º 1
0
 public void actionPerformed(ActionEvent e) {
   String s = e.getActionCommand();
   if (s.equals("+")) {
     this.fnumber = Float.parseFloat(this.jtf.getText());
     this.jtf.setText("");
     this.temp = 1;
   } else if (s.equals("-")) {
     this.fnumber = Float.parseFloat(this.jtf.getText());
     this.jtf.setText("");
     this.temp = 2;
   } else if (s.equals("*")) {
     this.fnumber = Float.parseFloat(this.jtf.getText());
     this.jtf.setText("");
     this.temp = 3;
   } else if (s.equals("/")) {
     this.fnumber = Float.parseFloat(this.jtf.getText());
     this.jtf.setText("");
     this.temp = 4;
   } else if (s.equals(".")) {
     if (jtf.equals("")) {
       jtf.setText("0.");
     } else {
       jtf.setText(jtf.getText() + ".");
     }
   } else if (s.equals("=")) {
     this.bnumber = Integer.parseInt(this.jtf.getText());
     switch (this.temp) {
       case 1:
         result = fnumber + bnumber;
         this.jtf.setText(String.valueOf(result));
         break;
       case 2:
         result = fnumber - bnumber;
         this.jtf.setText(String.valueOf(result));
         break;
       case 3:
         result = fnumber * bnumber;
         this.jtf.setText(String.valueOf(result));
         break;
       case 4:
         result = fnumber / bnumber;
         this.jtf.setText(String.valueOf(result));
         break;
     }
   } else {
     jtf.setText(jtf.getText() + e.getActionCommand());
   }
 }
Exemplo n.º 2
0
  public void validatePopupAdd(JTextField field1, JTextField field2, JButton button) {
    if (field2.equals("") && !field1.getText().isEmpty()) {
      JOptionPane.showMessageDialog(button, "Please Fill All the details!");
    }
    if (field2.getText().isEmpty() && field1.getText().isEmpty()) {
      JOptionPane.showMessageDialog(button, "Please Fill All the details!");

    } else if (!field1.getText().matches("[0-9]+")) {
      JOptionPane.showMessageDialog(button, "Please enter a price!");
    }

    //		}else if (field1.getText().matches("[0-9]+") && field2.getText().isEmpty()){
    //		JOptionPane.showMessageDialog(button, "Please Fill All the details!");
    // }

  }
Exemplo n.º 3
0
  private void textFieldClicked(java.awt.event.MouseEvent evt) { // GEN-FIRST:event_textFieldClicked
    if (evt.getSource() instanceof javax.swing.JTextField) {
      javax.swing.JTextField textField = (javax.swing.JTextField) evt.getSource();

      JFileChooser fc = new JFileChooser();
      int result;
      if (textField.equals(this.modelAuiModelTextField)) {
        result = fc.showSaveDialog(this);
      } else {
        result = fc.showOpenDialog(this);
      }

      if (result == JFileChooser.APPROVE_OPTION) {
        textField.setText(fc.getSelectedFile().getAbsolutePath());
      }
    }
  } // GEN-LAST:event_textFieldClicked
Exemplo n.º 4
0
  public void actionPerformed(ActionEvent event) {

    // if clear button is pressed, clear all fields
    if (event.getSource() == clear_button) {
      // erase all fields

      taskname_field.setText("");
      taskdesc_field.setText("");

      priority_checkbox.setSelected(false);
      numberofdays_field.setText("");
      // isallocatedcheckbox.setSelected(false);
      duedate_field.setText("");
    }

    // if submit button is pressed, save all data onto database
    if (event.getSource() == submit_button) {
      try {
        {
          Calendar calendar = Calendar.getInstance();
          calendar.setTime(new Date()); // set to current date
          calendar.add(
              Calendar.DAY_OF_MONTH,
              Integer.parseInt(this.numberofdays_field.getText())
                  - 1); // add days required... then:
          // ^ subtract one day, because if task is created today and allocated tomorrow for one
          // day,
          // then it should be done by end of day tomorrow
          Date date = calendar.getTime(); // (see next *1) use this date to be the earliest
          // because of expected task duration

          /*This is a constraint
           * the date and the length of days that user expected to take
           * if not feasible then the program will say so
           * */
          // method compares the current date and the date that was entered by the user
          if (this.task_idfield.getText().length() != 7 // check chars
              || this.taskname_field.getText().length() > 50 // check chars
              || this.taskdesc_field.getText().length() > 50
              || ((Date) this.duedate_field.getValue()).compareTo(date)
                  < 0 // check that the date is possible (see last *1)
              || this.numberofdays_field.getText().length() > 2
              || this.numberofdays_field.getText().length() == 0 // check number of digits
              || Integer.parseInt(this.numberofdays_field.getText())
                  < 1) // check number of days required for task
          {
            JOptionPane.showMessageDialog(
                this,
                "Task ID has to be 7 chars; "
                    + "\n"
                    + "Description <= 50 chars; "
                    + "\n"
                    + "Because the expected duration of the task is "
                    + Integer.parseInt(this.numberofdays_field.getText())
                    + " days, the due date cannot be earlier than: "
                    + new StringBuffer(new SimpleDateFormat("dd/MM/yyyy").format(date)).toString()
                    + "; "
                    + "\n"
                    + "Task duration must be 2 digit number maximum and must be an integer greater than 0");
          } else

          // check if taskid_field is equals to any of the fields on the database

          if (task_idfield.equals("")) {
            JOptionPane.showMessageDialog(
                this, "Please insert an identification number for a task");

          } else // add constraint and tell customer to enter 7 values
          if (taskname_field.equals("")) {
            JOptionPane.showMessageDialog(this, "Please insert a name to identity the task");

          } else {

            // get all inputs from user inputs and store in variables
            taskid_input = task_idfield.getText();
            taskname_input = taskname_field.getText();
            taskdesc_input = taskdesc_field.getText();

            if (priority_checkbox.isSelected()) {
              priority_input = 1;
            } else {
              priority_input = 0;
            }

            // create and store date from user input
            date = (Date) duedate_field.getValue();

            // store number of days input from user
            numberofdays_input = Integer.parseInt(numberofdays_field.getText());

            // 	String[] column_names = { "Task ID", "Task Name", "Task Description", "Task
            // Priority", "Due Date", "Number of Days", "Is Allocated" , "Unallocateable" };

            task = new Object[8];
            task[0] = taskid_input;
            task[1] = taskname_input;
            task[2] = taskdesc_input;
            task[3] = priority_input;
            task[4] = date;
            task[5] = numberofdays_input;
            task[6] = 0;
            task[7] = 0;

            try {
              //
              SqlConnection.connect();

              SqlConnection.ps =
                  SqlConnection.connection.prepareStatement(
                      "INSERT  INTO TASK VALUES (?,?,?,?,?,?,?,?)");

              SqlConnection.ps.setString(1, taskid_input);
              SqlConnection.ps.setString(2, taskname_input);
              SqlConnection.ps.setString(3, taskdesc_input);
              SqlConnection.ps.setInt(4, priority_input);
              SqlConnection.ps.setDate(5, new java.sql.Date(date.getTime()));
              SqlConnection.ps.setInt(6, numberofdays_input);
              SqlConnection.ps.setInt(7, 0);
              SqlConnection.ps.setInt(8, 0);

              SqlConnection.ps.executeUpdate();

              // now enter skills into TASK SKILL database
              for (int i = 0; i < skill_list.size(); i++) {
                if (skill_list.get(i).isSelected()) {
                  String skillid = skill_list.get(i).getText();
                  SqlConnection.statement.executeUpdate(
                      "INSERT INTO TASKSKILL VALUES ('" + taskid_input + "', '" + skillid + "')");
                }
              }

              SqlConnection.ps.close();
            } catch (SQLException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
            // SqlConnection.ps.close();
            SqlConnection.closeConnection();
            this.setVisible(false);
          }
        }

      } catch (Exception exc) {
        JOptionPane.showMessageDialog(
            this,
            "Check your inputs:"
                + "\n"
                + "Priority has to be a 1-digit number;"
                + "\n"
                + "Date has to be in the format dd/MM/yyyy;"
                + "\n"
                + "Task length has to be 2-digit number");
        System.out.println(exc);
      }
    }
    // display dialog box asking task manager if they want to quit,
    // if task manager does not want to quit, go back to adding more tasks
    // if customer quits, close the dialog box and the frame

    // now close the window after saving
  }
Exemplo n.º 5
0
 public void actionPerformed(ActionEvent e) {
   // TODO Auto-generated method stub
   if (e.getSource() == btnNuevo) {
     limpiar();
     setCodigo(inc.GeneraCodigo());
   }
   if (e.getSource() == btnLimpiar) {
     limpiar();
   }
   if (e.getSource() == btnBuscar) {
     int codigo = Integer.parseInt(JOptionPane.showInputDialog("Ingrese el número de código"));
     if (codigo != 0) {
       buscar(codigo);
     } else {
       return;
     }
   }
   if (e.getSource() == btnRegistrar) {
     if (getCodUsu() == -1
         || getCodEsp() == -1
         || getCodTipo() == -1
         || getDescripcion().equals("")
         || getObservacion().equals("")
         || txtTiempoEstimado.equals("")
         || txtTiempoReal.equals("")
         || getFecRegistro().equals("")
         || getFecInicio().equals("  -  -    ")
         || getFecFinal().equals("  -  -    ")
         || getEstado() == -1) {
       JOptionPane.showMessageDialog(null, "Faltan Ingresar Datos ", "System Error", 0);
       return;
     }
     registrar();
   }
   if (e.getSource() == btnModificar) {
     if (getCodUsu() == -1
         || getCodEsp() == -1
         || getCodTipo() == -1
         || getDescripcion().equals("")
         || getObservacion().equals("")
         || txtTiempoEstimado.equals("")
         || txtTiempoReal.equals("")
         || getFecRegistro().equals("")
         || getFecInicio().equals("  -  -    ")
         || getFecFinal().equals("  -  -    ")
         || getEstado() == -1) {
       JOptionPane.showMessageDialog(null, "Faltan Ingresar Datos ", "System Error", 0);
       return;
     }
     Incidencia x = inc.buscar(getCodigo());
     if (x == null) {
       JOptionPane.showConfirmDialog(null, "El Codigo no existe...!!!");
     } else {
       x.setCodigo(getCodigo());
       x.setCodUsu(getCodUsu());
       x.setCodEsp(getCodEsp());
       x.setCodTipInc(getCodTipo());
       x.setDescripcion(getDescripcion());
       x.setComentarios(getObservacion());
       x.setTiempoEst(getTiempoEstimado());
       x.setTiempoReal(getTiempoReal());
       x.setFecRegistro(getFecRegistro());
       x.setFecInicio(getFecInicio());
       x.setFecFin(getFecFinal());
       x.setEstado(getEstado());
     }
     inc.grabar();
   }
   if (e.getSource() == btnListado) {
     mostrarIncidencias();
   }
   if (e.getSource() == btnImprimir) {
     JOptionPane.showConfirmDialog(null, getIncidencia(), "Sistema de Gestion de Incidencias", 0);
   }
 }