kamiiyuID:kamiiyu
33771次访问,排名3349好友0人,关注者0
kamiiyu的文章
原创 16 篇
翻译 0 篇
转载 51 篇
评论 5 篇
kamiiyu的公告
一个菜鸟的Blog,留下一些自己学习的印迹,有什么错误欢迎大家拍砖指正交流~ 谢谢!
最近评论
mohroq:wow gold,
sealrose:谢谢你^^
kamiiyu:呵呵,谢谢卡卡西的意见,其实这段代码我也是在网上找到的,但是忘了标明是转贴。

当初我在刚学swing的时候,看到标准类库里有在在jtable加checkbox等控件的方法,所以就像如果我能不能加一个按钮上去,刚好又在网上找到这段代码所以就贴过来了。

不过很感谢你的批评和指正,有空我会去你那转转的。
卡卡西:this.setText((value == null)? "": ((JButton)value).getText());

我想你如果仔细想想这句代码,我想你自己也会笑。想想这个 this是什么?
MyTableCellRenderer extends JButton
这句说明了一切!
卡卡西:Swing:

Sun优秀科学家和Netscape杰出工程师的作品!

  Swing出现了快10年了,凭借其先进的设计思想,一直未曾落后于哪种语言的界面开发技术,使用和理解Swing的设计思想,对软件开发者大有裨益。

http://www.douban.com/group/15620/
我在豆瓣上开的小组,有兴趣聊聊!
<……
文章分类
    收藏
    相册
    Hello
    emu in blogjava
    Rey的技术博客
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    转载  Servlet中的八大Listener收藏

    新一篇: struts乱码解决 | 旧一篇: [心得]被霏凡封的帖子,小红伞,趋势分析,五大杀毒引擎分

    JSP/Servlet 中的事件处理写过AWT或Swing程序的人一定对桌面程序的事件处理机制印象深刻:通过实现Listener接口的类可以在特定事件(Event)发生时,呼叫特定的方法来对事件进行响应。

    其实我们在编写JSP/Servle程序时,也有类似的事件处理机制,所不同的是在JSP/Servlet中是在web.xml中注册Listener,由Container在特定事件发生时呼叫特定的实现Listener的类。


    1. Servlet中的Listener和Event:

    在JSP 2.0/Servlet 2.4中,共有八个Listener接口,六个Event类别。
    ServletContextListener接口
    [接口方法] contextInitialized()与 contextDestroyed()
    [接收事件] ServletContextEvent
    [触发场景] 在Container加载Web应用程序时(例如启动 Container之后),会呼叫contextInitialized(),而当容器移除Web应用程序时,会呼叫contextDestroyed ()方法。

    ServletContextAttributeListener
    [接口方法] attributeAdded()、 attributeReplaced()、attributeRemoved()
    [接收事件] ServletContextAttributeEvent
    [触发场景] 若有对象加入为application(ServletContext)对象的属性,则会呼叫attributeAdded(),同理在置换属性与移除属性时,会分别呼叫attributeReplaced()、attributeRemoved()。

    HttpSessionListener
    [接口方法] sessionCreated()与sessionDestroyed ()
    [接收事件] HttpSessionEvent
    [触发场景] 在session (HttpSession)对象建立或被消灭时,会分别呼叫这两个方法。

    HttpSessionAttributeListener
    [接口方法] attributeAdded()、 attributeReplaced()、attributeRemoved()
    [接收事件] HttpSessionBindingEvent
    [触发场景] 若有对象加入为session(HttpSession)对象的属性,则会呼叫attributeAdded(),同理在置换属性与移除属性时,会分别呼叫attributeReplaced()、 attributeRemoved()。

    HttpSessionActivationListener
    [接口方法] sessionDidActivate()与 sessionWillPassivate()
    [接收事件] HttpSessionEvent
    [触发场景] Activate与Passivate是用于置换对象的动作,当session对象为了资源利用或负载平衡等原因而必须暂时储存至硬盘或其它储存器时(透 过对象序列化),所作的动作称之为Passivate,而硬盘或储存器上的session对象重新加载JVM时所采的动作称之为Activate,所以容 易理解的,sessionDidActivate()与 sessionWillPassivate()分别于Activeate后与将Passivate前呼叫。

    ServletRequestListener
    [接口方法] requestInitialized()与 requestDestroyed()
    [接收事件] RequestEvent
    [触发场景] 在request(HttpServletRequest)对象建立或被消灭时,会分别呼叫这两个方法。

    ServletRequestAttributeListener
    [接口方法] attributeAdded()、 attributeReplaced()、attributeRemoved()
    [接收事件] HttpSessionBindingEvent
    [触发场景] 若有对象加入为request(HttpServletRequest)对象的属性,则会呼叫attributeAdded(),同理在置换属性与移除属性时,会分别呼叫attributeReplaced()、 attributeRemoved()。

    HttpSessionBindingListener
    [接口方法] valueBound()与valueUnbound()
    [接收事件] HttpSessionBindingEvent
    [触发场景] 实现HttpSessionBindingListener接口的类别,其实例如果被加入至session(HttpSession)对象的属性中,则会 呼叫 valueBound(),如果被从session(HttpSession)对象的属性中移除,则会呼叫valueUnbound(),实现 HttpSessionBindingListener接口的类别不需在web.xml中设定。

    2. 如何注册Servlet中的事件
    实现上面这几个接口的类别,除了HttpSessionBindingListener外,必须在web.xml中向容器注册,容器才会在对应的事件发生时呼叫对应的类别,如:
     < listener > 
     < listener-class > demo.servlet.listener.CustomServletContextListener  
     

    3. Servlet事件的应用实例

    看到这里,你也许会有疑问: 了解这些 listener和event 有什么用呢?我平时开发没有用到这些,一样也能完成任务啊.

    不错,在日常的开发中很少用到这些事件处理的方面,但是在某些情况下使用事件处理机制却可以达到事半功倍的效果,例如下面两个例子:

    4.Java类实例
    ==========
    //侦听启动和关闭
    import javax.servlet.ServletContextListener;
    import javax.servlet.*;

    public class TigerListen implements ServletContextListener {
     public void contextInitialized(ServletContextEvent sce)
     {
      System.out.print("Init") ;
     }
     public void contextDestroyed(ServletContextEvent sce)
     {
      System.out.print("Destroved") ;
     }
    }

    对应的web.xml是
    ============
    <!--l version="1.0" encoding="UTF-8-->
        TigerListen
     
     

    ============

     

    发表于 @ 2007年04月24日 13:54:00|评论(loading...)|编辑

    新一篇: struts乱码解决 | 旧一篇: [心得]被霏凡封的帖子,小红伞,趋势分析,五大杀毒引擎分

    评论:没有评论。

    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © kamiiyu