The document provides instructions on creating and customizing Java applets. It explains that applets extend the JApplet class and must implement init(), start(), stop(), and paint() methods. It also lists Graphics methods that can be used to draw on applets and describes how to add mouse event handling.
1 of 4
Download to read offline
More Related Content
Applets
1. Java Applet Handouts<br />To create an applet from BlueJ, simply click new class then the applet radio button.
10. public void destroy(){ }Methods will run in sequence displayed.<br />To customize the look of the applet, call Graphics methods in the paint method.<br />abstract voidcopyArea(intx, inty, intwidth, intheight, intdx, intdy) Copies an area of the component by a distance specified by dx and dy.voiddraw3DRect(intx, inty, intwidth, intheight, booleanraised) Draws a 3-D highlighted outline of the specified rectangle.abstract voiddrawArc(intx, inty, intwidth, intheight, intstartAngle, intarcAngle) Draws the outline of a circular or elliptical arc covering the specified rectangle.voiddrawBytes(byte[]data, intoffset, intlength, intx, inty) Draws the text given by the specified byte array, using this graphics context's current font and color.voiddrawChars(char[]data, intoffset, intlength, intx, inty) Draws the text given by the specified character array, using this graphics context's current font and color.abstract booleandrawImage(Imageimg, intx, inty, Colorbgcolor, ImageObserverobserver) Draws as much of the specified image as is currently available.abstract booleandrawImage(Imageimg, intx, inty, ImageObserverobserver) Draws as much of the specified image as is currently available.abstract booleandrawImage(Imageimg, intx, inty, intwidth, intheight, Colorbgcolor, ImageObserverobserver) Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.abstract booleandrawImage(Imageimg, intx, inty, intwidth, intheight, ImageObserverobserver) Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.abstract booleandrawImage(Imageimg, intdx1, intdy1, intdx2, intdy2, intsx1, intsy1, intsx2, intsy2, Colorbgcolor, ImageObserverobserver) Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface.abstract booleandrawImage(Imageimg, intdx1, intdy1, intdx2, intdy2, intsx1, intsy1, intsx2, intsy2, ImageObserverobserver) Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface.abstract voiddrawLine(intx1, inty1, intx2, inty2) Draws a line, using the current color, between the points (x1,y1) and (x2,y2) in this graphics context's coordinate system.abstract voiddrawOval(intx, inty, intwidth, intheight) Draws the outline of an oval.abstract voiddrawPolygon(int[]xPoints, int[]yPoints, intnPoints) Draws a closed polygon defined by arrays of x and y coordinates.voiddrawPolygon(Polygonp) Draws the outline of a polygon defined by the specified Polygon object.abstract voiddrawPolyline(int[]xPoints, int[]yPoints, intnPoints) Draws a sequence of connected lines defined by arrays of x and y coordinates.voiddrawRect(intx, inty, intwidth, intheight) Draws the outline of the specified rectangle.abstract voiddrawRoundRect(intx, inty, intwidth, intheight, intarcWidth, intarcHeight) Draws an outlined round-cornered rectangle using this graphics context's current color.abstract voiddrawString( HYPERLINK quot;
http://java.sun.com/j2se/1.4.2/docs/api/java/text/AttributedCharacterIterator.htmlquot;
quot;
interface in java.textquot;
AttributedCharacterIteratoriterator, intx, inty) Draws the text given by the specified iterator, using this graphics context's current color.abstract voiddrawString(Stringstr, intx, inty) Draws the text given by the specified string, using this graphics context's current font and color.voidfill3DRect(intx, inty, intwidth, intheight, booleanraised) Paints a 3-D highlighted rectangle filled with the current color.<br />abstract voidfillArc(intx, inty, intwidth, intheight, intstartAngle, intarcAngle) Fills a circular or elliptical arc covering the specified rectangle.abstract voidfillOval(intx, inty, intwidth, intheight) Fills an oval bounded by the specified rectangle with the current color.abstract voidfillPolygon(int[]xPoints, int[]yPoints, intnPoints) Fills a closed polygon defined by arrays of x and y coordinates.voidfillPolygon(Polygonp) Fills the polygon defined by the specified Polygon object with the graphics context's current color.abstract voidfillRect(intx, inty, intwidth, intheight) Fills the specified rectangle.abstract voidfillRoundRect(intx, inty, intwidth, intheight, intarcWidth, intarcHeight) Fills the specified rounded corner rectangle with the current color.abstract ColorgetColor() Gets this graphics context's current color.abstract FontgetFont() Gets the current font.abstract voidsetColor(Colorc) Sets this graphics context's current color to the specified color.abstract voidsetFont(Fontfont) Sets this graphics context's font to the specified font.<br />How to add Mouse Events<br />Import necessary classes: