⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1.htm

📁 Java Applet入门教程
💻 HTM
字号:
<html><!-- #BeginTemplate "/Templates/empolder_doc.dwt" -->
<head>
<!-- #BeginEditable "doctitle" --> 
<title>|&gt;&lt;| 太平洋电脑信息网 -&gt; 网络学院 -&gt; 开发教室</title>
<!-- #EndEditable --> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
-->
</style>
<link rel="stylesheet" href="/pcedu/style/text.css"></head>

<body bgcolor="#FFFFFF" topmargin=0 leftmargin=0 marginheight="0">
<script language="JavaScript" src="/pcedu/script/top.js">
</script>
<table width=760 border=0 cellspacing=0 cellpadding=0 align=center>
  <tr> 
    <td width=194 height="56"><a href=http://www.pconline.com.cn><img src=http://www.pconline.com.cn/images/pconlinelogo.gif width=162 height=35 vspace=10 border=0></a></td>
    <td width=406 height="56">
      <script language="JavaScript" src="/pcedu/script/empolder_ad.js">
</script>
    </td>
    <td width=158 align=right height="56">
      <script language="JavaScript" src="/pcedu/script/empolder_ad1.js">
</script>
    </td>
    <td align=right width=2 height="56">&nbsp;</td>
  </tr>
</table>
<table border=0 cellpadding=0 cellspacing=0 width=760 align="center">
  <tbody> 
  <tr valign=bottom> 
    <td rowspan=2 width=172><img height=32 src="/pcedu/images/pcedu_lo.gif" 
      width=172 border="0"></td>
    <td height=30 rowspan=2> 
      <table cellpadding=0 cellspacing=0 width="588" bgcolor="#FFA000" background="/pcedu/images/e_menu5.gif" border="0">
        <tbody> 
        <tr valign="bottom"> 
          <td height="17"> 
            <script language="JavaScript" src="/pcedu/script/title_empolder.js">
</script>
          </td>
        </tr>
        </tbody> 
      </table>
    </td>
  </tr>
  <tr></tr>
  <tr bgcolor="#303880"> 
    <td colspan=2 height=1 valign=bottom><img height=1 
      src="/pcedu/images/blank.gif" width=1></td>
  </tr>
  <tr> 
    <td colspan=2 height=5 valign=bottom><img height=5 
      src="/pcedu/images/blank.gif" width=1></td>
  </tr>
  </tbody> 
</table>
<table width="760" cellspacing="0" cellpadding="0" align="center" height="37">
  <tr> 
    <td width="170" valign="top"> 
      <table border="0" width="170" height="100%"
    cellspacing="1" bgcolor="#000000">
        <tr bgcolor="#F8F8D2"> 
          <td width="100%" valign="top"><!-- #BeginEditable "left" --> 
            <div align="center"> 
              <table width="100%" border="0" cellspacing="1" cellpadding="0" bgcolor="#000000" align="center">
                <tr bgcolor="#E17329"> 
                  <td height="20" align="center"><font color="#FFFFFF">==<b>开发教室==</b></font></td>
                </tr>
              </table>
              <br>
            </div>
            <!-- #EndEditable -->
            <script language="JavaScript" src="/pcedu/script/left_empolder.js">
