Chapter 14 Applets Images and audio Prerequisites for part工工工 hapter 8 Inheritance and polymorphism Chapter 9 Abstract Classes and Interfaces Chapter 11 Getting Started with GUI Programmin Chapter 12 Event-Driven Programming 愿生如夏花之绚烂,死如秋叶之静美-泰戈尔 Chapter 13 Creating User Interfaces hapter 14 Applets, Images, Audio Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 1 Chapter 14 Applets, Images, and Audio Prerequisites for Part III Chapter 11 Getting Started with GUI Programming Chapter 8 Inheritance and Polymorphism Chapter 13 Creating User Interfaces Chapter 14 Applets, Images, Audio Chapter 9 Abstract Classes and Interfaces Chapter 12 Event-Driven Programming 愿生如夏花之绚烂,死如秋叶之静美---- 泰戈尔
Objectives To explain how the Web browser controls and executes applets(s 14.2) To describe the init, start, stop, and destroy methods in the applet class ( s 142) To know how to embed applets in Web pages(s 14.4) To run applets from appletviewer and from Web browsers(s 14.4) To pass string values to applets from htMl(8 14.5) To write a Java program that can run as both an application and an applet( s 146) To get image files using the uRl class and display images in the panel( s 14.oPtional) To develop a reusable component Image Viewer to display images(s 14.10 Optional To get audio files and play sound(s 14 12 Optional) To package and deploy Java projects using Java archive files (s 14.13 Optional) o To use Swing pluggable look-and-feel (8 14 14 Optional) Liang, Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 2 Objectives ⚫ To explain how the Web browser controls and executes applets (§ 14.2). ⚫ To describe the init, start, stop, and destroy methods in the Applet class (§ 14.2). ⚫ To know how to embed applets in Web pages (§ 14.4). ⚫ To run applets from appletviewer and from Web browsers (§ 14.4). ⚫ To pass string values to applets from HTML (§ 14.5). ⚫ To write a Java program that can run as both an application and an applet (§ 14.6). ⚫ To get image files using the URL class and display images in the panel (§ 14.9 Optional). ⚫ To develop a reusable component ImageViewer to display images (§ 14.10 Optional). ⚫ To get audio files and play sound (§ 14.12 Optional). ⚫ To package and deploy Java projects using Java archive files (§ 14.13 Optional). ⚫ To use Swing pluggable look-and-feel (§ 14.14 Optional)
Introduction pple PRogram that runs in Applet Container e appletviewer(test utility for applets) Web browser (IE, Communicator) OExecutes when HTML(Hypertext Markup Language) document containing applet is opened and downloaded O Applications run in command windows Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 3 Introduction ⚫Applet Program that runs in Applet Container ⚫appletviewer (test utility for applets) ⚫Web browser (IE, Communicator) Executes when HTML (Hypertext Markup Language) document containing applet is opened and downloaded Applications run in command windows
Launching applets o Applications are http://somelocation/file.html started by a call to the main method <HTML> HTML file ● Applets have no main < APPLET CODE=…> </APPLET> method o Class file referenced in Applet Classes the html document Locationhttp://somelocation/file.html Browser loads and Browser runs the applet OJDK includes the Loading. appletviewer application Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai -kaiyu 4 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
The TicTacToe Applet ● You start as player"ⅹ" Fig 3.2 Sample execution of the TicTactoe applet Ap回冈國Ap回囻Ap图匾Ap回冈國Ap□回区 Applet Applet 又。 XI XOX XOX X。 Applet started Applet started Applet started Applet started Applet started Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 5 The TicTacToe Applet ⚫You start as player "X" Fig. 3.2 Sample execution of the TicTacToe applet