I'm using a NetBeans as my IDE for Java. I have class called NewSchoolYearDialog extended by JDialog:
The purpose of that Save button in the image above is to insert a school year into a database.
Now I want to reuse that design to create another JDialog to edit the school year by just creating an object of a class NewSchoolYearDialog, set the title to "Edit School Year", and change the Save button implementation to update the school year.
Should I create another class extended by JDialog and just copy the design, or there is another way to do it?

As a rule of clean code, it is not clean to copy your code, and based on your issue, the difference between insert and update is just having id or not. you can check id exists or not and then call update or insert.