<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    學海拾遺

    生活、技術、思想無處不在學習
    posts - 52, comments - 23, trackbacks - 0, articles - 3
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    JAVA Applet生命周期

    Posted on 2007-03-17 10:48 tanzek 閱讀(3209) 評論(0)  編輯  收藏

    還是在看Java Tutorial,到了"Applets"。
    下面就列出一些看到的重點吧。

    An?applet?is?a?special?kind?of?Java?program?that?a?browser?enabled?with?Java?technology?can?download?from?the?internet?and?run.?An?applet?is?typically?embedded?inside?a?web - page?and?runs?in?the?context?of?the?browser.?An?applet?must?be?a?subclass?of?the?java.applet.Applet? class ,?which?provides?the?standard? interface ?between?the?applet?and?the?browser?environment.
    applet是一種特殊的JAVA程序,允許帶有Java技術的瀏覽器能夠從Internet下載它并運行。applet是典型的嵌入到網頁里面并在瀏覽器上下文中運行的。applet必須是java.applet.Applet類的子類,java.applet.Applet提供applet和瀏覽器環境之間的接口標準。

    Swing?provides?a?special?subclass?of?Applet,?called?javax.swing.JApplet,?which?should?be?used?
    for ?all?applets?that?use?Swing?components?to?construct?their?GUIs.
    Swing提供一個特殊的applet子類,叫做javax.swing.JApplet,當所有的applet要用到Swing部件來構造他們的GUI時,那么它就需要用到它。

    By?calling?certain?methods,?a?browser?manages?an?applet?life?cycle,?
    i f
    ?an?applet?is?loaded?in?a?web?page.?
    如果applet已經加載到一個網頁中,那么通過調用applet的某一方法,瀏覽器可以控制applet的生命周期。
    上面講了applet的一些知識,接下來的就是applet的生命周期的講解了:
    方法地地Life?Cycle?of?an?Applet:?Basically,?there?are?four?methods?in?the?Applet?class?on?which?any?applet?is?built.?
    Applet的生命周期:基本上,在Applet類的每個實例中有四個方法。

    init:?This?method?is?intended?
    for?whatever?initialization?is?needed?for
    ?your?applet.?It?is?called?after?the?param?attributes?of?the?applet?tag.?
    init:這個往往用來執行你的applet需要做的所有初始化工作,當在applet標記中的param屬性讀入后開始調用。

    start:?This?method?is?automatically?called?after?init?method.?It?is?also?called?whenever?user?returns?to?the?page?containing?the?applet?after?visiting?other?pages.?
    start:此方法在init方法調用完后自動調用,它是執行訪問其它頁面后用戶重新返回到包含applet的頁面中時的操作。

    stop:?This?method?is?automatically?called?whenever?the?user?moves?away?from?the?page?containing?applets.?You?can?use?
    this
    ?method?to?stop?an?animation.?
    stop:此方法當用戶從包含applet的頁面中離開時自動調用,你能夠用此方法來停止你的動畫。

    destroy:?This?method?is?only?called?when?the?browser?shuts?down?normally.?
    destroy:此方法僅當正常地關閉瀏覽器時被調用。

    Thus,?the?applet?can?be?initialized?once?and?only?once,?started?and?stopped?one?or?more?times?in?its?life,?and?destroyed?once?and?only?once.

    因此,applet僅能用init一次,能夠在它的生命中被start和stop一次或多次,同時也僅能被destroy一次。

    最后還用一個例子吧:
    ?1/*
    ?2?*?Java(TM)?SE?6?Version?
    ?3?*/

    ?4
    ?5import?java.applet.Applet;
    ?6import?java.awt.Graphics;
    ?7
    ?8//No?need?to?extend?JApplet,?since?we?don't?add?any?components;
    ?9//we?just?paint.
    10public?class?Simple?extends?Applet?{
    11
    12????StringBuffer?buffer;
    13
    14????public?void?init()?{
    15????????buffer?=?new?StringBuffer();
    16????????addItem("initializing?");
    17????}

    18
    19????public?void?start()?{
    20????????addItem("starting?");
    21????}

    22
    23????public?void?stop()?{
    24????????addItem("stopping?");
    25????}

    26
    27????public?void?destroy()?{
    28????????addItem("preparing?for?unloading");
    29????}

    30
    31????private?void?addItem(String?newWord)?{
    32????????System.out.println(newWord);
    33????????buffer.append(newWord);
    34????????repaint();
    35????}

    36
    37????public?void?paint(Graphics?g)?{
    38????//Draw?a?Rectangle?around?the?applet's?display?area.
    39????????g.drawRect(0,?0,?
    40???????????getWidth()?-?1,
    41???????????getHeight()?-?1);
    42
    43????//Draw?the?current?string?inside?the?rectangle.
    44????????g.drawString(buffer.toString(),?5,?15);
    45????}

    46}

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 无码日韩精品一区二区三区免费 | 一个人看www免费高清字幕| 毛片a级毛片免费观看免下载| 亚洲精品不卡视频| 99在线热视频只有精品免费| 亚洲国产成人久久综合碰碰动漫3d | 免费AA片少妇人AA片直播| 亚洲黄色在线视频| 在线看免费观看AV深夜影院 | 亚洲AV中文无码乱人伦| 深夜a级毛片免费视频| 亚洲电影日韩精品 | 好猛好深好爽好硬免费视频| 亚洲人妻av伦理| 一个人看的www免费视频在线观看| 国产AV无码专区亚洲AWWW| 怡红院免费的全部视频| 婷婷亚洲综合五月天小说| 亚洲精品在线免费观看视频| 久久亚洲精品专区蓝色区| 国产精品麻豆免费版| 一级毛片在线完整免费观看| 中文字幕久久亚洲一区| 久久久久久成人毛片免费看| 亚洲第一页中文字幕| 大学生高清一级毛片免费| 黄色网址在线免费观看| 国产精品久久久亚洲| 91免费国产自产地址入| 亚洲精品无码人妻无码| 国产亚洲美女精品久久久| 91精品视频在线免费观看| 亚洲精品无码国产片| 亚洲一区无码精品色| 99在线在线视频免费视频观看 | 亚洲jizzjizz在线播放久| 亚洲国产午夜中文字幕精品黄网站| 拍拍拍无挡免费视频网站| 亚洲人成网站色在线观看| 亚洲综合最新无码专区| 91热成人精品国产免费|