@Override public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == annuler) { this.setVisible(false); } if (source == validate) { // ***************here we test if the field is filled or not************ if (tot_pop.getText().equals("")) { JOptionPane.showMessageDialog(errorMsg, "Fill the initial population"); } else { total_popInt = Integer.parseInt(tot_pop.getText()); // Animal a=new Animal(0,typef.getText(),total); int index = typef.getSelectedIndex(); String typeAnim = (typef.getItemAt(index)).toString(); // ****************here we test if what we insert exist with the function above******** if (testingInit("cow")) { write = new fileWriting("init_pop", typeAnim + " " + total_popInt); anima = new AnimalType(total_popInt, typeAnim); this.setVisible(false); // JOptionPane.showMessageDialog(null, "The animal type is created successfully"); } else { JOptionPane.showMessageDialog(errorMsg, "Information on this date already given"); } switch (typeAnim) { case "Cow": AppFrame.totalPopulationCOW = AppFrame.totalPopulationCOW + total_popInt; initialPopCOW = total_popInt; break; case "Deer": AppFrame.totalPopulationDEER = AppFrame.totalPopulationDEER + total_popInt; initialPopDEER = total_popInt; break; case "Horse": AppFrame.totalPopulationHORSE = AppFrame.totalPopulationHORSE + total_popInt; initialPopHORSE = total_popInt; break; default: System.out.println("Switch in Initialize is not working"); break; } Main.totalPopulation = Main.totalPopulation + total_popInt; new AnimalDetails( "2009", "01", CreateAnimal.animalTypeToEnum(typeAnim), total_popInt, 0, "Winter"); new CreateAnimal(CreateAnimal.animalTypeToEnum(typeAnim), total_popInt); } } }