[Java] 看图程序 →→→→→进入此内容的聊天室

来自 , 2020-02-22, 写在 Java, 查看 140 次.
URL http://www.code666.cn/view/c7af0926
  1. package org.crazyit.viewer;
  2.  
  3. import java.awt.event.ActionEvent;
  4. import java.util.HashMap;
  5. import java.util.Map;
  6.  
  7. import javax.swing.AbstractAction;
  8. import javax.swing.ImageIcon;
  9.  
  10. import org.crazyit.viewer.action.Action;
  11.  
  12. /**
  13.  * 工具栏的Action类
  14.  *
  15.  * @author yangenxiong yangenxiong2009@gmail.com
  16.  * @author Kelvin Mak kelvin.mak125@gmail.com
  17.  * @version  1.0
  18.  * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
  19.  * <br>Copyright (C), 2009-2010, yangenxiong
  20.  * <br>This program is protected by copyright laws.
  21.  */
  22. public class ViewerAction extends AbstractAction {
  23.         private String actionName = "";
  24.         private ViewerFrame frame = null;
  25.        
  26.         //这个工具栏的AbstractAction所对应的org.crazyit.viewer.action包的某个Action实全
  27.         private Action action = null;
  28.  
  29.         /**
  30.          * 构造器
  31.          *
  32.          */
  33.         public ViewerAction() {
  34.                 // 调用父构造器
  35.                 super();
  36.         }
  37.  
  38.         /**
  39.          * 构造器
  40.          *
  41.          * @param icon
  42.          *            ImageIcon 图标
  43.          * @param name
  44.          *            String
  45.          */
  46.         public ViewerAction(ImageIcon icon, String actionName, ViewerFrame frame) {
  47.                 // 调用父构造器
  48.                 super("", icon);
  49.                 this.actionName = actionName;
  50.                 this.frame = frame;
  51.         }
  52.  
  53.         /**
  54.          * 重写void actionPerformed( ActionEvent e )方法
  55.          *
  56.          * @param e
  57.          *            ActionEvent
  58.          */
  59.         public void actionPerformed(ActionEvent e) {
  60.                 ViewerService service = ViewerService.getInstance();
  61.                 Action action = getAction(this.actionName);
  62.                 //调用Action的execute方法
  63.                 action.execute(service, frame);
  64.         }
  65.        
  66.         /**
  67.          * 通过actionName得到该类的实例
  68.          * @param actionName
  69.          * @return
  70.          */
  71.         private Action getAction(String actionName) {
  72.                 try {
  73.                         if (this.action == null) {
  74.                                 //创建Action实例
  75.                                 Action action = (Action)Class.forName(actionName).newInstance();
  76.                                 this.action = action;
  77.                         }
  78.                         return this.action;
  79.                 } catch (Exception e) {
  80.                         return null;
  81.                 }
  82.         }
  83.        
  84.        
  85. }

回复 "看图程序"

这儿你可以回复上面这条便签

captcha