Documente Academic
Documente Profesional
Documente Cultură
Applets are not executed by the consolebased Java run-time interpreter. They are executed by either a Web browser or an applet viewer. Execution of an applet does not begin at main( ). User I/O is not accomplished with Javas stream I/O classes.
// A minimal applet. import java.awt.*; import java.applet.*; public class FirstApplet extends Applet { public void paint(Graphics g) { g.drawString("Java makes applets easy",20,20); } } /* <applet code=FirstApplet width=200 height=60> </applet> */
3
Step-1: Edit a Java source file. Step-2: Compile your program. Step-3: Run it. (There are 2 ways to run an applet)
Executing the applet within a Java-compatible Web
browser.(By locating html part in separate html file) Using an applet viewer, such as the standard SDK tool, appletviewer.(C:\>appletviewer FirstApplet.html [or] C:\>appletviewer FirstApplet.java)
4
init()
start()
do some work
init ( )
Called when applet is loaded onto
start ( )
users machine. Prep work or onetime-only work done at this time. (page called up). Called every time applet becomes visible.
stop() destroy()
stop ( )
destroy ( )
Needed if you do any drawing or painting other than just using standard GUI Components Any painting you want to do should be done here, or in a method you call from here Call repaint( ) when you have changed something and want your changes to show up on the screen
6
g.drawString(Hello,20,20);
void setForeground(Color)
< APPLET [CODEBASE = codebaseURL] CODE = appletFile [ALT = alternateText] [NAME = appletInstanceName] WIDTH = pixels HEIGHT = pixels [ALIGN = alignment] [VSPACE = pixels] [HSPACE = pixels] > [< PARAM NAME = AttributeName VALUE = AttributeValue>] [< PARAM NAME = AttributeName2 VALUE = AttributeValue>] . . . [HTML Displayed in the absence of Java] </APPLET>
9