<form id="hz9zz"></form>
  • <form id="hz9zz"></form>

      <nobr id="hz9zz"></nobr>

      <form id="hz9zz"></form>

    1. 明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

      Java編程小技巧集錦

      [摘要]東方快騎阿樂飛揚1. Javadoc API文件產生器   Javadoc程序讀取一個Java類文件并自動創建一組HTML文件,這些HTML 文件描述了Java類文件的類、變量、成員函數,所有Jav...
      東方快騎阿樂飛揚

      1. Javadoc API文件產生器
        Javadoc程序讀取一個Java類文件并自動創建一組HTML文件,這些HTML 文件描述了Java類文件的類、變量、成員函數,所有Java類庫的APIHTML 文件都可以由此程序創建。Javadoc把軟件包名或源文件列表當做一個變量。Javadoc依靠以@打頭的備注標記來創建HTML文件,下面就是標注的列表,它們被Javadoc用于在HTML 文件中創建鏈接。

      選項 功能
      @see classname 此標注在類列表中增加一個到所提供類的"See Also"條目。
      @see classname # methodname 此標注創建一個到特定的成員函數的"See Also"條目。
      @version text 此標注在HTML文件中加入一個版本信息條目
      @author text 此標注在HTML文件中加入一個作者信息條目
      @param name description 此標注用成員函數備注來描述一個成員函數所帶變量
      @return description 此標注用成員函數備注來描述返回值
      @exception classname 此標注用成員函數備注來連接成員函數產生的異常出口
      -classpath path 此命令行指定尋找Java文件的目錄
      -d directory 此命令行指定用來放入最終HTML文件十分有用。



      2 調試器--jdb.exe

      Java調度器為Java程序提供了一個命令行調試環境。它既可在本地,也可在與遠程的解釋器的一次對話中執行。jdb于本地機器中可用如下的命令啟動。

      選項 功能
      catch calssID 為特定異常出口而中斷
      classes 列出當前已知的類
      clear classID:line 清除一個斷點
      cont 從斷點處繼續執行
      down[n frames] 下移一個線程的堆棧
      dump ID[ID...] 顯示所有對象信息
      exit(或quit) 退出調試器
      help(或?)  列出所有命令
      ignore classID 忽略特定的異常出口
      list[line number] 顯示源代碼
      load classbame 載入要調試的Java類
      locals 在當前堆棧幀中顯示所有局部變量
      memory 報告內存使用情況
      methods classID 列出一個類的成員函數集
      print ID[ID...] 列出對象或域
      resume [threadID...] 恢復線程(默認情況恢復所有線程)
      run class [args] 開始執行已下載的Java類
      step 執行當前行
      stop in classID:method 在一成員函數中設一斷點
      stop at classID:line 在一行設一斷點
      suspend[threadID...] 停止一個線程(默認情況停止所有線程)
      hreads threadgroup 列出線程
      thread threadID 設置當前線程
      threadgroups 列出線程組
      threadgroup name 設置當前線程組
      up [n frames] 上移一個線程堆棧
      use [path] 顯示或改變源程序路徑
      where [threadID] or all 使一線程的堆線置空
      !! 重復上一次命令
      -host hostname 該命令告訴Jdb到哪里去建立遠程運行的Java解釋器對話過程
      -password password 本選項告訴Jdb 用哪個密碼去與遠程運行的Java 對話進程相連接。

      密碼 password是由運行帶有-debug選項的Java解釋器所提供的。



      3 在Applet中引用jar中的資源文件

      如果想在servlets程序設計中加上一些圖片,聲音,卡通等,只需使用sun 公司提供的一個有用的工具:jar。這個工具可以把這些資源文件合在一個文件里,避免頻繁的http request,可以下載緩存!

      用jar中的資源的實例方法如下:加一個圖片按扭ImageButton

      (提個醒i.e.g :聲音,卡通,圖片相對路徑為./img/my.gif)

      import java.awt.*;
      import java.awt.event.*;    //下載吧
      import javax.swing.*;     //下載吧
      public class ImageButtonApplet extends JApplet{
           private String path = "/img/my.gif";
           private ImageIcon myButtonIcon = new ImageIcon(getClass().getResource(path));

      /*通過本人多次調試和看jdk自帶的demo 自代的API 文擋, 從JDK1.1得來,相關還有ClassLoader, demo在引用資源的時候采用方法 getClass().getResource(String sourceName)

      如下:

      public URL getResource(String name)
      Finds a resource with a given name. This method returns null if no resource with this name is found. The rules for searching resources associated with a given class are implemented by the * defining class loader of the class.
      This method delegates the call to its class loader, after making these changes to the resource name: if the resource name starts with "/", it is unchanged; otherwise, the package name is prepended to the resource name after converting "." to "/". If this object was loaded by the bootstrap loader, the call is delegated to ClassLoader.getSystemResource.
      Parameters:
      name - name of the desired resource
      Returns:
      a java.net.URL object.

      */
           /**Initialize the applet*/
           public void init(){
           try {
                if (myButtonIcon == null)
                throw new Exception("cannot get the image!");
                JButton iButton = new JButton(myButtonIcon);
                Container cp = this.getContentPane();
                cp.add(iButton);
           }
           catch (Exception e){
              e.printStackTrace();
           }
      }

      }

      子編譯之后,把ImageButtonApplet.class和my.gif保持相對路徑打進jar里面,對應的HTML頁面代碼為<APPLET CODE = "ImageButtonApplet.class" CODEBASE = "." ARCHIVE = "my.jar" WIDTH = "200" HEIGHT = "200"></APPLET>。成功關鍵在于使用getClass().getResource(path).


      日韩精品一区二区三区高清