Getting started with Java Applet 1

zhaozj2021-02-11  237

Getting started with Java Applet

YY435

Pacific Network Academy

first day

Summary: [Development of Javapplets] [Compile and View Results] [JavaApplet] [JavaApplet] [related to C language]

Preparation of a first example: 1. Have a Java compiler, can be Sun's JDK compiler, or Microsoft's VJ , or some compilers developed by other companies, but the best Select VJ because it is the best Java compiler now.

2. A text write software, the general machine has, the notepad can be. If it is VJ , you can save this step. If it is JDK, it is best to be one.

3. Browser, can be Netscape, of course, Microsoft IE, other browsers, I don't know if I support Java, it is best to prepare these two in these two, I believe it is not difficult!

Two hands-written first Java Applet program: HelloWorld.java, you can use notepad. (Say with VJ)

The source code code is as follows: (the result is displayed on the right)

Import java.applet. *;

Import java.awt. *;

Public Class HelloWorld Extends Applet

{

Public void Paint (Graphics G)

{

g.drawstring ("Hello, Java World!", 2, 20);

}

}

(This example is very short. But you can explain a lot of questions, huh, huh, to explain it in detail later)

After entering this example, you must remember to save it with HelloWorld.java.

Three JDK compiler compile: Enter the following command in the command line of DOS:

C: /javajdk/javac.exe helloWorld.java

The front C: / Javajdk / is the name of the catalog installed, JavaC.exe is the name of the compiler, and helloworld.java is the name of this program you just prepared. If the compilation is unsuccessful, it is your source code code. If you have a problem, please check it carefully, compile it, and then generate a helloworld.class file. At this time, things are basically completed. Next is to put this generated .class file into the web page, build a web file, as follows:

My first javaapplet program </ title> </ head> </ body></p> <p><p> <applet code = HelloWorld.class width = 300HEight = 200> </ applet></p> <p></ body> </ html></p> <p>If you don't have to say it, you don't have to say it. Double-click this file, you can see this effect that has just been compiled, in the browser. Please see the front.</p> <p>Four VJ compiled and developed the development environment</p> <p>After starting the VJ development environment, it will have a new window, as follows (Figure 1):</p> <p>I will open it, this time, VJ has helped you create a project file, VJ development, any program, it is made in a project, although your program is really small. In its Project Explorer, you can see two files that have been given to you, as shown in Figure 2: Because this program is too small, remove it, the applet1.java (right click, you can choose to delete), Create a new class yourself, click on the Add Class option in the "Project" menu, as shown in Figure 3:</p> <p>Enter: HelloWorld.java in the class name. Entering the car, please press the source code I have given in the new class to add it complete, then, then open the "page1.htm" file in Figure 2, and take it ahead of me. Once you have changed, you can. In this VJ , you can also watch the results directly. If you press the F5 button, you can also watch in a real environment. These are here, if you want to know more about the VJ development environment, then you need to find a book, I can't do it, huh, huh!</p> <p>Fifth pair of detailed explanations of the first example (explained "//" to marke it) Import java.applet. *;</p> <p>/ / To quote Java's Applet class, of course you need to put it first! Equivalent to the #inlcude in the C language.</p> <p>Import java.awt. *; // This is an input and output class, which is used to use the DrawString output function in the program, which is in this class library.</p> <p>// These class libraries introduced earlier, others have helped us do well, don't use white, of course, you can also introduce your own class!</p> <p>Public Class HelloWorld Extends Applet</p> <p>// This is the formal entry of the Java Applet program, and the computer starts from here to perform your settings. Note: public is that the Applet is a public class, and the Class is a class, and the public class represents this is a public class. Then, the name of your program, that is, the name of the file must be the same as the class name of the program's cutout, otherwise compiling // is not. If you don't believe it, you can try it. Extends is the keyword of Java, just like the keyword in the C language, here // means it is an extension of the class library applet. Extends itself is the meaning of expansion.</p> <p>{</p> <p>Public void Paint (Graphics G)</p> <p>// void is empty value, that is, this function does not return value, Paint is the default output function, there is a graphics type parameter</p> <p>{g.drawstring ("Hello, Java World!", 2, 20);</p> <p>// This is the output statement that is often used in Java. DrawString functions require three output variables, the first is a string, to use // quoted, second, three is the output position, respectively The value of the X, Y axis is worth noting that its Y-axis is positive direction.</p> <p>}</p> <p>The relationship between Java Applet and Java and C language Java applet is a subset of the JVAV language. It is a class, so it is full of Java, while JavaScript is not Java's subset, Java Applet and Java The syntax rules are exactly the same. Learning Java Applet is a must-part of learning Java. The Java language can be said that it is basically developed from the C language. Most of Java is inherited from C or C , but it has a write improvement on C or C , deleting many C or C restrictions on the machine. It is the biggest improvement in C or C or the pointer in C or C , which is definitely a good thing for users who are afraid of pointers. Of course, this also canceled the flexibility of C or C grammar Sex, this is good or bad, or wait for everyone to evaluate it. In short, all readers who have learned C or C will learn Java will be very fast. Java's grammar is just a view, focus on the difference between Java and C or C , and Java's new features.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-4738.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="4738" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.041</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'MVRZfPkDfuvhbBm_2BA0ROD1nrjMuxy5I9yIjDxeAj7TuYvzXXq00dVstFSJ_2FwoUTTWJy2_2FRhgm_2BNJsMZj'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>