imageFrame.setLocationRelativeTo(null);// Center the frame
imageFrame.setVisible(true);// Make the frame visible
}catch(IOExceptionex){
ex.printStackTrace();
outputTextArea.append("Molecule display failed. The provided molecule name may be incorrect or does not match any records in the PubChem database.\n\n");
}
}
});
@@ -154,6 +158,18 @@ public class GUI extends JFrame {
}
});
// Add window listener to save the database before closing the window
addWindowListener(newWindowAdapter(){
@Override
publicvoidwindowClosing(WindowEvente){
try{
moleculeDb.save("molecule.db");// save the database
}catch(IOExceptionex){
ex.printStackTrace();
}
}
});
// Connect to client or server
connectToServerOrClient();
@@ -161,6 +177,14 @@ public class GUI extends JFrame {
pack();
setLocationRelativeTo(null);
setVisible(true);
// Load database on startup
try{
initDb("molecule.db");
}catch(IOExceptione){
e.printStackTrace();
}
}
/**
@@ -173,25 +197,13 @@ public class GUI extends JFrame {