From b37205abec26cdcc1ed71babd8c34d0b8fa6d99a Mon Sep 17 00:00:00 2001 From: Abdoalrahmankhedr Date: Sun, 16 Nov 2025 11:05:44 +0200 Subject: [PATCH] Solve the enrollment problem with empty course I have added that the course is empty and doesn`t has any lessons show message to the student to inform him that the course is empty and he will not be able to enroll this course now --- src/pages/CourseLessons.java | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/pages/CourseLessons.java b/src/pages/CourseLessons.java index 6818d95..6e92bf9 100644 --- a/src/pages/CourseLessons.java +++ b/src/pages/CourseLessons.java @@ -227,16 +227,23 @@ public static void start(Course course, int ID){ JScrollPane scrollPane = new JScrollPane(lessonsPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setBorder(null); frame.EnrollBtn.addActionListener(e -> { - int response=showMessage("Do You Want to Enroll the Course with name:"+course.getTitle()); - if(response == JOptionPane.YES_OPTION){ - StudentService.enroll(ID,course.getId()); - StudentLessons.start(course,ID); - frame.dispose(); - StudentDashBoard.start(ID); - MainWindow.goToFrame("StudentDashBoard"); + if(course.getLessons().size()==0){ + showMessage("This course is Empty you can`t enroll it now!!"); + frame.dispose(); + StudentDashBoard.start(ID); + MainWindow.goToFrame("StudentDashBoard"); + } + else{ + int response=showMessage("Do You Want to Enroll the Course with name:"+course.getTitle()); + if(response == JOptionPane.YES_OPTION){ + StudentService.enroll(ID,course.getId()); + StudentLessons.start(course,ID); + frame.dispose(); + StudentDashBoard.start(ID); + MainWindow.goToFrame("StudentDashBoard"); + } } }); - frame.jPanel4.removeAll(); frame.jPanel4.setLayout(new BorderLayout()); frame.jPanel4.add(scrollPane, BorderLayout.CENTER);