001package jmri.util; 002 003import java.awt.event.ActionEvent; 004import javax.swing.AbstractAction; 005import javax.swing.JFrame; 006import org.slf4j.Logger; 007import org.slf4j.LoggerFactory; 008 009/** 010 * Swing action that defers class loading until invoked. 011 * <p> 012 * The "Frame" in the name refers to this class being optimized to create a 013 * JFrame when invoked. 014 * <p> 015 * This does not manage the JFrame instance; if you invoke this twice, you get 016 * two JFrame objects. 017 * 018 * @author Bob Jacobsen Copyright (C) 2003 019 */ 020abstract public class AbstractFrameAction extends AbstractAction { 021 022 public AbstractFrameAction(String actionName, String className) { 023 super(actionName); 024 this.className = className; 025 } 026 027 String className; 028 029 @Override 030 public void actionPerformed(ActionEvent e) { 031 try { 032 JFrame f = (JFrame) Class.forName(className).getDeclaredConstructor().newInstance(); 033 f.setVisible(true); 034 } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException 035 | IllegalAccessException | java.lang.reflect.InvocationTargetException ex) { 036 log.error("Error starting JFrame {}", className, ex); 037 } 038 } 039 private final static Logger log = LoggerFactory.getLogger(AbstractFrameAction.class); 040 041}