</script>
          </td>
        </tr>
      </table>
    </td>
    <td width="10"><img src="/pcedu/images/blank.gif" width="1" height="1"></td>
    <td width="580" valign="top" class="article"> 
      <p><img src="/pcedu/images/666666.gif" width="99%" height="1"></p>
      <!-- #BeginEditable "content" --> 
      <p align="center"><span class="title">Java Applet 入门</span></p>
      <p align="right"><a href="mailto:yy435@263.net">yy435</a></p>
      <p align="right">太平洋网络学院</p>
      <p align="center" class="green">第六天</p>
      <p class="green">一 图形文件的读入</p>
      <p>&nbsp;&nbsp;&nbsp;&nbsp;在Java中,可以直接载入并输出图形文件格式, 一共有两种,分别是Gif和Jpeg文件(不要怀疑,真的不支持BMP文件格式)。只要你能够给定图形文件的位置和文件名,就可以通过getImage这个方法载入所要的图形。</p>
      <p>&nbsp;&nbsp;&nbsp;&nbsp;在这里所说的位置,指的并不是在磁盘上的哪一个目录,而是图形文件所在的URL位置。换句话说,你不但可以在Java程序中使用存放在自己硬盘上的图形文件,还可以通过URL指定的方式,直接度曲网络资源上的图形文件,而且使用的方式非常简单,完全没有一般在编写网络程序上常遇到的困难和负担。</p>
      <p>&nbsp;&nbsp;&nbsp;&nbsp;让我们来看一看getImage的使用方式,getImage这个方法主要出现在两个类里,第一个是java.applet.Applet中,另外一个是java.awt.Tookit。在编写Java应用程序时,只能使用Java.awt.Tookit中的方法,而编写Java小应用程序时,良种都可以使用。getImage方法的格式是:<br>
        1)在java.applet.Applet类内<br>
        <font color="#FF9999">Image getImage(URL,url)<br>
        Image getImage(URL url,String name)</font><br>
        2)在java.awt.Tookit类内<br>
        <font color="#FF9999">Image getImage(String filename)<br>
        IMage getImage(URL url)</font></p>
      <p>&nbsp;&nbsp;&nbsp;&nbsp;举个例子来说,它的调用方法为:</p>
      <p><font color="#FF9999">URL url1,url2;<br>
        url1=new URL(&quot;file:/d:/image/pic1.gif&quot;);<br>
        url2=new URL(&quot;http://abc.cde.edu.cn/Applet/pic2.jpg&quot;);<br>
        Image image1=getImage(url1):<br>
        Image image2=getImage(url2):<br>
        Image image3=getImage(getCodeBase(),&quot;p1.jpg&quot;);</font></p>
      <p>&nbsp;&nbsp;&nbsp;&nbsp;其中的getCodeBase()方法是返回相对路径,也就是说,你的网页文件现在在哪儿,那么它的返回值就是你的网页文件的这个位置。</p>
      <p>把图形文件读入内存中后,下一步,就是要将它显示出来了,怎么显示出来,用g.drawImage(image1,x,y,this)方法就可以了,x,y是图形显示的坐标点。如果要改变大小,可以用如下的显示方式。</p>
      <p><font color="#FF9999">g.drawImage(image1,x,y,width,height,this);<br>
        g.drawImage(image1,x,y,width,height,Color.blue,this);</font></p>
      <p>&nbsp;&nbsp;&nbsp;&nbsp;后面的一种方法是将图片的背景色设置成为blue颜色,改变width和height就可以达到改变图片的显示大小与比例,可以形成放大与缩小,或者是拉长拉扁等效果了。</p>
      <p>&nbsp;&nbsp;&nbsp;&nbsp;让我们看一个具体的例子吧!</p>
      <table width="600" border="1" bordercolor="#FF9933">
        <tr> 
          <td width="365"><applet code="Applet1.class" width="400" height="200">
            </applet></td>
          <td width="219"> 
            <p>这是一幅图片显示两次,请查看它的源代码</p>
            <p>[<a style="text-decoration: none"href="#" onclick="window.open('12.htm','1','menubar=no,toolbar=1,location=no,directories=no,status=no,resizable=1,scrollbars=1,width=780,height=440,top=20,left=10');"> 
              查看源代码</a>]</p>
          </td>
        </tr>
      </table>
      <p>&nbsp;</p>
      <p>二 声音文件的读入</p>
      <p>&nbsp;&nbsp;&nbsp;&nbsp;声音文件和Java读入图形格式的原理是一样的,但是,现在Java好象还只支持AU格式的声音文件格式,这种格式并不多见,所以可能需要大家将别的文件格式转化成为这种格式了。它的调入方法和播放方法如下:</p>
      <p><font color="#FF9999">import java.applet.AudioClip;<br>
        AudioClip bgsound=getAudioClip(URL url):</font></p>
      <p><font color="#FF9999">bgsound.play(); &nbsp;&nbsp;&nbsp;&nbsp;//播放一次<br>
        bgsound.loop();&nbsp;&nbsp;&nbsp;&nbsp;//循环播放<br>
        bgsound.stop(); &nbsp;&nbsp;&nbsp;&nbsp;//停止播放<br>
        //你也可以直接一次性地读入并播放<br>
        play(getCodeBase(),&quot;audio/welcome.au&quot;);</font></p>
      <p><font color="#FF9999">……</font></p>
      <p>它的URL的使用方法同前面的读入图象时用的方法是一个原理,这儿就不多说了!</p>
      <p>三 JavaApple中字体属性的设置</p>
      <p align="center"><a href="../05/12.htm">[上一页]</a> <a href="13.htm">[下一页]</a></p>
      <!-- #EndEditable --> 
      <div align="center">
<table width="100%" border="0">
          <tr class="sfont"> 
            <td>
              <div align="center"><a href="javascript:history.go(-1)">[返回]</a>
              </div>
            </td>
          </tr>
        </table>
      </div> 
      </td>
  </tr>
</table>
<hr noshade size="2" width="760">
<div align="center"> 
  <p align="center"><font color="#000000"> 
    <script language="JavaScript" src="/pcedu/script/title_edu.js">
</script>
    </font> <br>
    <br>
    版权所有&copy;2000 太平洋电脑网<br>
    <font face="Arial, Helvetica, sans-serif">
    <script>
document.write("<a href=http://best.netease.com/cgi-bin/view/viewbasic.cgi?exp target=_blank><img src=http://best.netease.com/cgi-bin/log.cgi?user=exp&refer="+escape(document.referrer)+"&cur="+escape(document.URL)+" border=0 alt='网易中文排行榜' width=1 height=1></a>");
</script>
    <a href=mailto:webmaster@pconline.com.cn> </a></font><font face="Arial, Helvetica, sans-serif"><a href=mailto:webmaster@pconline.com.cn>webmaster@pconline.com.cn</a></font><font face="Arial, Helvetica, sans-serif"><a href=mailto:webmaster@pconline.com.cn> 
    <script language="">document.write("<a href=http://best.netease.com/cgi-bin/view/viewbasic.cgi?pconline1 target=_blank><img src=http://best.netease.com/cgi-bin/log.cgi?user=pconline1&refer="+escape(document.referrer)+"&cur="+escape(document.URL)+" border=0 width=1 height=1 ></a>");</script>
    </a>
    <script language="">
document.write("<a href=http://www0.pconline.com.cn:8810/pccount/index.php target=_blank><img src=http://www0.pconline.com.cn:8810/cgi-bin/test.cgi?user=pcedu&refer="+escape(document.referrer)+"&cur="+escape(document.URL)+" border=0 width=0 height=0 alt='' ></a>");
</script>
    </font> </p>
    </div>
 
</body>
<!-- #EndTemplate --></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -