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

📄 applet.html

📁 java 基础的 一点东西,,可以看看
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD>  <TITLE>Java(TM) Language Basics, Part 1, Lesson 3: Building Applets</TITLE>  <META NAME="AUTHOR" CONTENT="Monica Pawlan">  <META NAME="KEYWORDS" CONTENT="programming, basics, Java 2">  <META NAME="OWNER" CONTENT="Editorial/JDC">  <META NAME="revision" CONTENT="@(#)applet.src	1.25 09/24/99  JDC">    <STYLE TYPE="text/css">    <!--     CODE {font-family: Courier, Monospace;          font-size: 12pt}    PRE {font-family: Courier, Monospace;         font-size: 11pt}      -->  </STYLE></HEAD><!-- Start Body Insert--><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" ALINK="#FF0000" VLINK="#660066"><!-- End Body Insert--><!-- Start PageTop Insert --><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="100%">  <TR ALIGN="CENTER" VALIGN="TOP">    <TD WIDTH="157" ALIGN="LEFT">    <IMG SRC="/images/pixel.gif" HEIGHT="40" WIDTH="40" ALT="">    <A HREF="http://java.sun.com/index.html"><IMG SRC="/images/javalogo52x88.gif" WIDTH="52" HEIGHT="88" ALT="Java Technology Home Page" BORDER="0"></A>    <BR>    <IMG SRC="/images/pixel.gif" WIDTH="157" HEIGHT="1" ALT=""></TD>    <TD>    <FORM NAME="seek1" METHOD="GET" ACTION="http://search.java.sun.com/query.html">    <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%">      <TR>        <TD ALIGN="RIGHT">        <IMG SRC="/images/stripelt.gif" WIDTH="6" HEIGHT="14" ALT=""></TD>                <TD WIDTH="100%">                <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%">          <TR>            <TD BGCOLOR="#CC9966" WIDTH="100%">            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>          </TR>                    <TR>            <TD>            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>          </TR>                    <TR>            <TD BGCOLOR="#CC9966">            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>          </TR>                    <TR>            <TD>            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>          </TR>                    <TR>            <TD BGCOLOR="#CC9966">            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>          </TR>                    <TR>            <TD>            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>          </TR>                    <TR>            <TD BGCOLOR="#CC9966">            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>          </TR>        </TABLE>        </TD>                <TD ALIGN="LEFT">        <IMG SRC="/images/stripert.gif" WIDTH="6" HEIGHT="14" ALT=""></TD>        <TD>                <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">          <TR>            <TD VALIGN="CENTER">            <A HREF="http://java.sun.com/a-z/index.html"><IMG SRC="/images/azindex.gif" BORDER="0" WIDTH="72" HEIGHT="11" ALT="A-Z Index"></A></TD>                          <TD VALIGN="CENTER">            <FONT FACE="Helvetica" SIZE="1">            <INPUT TYPE="text" SIZE="15" MAXLENGTH="128" NAME=qt></FONT></TD>                        <TD VALIGN="CENTER">            <INPUT TYPE="image" SRC="/images/search.button.gif" WIDTH="55" HEIGHT="14" ALT="Search" value="search" BORDER="0"></TD>          </TR>        </TABLE>        </TD>      </TR>    </TABLE>    </FORM>    <P>    <TABLE BORDER="0" WIDTH="100%" CELLPADDING="0" CELLSPACING="0">      <TR VALIGN="TOP">        <TD WIDTH="100%"><IMG SRC="/images/chiclet.row.gif" WIDTH="55"           HEIGHT="18" ALT=""></TD>                  <TD ROWSPAN="4" ALIGN="RIGHT" WIDTH="152">        <A HREF="/developer/index.html"><IMG SRC="/images/developer.connection.header.gif" BORDER="0" HEIGHT="42" WIDTH="319" ALT="Java Developer Connection(SM)"></A></TD>      </TR>            <TR VALIGN="TOP">        <TD BGCOLOR="#FFFFFF" HEIGHT="1" WIDTH="100%">        <IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD>      </TR>            <TR VALIGN="TOP">        <TD BGCOLOR="#CC9966" HEIGHT="1" WIDTH="100%">        <IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD>      </TR>            <TR VALIGN="TOP">        <TD><A HREF="/developer/onlineTraining/"><IMG SRC="/images/online-training.gif" WIDTH="165" HEIGHT="22" ALT="Online Training" BORDER=0></A></TD>      </TR>    </TABLE>    </TD>  </TR></TABLE><!-- End PageTop Insert --><!-- Start NavBar Insert --><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="3" BGCOLOR="#FFFFFF" WIDTH="157" ALIGN="LEFT"><!-- tab categories --><TR><TD><A HREF="http://java.sun.com/products/"><IMG SRC="/images/side.tab.products.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Downloads, APIs, Documentation"></A></TD></TR><TR><TD><A HREF="/developer/index.html"><IMG SRC="/images/side.tab.developer.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Java Developer Connection"></A></TD></TR><TR><TD><A HREF="/developer/infodocs/index.shtml"><IMG SRC="/images/side.tab.docs.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Tutorials, Tech Articles, Training"></A></TD></TR><TR><TD><A HREF="/developer/support/index.html"><IMG SRC="/images/side.tab.support.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Online Support"></A></TD></TR><TR><TD><A HREF="/developer/community/index.html"><IMG SRC="/images/side.tab.community.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Community Discussion"></A></TD></TR><TR><TD><A HREF="http://java.sun.com/industry/"><IMG SRC="/images/side.tab.news.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="News &amp; Events from Everywhere"></A></TD></TR><TR><TD><A HREF="http://java.sun.com/solutions"><IMG SRC="/images/side.tab.solutions.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Products from Everywhere"></A></TD></TR><TR><TD><A HREF="http://java.sun.com/casestudies"><IMG SRC="/images/side.tab.case.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="How Java Technology is Used Worldwide"></A></TD></TR><TR><TD>    <DIV ALIGN="RIGHT">    <A HREF="/servlet/PrintPageServlet"><IMG SRC="/images/printbutton.gif" WIDTH="155" HEIGHT="25" ALT="Print Button" BORDER="0"></A>    </DIV></TD></TR><TR><TD>&nbsp;</TD></TR><!-- End NavBar Insert --><!-- START SUB-NAV --><TR>  <TD><!-- INSERT SUB-NAV INFO -->  </TD></TR><!-- END SUB-NAV --></TABLE><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0"><TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><!-- Template Version 2.0 --><!-- ================== --><!-- Start Main Content --><!-- ================== --><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0"><TR><TD VALIGN="TOP"><FONT FACE="Verdana, Arial, Helvetica, sans-serif">  <A NAME="top"></A>  <DIV ALIGN="RIGHT">  <FONT SIZE="-1"><A HREF="/developer/onlineTraining/index.html">Training Index</A></FONT>  <H2>Java<FONT SIZE="-2"><SUP>TM</SUP></FONT> Programming Language Basics, Part 1<BR>  <FONT SIZE="3">Lesson 3: Building Applets</FONT></H2>    <FONT SIZE="-1">[<A HREF="prog.html">&lt;&lt;BACK</A>] [<A HREF="index.html#contents">CONTENTS</A>] [<A HREF="front.html">NEXT&gt;&gt;</A>]</FONT></DIV><P>Like applications, applets are created from classes. However, applets do not have a <CODE>main</CODE> method as an entry point, but instead, have several methods to control specific aspects of applet execution. <P>This lesson converts an application from Lesson 2 toan applet and describes the structure and elements of anapplet. <UL>   <LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">   <A HREF="#convert">Application to Applet</A></FONT>   <LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">   <A HREF="#run">Run the Applet</A></FONT>   <LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">   <A HREF="#struct">Applet Structure and Elements</A></FONT>   <LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">   <A HREF="#package">Packages</A></FONT>   <LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">   <A HREF="#more">More Information</A></FONT></UL><HR><A NAME="convert"></A><H3>Application to Applet</H3>The following code is the <A HREF="./Code/SimpleApplet.java">applet</A> equivalent to the <CODE>LessonTwoB</CODE> application from Lesson 2. The figure below shows how the running applet looks. The structure and elements of the applet code are discussed after the section on how torun the applet just below. <P><IMG SRC="./Art/applet.gif" WIDTH="212" HEIGHT="193" ALT=""><P></FONT><PRE>import java.applet.Applet;import java.awt.Graphics;import java.awt.Color;public class SimpleApplet extends Applet{  String text = &quot;I'm a simple applet&quot;;  public void init() {        text = &quot;I'm a simple applet&quot;;        setBackground(Color.cyan);  }  public void start() {        System.out.println(&quot;starting...&quot;);  }  public void stop() {        System.out.println(&quot;stopping...&quot;);  }  public void destroy() {        System.out.println(&quot;preparing to unload...&quot;);  }  public void paint(Graphics g){        System.out.println(&quot;Paint&quot;);        g.setColor(Color.blue);        g.drawRect(0, 0,                   getSize().width -1,                   getSize().height -1);        g.setColor(Color.red);        g.drawString(text, 15, 25);  }}</PRE><FONT FACE="Verdana, Arial, Helvetica, sans-serif">The <CODE>SimpleApplet</CODE> class is declared <CODE>public</CODE> so the program that runs the applet (a browseror <CODE>appletviewer</CODE>), which is not local tothe program can access it. <A NAME="run"></A><H3>Run the Applet</H3>To see the applet in action, you need an <CODE>HTML</CODE> file with the Applet tag as follows:<P><CODE>&#60;HTML&#62;<BR>&#60;BODY&#62;<BR>&#60;APPLET CODE=SimpleApplet.class WIDTH=200 HEIGHT=100&#62;<BR>&#60;/APPLET&#62;<BR>&#60;/BODY&#62;<BR>&#60;/HTML&#62;<BR></CODE><P>The easiest way to run the applet is with appletviewer shown belowwhere <CODE>simpleApplet.html</CODE> is a file that contains the above HTML code:<P></FONT><PRE>   appletviewer simpleApplet.html</PRE><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><BLOCKQUOTE><HR>

⌨️ 快捷键说明

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