private int checkInputForTextField(JTextField toTest, int maxNumber){
        if(!toTest.getText().equals("")){
            int result = 0;
        
            String text = toTest.getText();
            boolean takeAwayLast = false;
            if(text.length()> 2) text = text.substring(0, 2);
            
            try{
                result = Integer.parseInt(text);
                if(result > maxNumber) takeAwayLast = true;
            }catch (NumberFormatException e){
                takeAwayLast = true;
            }
            
            if(takeAwayLast){
                text = text.substring(0, text.length()-1);
            }
            toTest.setText(text);
            return result;
        }else throw new IllegalStateException("The field is empty");
    }