// 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:
Applet Learning Notes 2 "Repost"
Use image
★ Enter image
Image.GetImage (URL, URL)
Image.getimage (URL URL, String Name)
EG:
URL URL1
URL1 = New URL ("
http://www.xyz.com/images/a.gif ");
Image image1 = getImage (URL1);
Image image2 = getImage (getCodeBase (), "../ images / a.gif"); getCodeBase () method is to return a relative path. That is to say, the web file is where he returns the location of the web file.
★ Display image
G. DrawImage (image1, x, y, width, height, this);
G. DrawImage (image1, x, y, width, height, color.blue, this);
The latter is set to blue image background.
2 use sound
★ Resource positioning
Audiopath = New URL (getCodeBase () "../ Sounds / a.midi");
★ Read resources
Getaudioclip (URL); read music into myaudio of the Audioclip class
EG: Audioclip myaudio = GetAudioclip (Audiopath);
★ Music play
Myaudio.loop (); // loop playback
MyAudio.Play (); // Play once
myaudio.stop (); // Stop playback
Or reading and playing directly
Play (getCodeBase () "../ Sounds / A.MIDI");
3. Use fonts and parameters
★ Create a Font
Font Myfont = New Font ("Lishu", Font.Bold, 14);
★ Set font
G.setfont (MyFont);
g.setcolor (color.green); // Set new color
g.drawstring ("string");
4. Draw a function
★ Plot line function
Drawline (X, Y, EX, EY) // Distance (X, Y) to Point (EX, EY)