Java tutorial
/****************************************************************************** * Copyright (c) 2014 Fred Laderoute. * All rights reserved. This program and the accompanying * materials are made available under the terms of the GNU * Public License v3.0 which accompanies this distribution, * and is available at http://www.gnu.org/licenses/gpl.html * * Contributors: * Fred Laderoute - initial API and implementation ******************************************************************************/ package com.password.locker; import java.security.Security; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.password.locker.util.Constants; import com.password.locker.util.ExceptionUtils; import com.password.locker.util.ShutdownHook; /** * Application entry point. * @author Fred Laderoute * */ public final class Main { /** * Logger. */ public static final Logger LOGGER = LoggerFactory.getLogger(Main.class); /** * Thread coordinator. */ public static final ScheduledExecutorService COORDINATOR = Executors.newSingleThreadScheduledExecutor(); /** * Application Constructor. */ private Main() { } /** * Main constructor. * @param args * arguments passed to the program. */ public static void main(final String[] args) { Security.addProvider(new BouncyCastleProvider()); setLookAndFeel(); StateMonitor monitor = new StateMonitor(); Main.COORDINATOR.scheduleAtFixedRate(monitor, Constants.MONITOR_DELAY, Constants.MONITOR_PERIOD, Constants.MONITOR_TIMEUNIT); addHook(); } /** * Attempt to set the look and feel of the application. */ private static void setLookAndFeel() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException e) { ExceptionUtils.fatalError(AppStart.class, e); } catch (InstantiationException e) { ExceptionUtils.fatalError(AppStart.class, e); } catch (IllegalAccessException e) { ExceptionUtils.fatalError(AppStart.class, e); } catch (UnsupportedLookAndFeelException e) { ExceptionUtils.fatalError(AppStart.class, e); } } /** * Shutdown hook. */ private static void addHook() { Runtime.getRuntime().addShutdownHook(new ShutdownHook(Thread.currentThread())); } /** * Start application. */ public static void appStart() { AppStart start = new AppStart(); start.start(); } }