11.1 Applets & graphics
11.1.1 What are applets? Applets are programs that display and run in a web browser Embedded in a web page Include graphics, GUI and event handing capabilities Must extend from the java.applet.Applet class
11.1.2 Launching applets Applications are started by a call to the main method Applets have no main method Class file referenced in the HTML document Browser loads and runs the Applet JDK includes the appletviewer application
11.1.3 Applets and security Applets could be invisible & malicious Must be constrained to prevent attacks Applet security rules Cannot run another program Cannot perform file I/O Cannot call native methods Cannot connect to any host other than the one that provided the Applet
11.1.4 Embedding a Java applet HTML tags are used to embed the Java applet Use the APPLET tag to specify the class file and the window size
11.2.1 Creating an applet Applets must extend java.applet.Applet Require methods to handle events Implement graphics and components, with appropriate layout managers
11.4.1 Applet inherited methods Applet inherits from Panel Can be asigned a layout manager (the default is FlowLayout) Other panels can be added Listeners can register Similar to other GUI applications
11.4.2 Applet lifecycle methods init(), start(), stop(), destroy() init() is called when the applet is loaded start() is called by init, and when the user returns to the page stop() is called when the user leaves the page destroy() is called when the browser is closed
11.5.1 GUI components, color & fonts Applets can implement a simple GUI Use layout managers, color and fonts Few restrictions other than the security controls Applets need to be small
11.5.4 Other applet methods Applet methods are called by the browser Different browser events result in calls to the methods
11.6.1 Applets and event-driven programming Components can generate events in response to user interaction Programmers create objects called handlers to react to these events Handlers must register as a listener with the component that can generate the event
11.7.1 Creating graphic objects To draw in a component a Graphics object is required Use the getGraphics() method to obtain an instance of Graphics paint(), update() and repaint() are important members of the component class
11.8 Case Study: JBANK Application