I need help understanding this code, looking for an explanation on the parts of
ID: 3720624 • Letter: I
Question
I need help understanding this code, looking for an explanation on the parts of it :
Main.java
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.SwingUtilities;
import base.DB;
import base.controller.Controller;
import base.model.CarLot;
import base.view.GUI;
public class Main {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
CarLot model;
try {
model = DB.retrieve();
if (model == null) {
throw new Exception();
}
} catch (Exception exc) {
model = new CarLot();
}
GUI view = new GUI("WidgetViewer");
final CarLot modelToStore = model;
view.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent we) {
try {
DB.store(modelToStore);
} catch (Exception e) {
System.out.println("Problem occurred while storing the model: " + e);
}
}
});
Controller controller = new Controller(model, view);
controller.initView();
controller.initController();
view.setVisible(true);
});
}
}
Explanation / Answer
// Please find the commments inline to the code. Thanks!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.