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

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

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

    學(xué)海拾遺

    生活、技術(shù)、思想無(wú)處不在學(xué)習(xí)
    posts - 52, comments - 23, trackbacks - 0, articles - 3
      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

    JAVA Applet生命周期

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

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

    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技術(shù)的瀏覽器能夠從Internet下載它并運(yùn)行。applet是典型的嵌入到網(wǎng)頁(yè)里面并在瀏覽器上下文中運(yùn)行的。applet必須是java.applet.Applet類的子類,java.applet.Applet提供applet和瀏覽器環(huán)境之間的接口標(biāo)準(zhǔn)。

    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提供一個(gè)特殊的applet子類,叫做javax.swing.JApplet,當(dāng)所有的applet要用到Swing部件來(lái)構(gòu)造他們的GUI時(shí),那么它就需要用到它。

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

    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:這個(gè)往往用來(lái)執(zhí)行你的applet需要做的所有初始化工作,當(dāng)在applet標(biāo)記中的param屬性讀入后開(kāi)始調(diào)用。

    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方法調(diào)用完后自動(dòng)調(diào)用,它是執(zhí)行訪問(wèn)其它頁(yè)面后用戶重新返回到包含applet的頁(yè)面中時(shí)的操作。

    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:此方法當(dāng)用戶從包含applet的頁(yè)面中離開(kāi)時(shí)自動(dòng)調(diào)用,你能夠用此方法來(lái)停止你的動(dòng)畫(huà)。

    destroy:?This?method?is?only?called?when?the?browser?shuts?down?normally.?
    destroy:此方法僅當(dāng)正常地關(guān)閉瀏覽器時(shí)被調(diào)用。

    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一次或多次,同時(shí)也僅能被destroy一次。

    最后還用一個(gè)例子吧:
    ?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}

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 在线观看免费大黄网站| 国产特黄一级一片免费 | 三年片在线观看免费观看大全动漫 | **aaaaa毛片免费同男同女| 国产亚洲A∨片在线观看| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 3d动漫精品啪啪一区二区免费| 国产亚洲婷婷香蕉久久精品| 中文字幕视频免费在线观看| 四虎永久精品免费观看| 亚洲AV无码一区二区三区久久精品 | 免费无遮挡无遮羞在线看| 亚洲人成色7777在线观看不卡| 国产精品亚洲专区在线播放| 国产午夜免费福利红片| 日本永久免费a∨在线视频| 亚洲综合精品网站| 中文字幕免费不卡二区| 亚洲精品视频在线| 国产精品色拉拉免费看| 亚洲精品国产高清在线观看| 免费国产不卡午夜福在线| j8又粗又长又硬又爽免费视频| 日韩在线永久免费播放| 97se亚洲综合在线| 深夜福利在线视频免费| 亚洲中文字幕久久精品无码APP | 一级特黄色毛片免费看| 国产亚洲精品精华液| 亚洲国产精品免费在线观看| 亚洲啪AV永久无码精品放毛片| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 天天摸天天操免费播放小视频| 小说区亚洲自拍另类| 亚洲人成人无码网www电影首页 | 国内一级一级毛片a免费| 中文字幕免费在线看电影大全 | 最近2019中文字幕免费大全5| 亚洲91精品麻豆国产系列在线| 日本一区二区三区日本免费| 中国内地毛片免费高清|