I'm using two JOptionPanes to ask the user for input but they pop-up thrice i think it has to do with my while/if loops my ExcelHandling class but I honestly don't know what's wrong with it.
Tried removing parts of the code in multiple classes to see if i could track where the multiple pop-up's come from but to no avail. It either runs thrice or not at all.
I've added the section of the code which i think is the culprit but if u think it might be in my main class or my ui class i can add them as well.
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
*
* @author Geert van den Berg
*/
public class ExcelHandling {
Window useNew = new Window();
private static final String FILE_NAME = "C:\\Users\\Holiday Planning\\HolidayPlanning.xlsx";
private String userin = useNew.userinput1;
private String userin1 = useNew.userinput2;
final DataFormatter df = new DataFormatter();
public String cellLocationDate = "";
public String cellLocationUserName = "";
ExcelHandling() throws IOException, FileNotFoundException {
try {
FileInputStream excelFile = new FileInputStream(new File(FILE_NAME));
Workbook workbook = new XSSFWorkbook(excelFile);
Sheet datatypeSheet = workbook.getSheetAt(0);
Iterator<Row> iterator = datatypeSheet.iterator();
while (iterator.hasNext()) {
Row currentRow = iterator.next();
Iterator<Cell> cellIterator = currentRow.iterator();
while (cellIterator.hasNext()) {
Cell currentCell = cellIterator.next();
if (currentCell.getCellType() == CellType.STRING) {
System.out.print(currentCell.getStringCellValue() + "--");
} else if (currentCell.getCellType() == CellType.NUMERIC) {
System.out.print(currentCell.getNumericCellValue() + "--");
}
String formattedCellValue = df.formatCellValue(currentCell);
if (formattedCellValue.equals(userin)) {
System.out.println("a match is found");
cellLocationUserName = currentCell.getAddress().formatAsString();
System.out.println(cellLocationUserName);
}
if (formattedCellValue.equals(userin1)) {
System.out.println("A Date is found");
cellLocationDate = currentCell.getAddress().formatAsString();
System.out.println(cellLocationDate);
}
}
System.out.println();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
I think this section of my program is running thrice for some reason which causes my seperate UI class to popup the JOptionPane thrice. (also the result of the final System.out.println(); is also displayed thrice but that seems to be the same problem. Any advice is welcome and I'm trying to make my code more towards the standard. Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire