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

📄 ch39.htm

📁 Java_by_Example,初级经典例子哦,珍藏版本
💻 HTM
📖 第 1 页 / 共 2 页
字号:
		show();	}		public boolean handleEvent(Event e) {		if (e.id == Event.WINDOW_DESTROY) {			dispose();			return true;		} else 			return super.handleEvent(e);	}	public static void main(String args[]) {		myFrame app = new myFrame(&quot;myFrame&quot;);	}}</PRE></BLOCKQUOTE><HR><P><CENTER><TABLE BORDER=1 WIDTH=80%><TR VALIGN=TOP><TD><B>NOTE</B></TD></TR><TR VALIGN=TOP><TD><BLOCKQUOTE>You'll notice that the color of various words change as you enter the listing into the Diva editor. This cool feature is called syntax highlighting.</BLOCKQUOTE></TD></TR></TABLE></CENTER><BLOCKQUOTE></BLOCKQUOTE><LI>Enter Listing D.1 into the editor window. When done, selectFile, Save and use myFrame.java as the file name. The file nameand the class name must be identical in order to compile. As yousave, Diva will ask if you want to add the file to the currentproject. Say yes. The saved file will be added to the myFrameproject, as shown in Figure C.4.<BR><A HREF="fc-4.gif"><B>Figure C.4</B> : <I>myFrame.java is now part of the myFrame project</I>.</A><LI>Select Build, Compile Active Java File. This will start thejavac compiler. Any messages produced by the compiler will bedisplayed in the window along the bottom of the IDE.<LI>Right-click the myJava.java file in the project window, andthen select Project Settings from the context menu. The Settingsfor the open project dialog box should appear with the Files tabdisplayed. If not, select the Files tab.<LI>Click myFrame.java entry in the list and then click Mark as&quot;main.&quot; This lets Diva know which Java file containsthe main procedure. You'll notice that myFrame.java is now markedwith a yellow star in the project window. You click OK to closethe dialog box.<LI>Click Build, Run Java to display the Run java dialog box.Then, click the Run button to actually start the Java interpreter.First, a DOS Window will appear entitled Java Console and thenthe myFrame application will appear.<LI>Click the Close button to exit the myFrame application.</OL><P>The Java console will continue running after the Java applicationis finished. Leave it running. It will be used for the next interpretedJava program that you run. After you close Diva, you can clickthe Close button of the DOS window to close it also. Be warned,however, that it may take a while to close.<H4>The Hierarchy Window</H4><P>The middle window in the top row of the Diva IDE shows the hierarchyof the open Java file. Figure C.5 shows the Hierarchy window formyFrame.java file.<P><A HREF="fc-5.gif"><B>Figure C.5</B> : <I>The Hierarchy window for myFrame.java</I>.</A><P>The Hierarchy window is very useful because you can collapse andexpand sections of the file so that it's easy to see what a filecontains-handy when looking at someone else's code. You'll alsosee that all of the procedures are shown. You can click any procedurename, and its corresponding code will be displayed.<H4>Other Features</H4><P>Diva has a primitive user interface design ability. You accessthis by creating a new file and selecting Diva Design Documentas the new file type. However, very little documentation existsfor this feature. You might be better off waiting for the betaversion.<P>You can also use Diva to automatically generate skeleton codeto handle a variety of common programming situations. Figure C.6shows part of the list of code snippets that Diva has available.You access this list by selecting Edit, Insert Skeleton Code.<P><A HREF="fc-6.gif"><B>Figure C.6</B> : <I>Diva lets you insert code snippets by selecting from a list</I>.</A><P>You can also add your own code to the list of snippets so thatyou can share code with other programmers or simply avoid retyping.<H3><A NAME="Java">Java+</A></H3><P>The Java+ IDE, shown in Figure C.7, seems to be designed to workwith applets. You can compile your Java classes and the IDE willdisplay any compiler messages in a separate window. This IDE doesnot use project files to group source files. Therefore, it isuseful for only small development projects.<P><A HREF="fc-7.gif"><B>Figure C.7</B> : <I>The myFrame.java file inside the Java+ IDE</I>.</A><H3><A NAME="JavaMaker">JavaMaker</A></H3><P>This is another IDE that automates the compilation process. Itdoes have a nice Print Preview mode so that you can see how yourJava code will print. Some people like to try to have only oneprocedure per page so that the code is more understandable. Youcan also launch the compiler and Appletviewer from inside theIDE. Figure C.8 shows what the myFrame.java file and the outputof the compiler looks like inside the JavaMaker IDE.<P><A HREF="fc-8.gif"><B>Figure C.8</B> : <I>The myFrame.java file inside the JavaMaker IDE</I>.</A><H2><A NAME="Tools"><FONT SIZE=5 COLOR=#Ff0000>Tools</FONT></A></H2><P>There are some programs out on the Net that are not directly relatedto compiling and running Java programs. Some programs will helpyou create a base program to start your project, and some willhelp with finding Java documentation.<P>This section describes a few of the tools that are available.<H3><A NAME="AppletGen">AppletGen</A></H3><P>This extremely useful program is a source code generator. AppletGencreates a skeleton applet customized according to your needs.It has no provisions to help you compile or edit the code; itsimply generates a text file. However, this ability might comein very handy. For example, it will free you from needing to rememberhow to add a menu to a frame. If you specify that your appletneeds a menu, the basic menu code will be added to the text file.<P>When AppletGen is first started, you will see the window shownin Figure C.9.<P><A HREF="fc-9.gif"><B>Figure C.9</B> : <I>The AppletGen program</I>.</A><P>As you can see, AppletGen has eight tabs. Here is a summary ofthe tabs:<BLOCKQUOTE>Applet Info-This tab lets you add some documentation to your applet.You can also specify which packages you need to import.</BLOCKQUOTE><BLOCKQUOTE>Applet Tab-This tab lets you specify the information that willbe added to the <TT>&lt;applet&gt;</TT> HTML tag when AppletGengenerates a HTML file. You can also list out the parameters neededfor your applet.</BLOCKQUOTE><BLOCKQUOTE>Applet Attributes-This tab has two subtabs. One, called Options,lets you select the font, colors, and determine if menus, frames,or a stand-alone app is used. The other, called Constants, letsyou enter a list of constants that your applet will be using.</BLOCKQUOTE><BLOCKQUOTE>Events-This tab lets you select which events your applet willrespond to. Procedure stubs will be created for each events thatyou select.</BLOCKQUOTE><BLOCKQUOTE>Threading-Shown in Figure D.9 above, this tab will let you specifyinformation about how you would like threads to be used in yourapplication.</BLOCKQUOTE><BLOCKQUOTE>URLs-You can indicate which URLs your applet will be using asa resource.</BLOCKQUOTE><BLOCKQUOTE>Resources-This is a listing of the AU, GIF, or JPEG files thatyour applet will be using. If the files are not local, the resourcenames defined on the URLs tab will be used.</BLOCKQUOTE><BLOCKQUOTE>Code Options-This tab lets you determine which types of filesAppletGen will create. You can choose to create HTML, Java Code,Documentation, Debug info, and an INI file. The INI file storesall of the choices that you made during the AppletGen session.</BLOCKQUOTE><BLOCKQUOTE>Code Window-This tab displays the Source code that AppletGen hascreated. You can also see the HTML and INI files. Each type offile has its own subtab. You need to click the button near thefile name (top left of the tab) in order to save the files.</BLOCKQUOTE><P>The AppletGen program is great if you are just learning Java.By changing the options on the various tabs and then looking atthe source code that is generated, you will be able to see a lotof different situations. In addition, you can always recreateany given situation if you need a base of code to start developingfrom.<P><CENTER><TABLE BORDER=1 WIDTH=80%><TR VALIGN=TOP><TD><B>NOTE</B></TD></TR><TR VALIGN=TOP><TD><BLOCKQUOTE>You can download this application-in beta form-from <A TARGET="resource window" HREF="http://ugWeb.cs.ualberta.ca/~nelson/AppletGen/AppletGen1.html.">http://ugWeb.cs.ualberta.ca/~nelson/AppletGen/AppletGen1.html.</A></BLOCKQUOTE></TD></TR></TABLE></CENTER><P><H3><A NAME="VbToJava">VbToJava</A></H3><P>This application will let you design using Visual Basic and thenconvert the design into Java code. It has only one screen, shownin Figure C.10, which lets you specify which FRM file to convert.You will also need to specify the Java class name and .java fileto create.<P><A HREF="fc-10.gif"><B>Figure C.10</B> : <I>The Visual Basic to Java Convertor</I>.</A><H3><A NAME="PortaFilter">PortaFilter</A></H3><P>The Java documentation is a little difficult to search becauseit is in HTML format. Bill Bercik has converted the documentationinto the Windows Help format and made the files available foryou to download. You can download the 1.4M file by looking atthis URL:<BLOCKQUOTE><PRE><A TARGET="resource window" HREF="http://www.dippybird.com/download.html">http://www.dippybird.com/download.html</A></PRE></BLOCKQUOTE><P>The following documents have been converted into the Windows Helpformat:<BLOCKQUOTE>Java-- Language Specification</BLOCKQUOTE><BLOCKQUOTE>Java-- White Paper</BLOCKQUOTE><BLOCKQUOTE>Java-- API</BLOCKQUOTE><BLOCKQUOTE>Java-- Man Pages</BLOCKQUOTE><BLOCKQUOTE>Java-- Virtual Machine Specification</BLOCKQUOTE><BLOCKQUOTE>Java-- FAQ's</BLOCKQUOTE><BLOCKQUOTE>Java-- Tips and Tricks</BLOCKQUOTE><BLOCKQUOTE>Java-- Resource Guide</BLOCKQUOTE><P>The help file was last updated on March 3, 1996, so it is prettyup-to-date.<H2><A NAME="Summary"><FONT SIZE=5 COLOR=#Ff0000>Summary</FONT></A></H2><P>This has been a small sampling of the IDEs and tools availableto you for downloading from the net. By monitoring the comp.lang.javanewsgroup, or searching the Alta Vista for Java + IDE, you caneasily find others. Take a few moments to look at each tool tosee if it will be useful to you. Every programmer uses a differentset of utilities and it takes effort to find the set that is rightfor you.<P>One important determinate of which tools to use is the scope ofyour project. If you are just learning Java, your tools shouldbe simple and easy to learn. If you are an accomplished programmer,using a complicated tool with many options might make more sense.Similarly, if you are developing a large program, a tool thattracks many files in a project-oriented way like Diva will bemore useful than Java+, which does not.<P>Finally, the Java language itself is still evolving. It will changeand so will the tools that support it. Java has a bright futureahead. Don't be blinded by it and don't wait for the perfect tool.Start coding today!<HR><HR WIDTH="100%"></P></CENTER><!-- reference library footer #1--></CENTER><IMG SRC="/images/rule.gif" WIDTH="460" HEIGHT="5" VSPACE="5"ALT="Ruler image"><br><FONT SIZE="-1">Contact <a href="mailto:reference@developer.com">reference@developer.com</a> with questions or comments.<br><a href="/legal/">Copyright 1998</a> <a href="http://www.earthweb.com" target="_top">EarthWeb Inc.</a>,  All rights reserved.<BR>PLEASE READ THE <a href="/reference/usage.html">ACCEPTABLE USAGE STATEMENT</a>.<BR>Copyright 1998 Macmillan Computer Publishing. All rights reserved.</FONT></BLOCKQUOTE><!--outer table--><TD VALIGN="TOP"><!--right side ads --><a target="resource window" href="http://adserver.developer.com/cgi-bin/accipiter/adclick.exe/AREA=DCAD1.REF" alt="Click here for more info"><img src="http://adserver.developer.com/cgi-bin/accipiter/adserver.exe/AREA=DCAD1.REF" alt="Click here for more info" height="88" width="88" border="0"></a><P><a target="resource window" href="http://adserver.developer.com/cgi-bin/accipiter/adclick.exe/AREA=DCAD2.REF" alt="Click here for more info"><img src="http://adserver.developer.com/cgi-bin/accipiter/adserver.exe/AREA=DCAD2.REF" alt="Click here for more info" height="88" width="88" border="0"></a><P></td></tr></table></BODY></HTML>

⌨️ 快捷键说明

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