1 / 9

Applet

Applet. Using the APPLET Tag. Applet 屬 性 (Code, Height, Width). Applet 參數. <applet> 標籤有三個必要的屬性 width 和 height : 指定 applet 在網頁上的寬高 code : 指定 applet 類別所在位置. Attribute 由網頁中讀取 屬性. Demo.htm. <html> <body> <applet code= = " Test.Applet1.class " width=100 height=100

elan
Télécharger la présentation

Applet

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Applet

  2. Using the APPLET Tag Applet 屬性 (Code, Height, Width) Applet 參數 • <applet> 標籤有三個必要的屬性 • width 和 height : 指定applet 在網頁上的寬高 • code : 指定 applet 類別所在位置

  3. Attribute由網頁中讀取屬性 Demo.htm <html> <body> <applet code= ="Test.Applet1.class"width=100 height=100 Name="Jing" Age="20"> </applet> </body> </html> Package Name Class Name package Test; import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; public class Applet1 extends JApplet{ public void paint(Graphics g){ String Name=getParameter("Name"); g.drawString("Name="+Name,1,10); } } Package Name Class Name Package Name ClassName.java

  4. Parameter由網頁中讀取參數 <html> <body> <applet code="Test.Applet1.class" width=100 height=100 Name="Jing" Age="20"> <PARAM name=kkName value=20> </applet> </body> </html> Demo.htm import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; public class Applet1 extends JApplet{ public void paint(Graphics g){ String Name=getParameter("kkName"); g.drawString("Name="+Name,1,10); } } ClassName.java

  5. applet 參數—提供外界目前applet所使用的參數資訊 getParameterInfo() Applet1 import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; public class Applet1 extends JApplet{ public String [][] getParameterInfo( ){ String [][] 參數資訊 = { {“檔名”, “字串”, “這個參數是一個圖檔名稱”}, {“顏色”, “整數值”, “文字的顏色”} }; return 參數資訊 ; } } ClassName.java

  6. Applet 資源 getDocumentBase() : 傳回這個 applet 所在文件的 URL 位置 getCodeBase() : 傳回 applet 的類別檔案所在的 URL 位置 public class AppletDemo extends JApplet{ } public void paint(Graphics g){ String strDocumentBase=this.getDocumentBase().toString(); String strCodeBase=this.getCodeBase().toString(); g.drawString("CodeBase="+strCodeBase,1,10); g.drawString("DocumentBase="+strDocumentBase,1,100); } 目前這個class 檔的位置 目前這個html 檔的位置

  7. 控制瀏覽器 • 瀏覽器的狀態列: 一行文字指出瀏覽器目前的動作 • 顯示新的文件 showStatus("現在的狀態"); getAppletContext().showDocument(“www.kimo.com.tw”); *有可能被瀏覽器忽略

  8. 整理一下 Applet stub: 當 applet 被建立時,一個 Appletstub 會依附著它,提供瀏覽器 與 applet 之間的介面 • AppletStub 介面所提供的methods • boolean isActive(); • URL getDocumentBase(); • URL getCodeBase(); • String getParameter(String name); • AppletContext getAppletContext(); • void appletResize(int width, int height); • AppletContext 介面所提供的一些 methods • AudioClip getAudioClip(URL url); • Image getImage(URL url); • Applet getApplet(String name); • Enumeration getApplets(); • void showDocument(URL url); • public void showDocument(URL url, String target); • Void showStatus(String status);

  9. Applet 與 Application • 基本觀念是在 applet 中加入 main 方法並且提供一個 JFrame讓 applet 在其中執行 import java.applet.Applet; import java.awt.* import javax.swing.*; public class MySuperApplet extends JApplet{ public static void main(String [] args) { JApplet theApplet= new MySuperApplet(); // 將 applet 實體化 JFrame theFrame=new JFrame(); // 建立視窗讓 applet 執行 theFrame.setSize(200,200); theFrame.getContentPane().add(“Center”,theApplet); theApplet.init(); // 起始 applet theApplet.start(); theFrame.setVisible(true); // 顯示視窗 } } Applet 部分的程式碼 : init() start()

More Related