Applet learning notes 1 "Repost"

xiaoxiao2021-03-06  87

// Import is imported to import a class and file import a parent class and does not import his subclavilt java.applet. *; import java.awt. *; // Extends means inheriting parent class myapplet extends applet The 4 important function init () for initialization of various parameters and getParameter () functions is triggered when the page is displayed when the page is displayed when the page is displayed when the page is displayed. Stop (). () The web page is marked with the end of the applet life * /

Public void init () {} // Paint (Graphics G) This method is included in the AWT. * Public Void Paint (GRAPHICS G) {//g.drawstring (but InTxinTy); use this function output in the applet Strings x, y is the coordinate g.drawstring ("Hello", 20, 30);}; 1.Applet execution mechanism is different from the APLICATION, so there is no main () function 2.applet. AppletViewer myapplet.html This HTML file The production is as follows: Add the following code in the HTML file: [param name = "" value = ""] Archive is used when compressed files multiple files, "," separated CODE for class files Width and Height are The path of the size of the display area, the path of the code applet file, no need, the default and HTML file in the same directory URL can be an absolute path ALT to display the displayed text display in the same page Name to call each APPLET file to call PARAM is a web page Passing an applet: import java.applet. *; Import java.applet. *; Import java.awt. *; Public class a extends applet {private string today; private int speed; public void initiaply; ) {String PV; PV = Gerparameter ("speed"); if (pv == null) {speed = 10;} else {speed = integ.parseint (PV);} Todisplay = "a.speed:" Speed; } Public void Paint (Graphics G) {g.drawstring (Todi SPLAY, 25, 25);}}; APPLET with parameters In initialization, read parameters in GetParameter when initialization, pay attention to the case of the parameter is the key to the success of parameters.

转载请注明原文地址:https://www.9cbs.com/read-97887.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.043, SQL: 9