how_tomcat_workshow_tomcat_works

Page 346

MyShutdownHook shutdownHook = new MyShutdownHook(); Runtime.getRuntime().addShutdownHook(shutdownHook); // create a temp file File file = new File(dir, filename); try { System.out.println("Creating temporary file"); file.createNewFile(); } catch (IOException e) { System.out.println("Failed creating temporary file."); } } private void shutdown() { // delete the temp file File file = new File(dir, filename); if (file.exists()) { System.out.println("Deleting temporary file."); file.delete(); } } void exitButton_actionPerformed(ActionEvent e) { shutdown(); System.exit(0); } public static void main(String[] args) { MySwingAppWithShutdownHook mySwingApp = new MySwingAppWithShutdownHook(); } private class MyShutdownHook extends Thread { public void run() { shutdown(); } } }


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.