60 likes | 171 Views
JAVA: Chapter 4 Applet & Advanced Graphic, Multimedia, input & output. Learning Outcome. At the end of this slide, student able to: Applet & Advanced Graphic Learn how the Web browser controls and executes the applet Learn how to handle mouse events and keystrokes
E N D
JAVA: Chapter 4 Applet & Advanced Graphic, Multimedia, input & output
Learning Outcome At the end of this slide, student able to: Applet & Advanced Graphic Learn how the Web browser controls and executes the applet Learn how to handle mouse events and keystrokes Multimedia, input & output Develop multimedia applications with audio and images. Understand input and output streams
Applets Applet is file that can used as Graphical User Interface (GUI) inside webpage.
Applets 1. Install jxpiinstall.exe and set as medium security 2. Create New project (to create applets file) 3. Create new java inside that project and clean & debug (to create .jar file) package javaapplication5; import javax.swing.*; public class JavaApplication5 extends JApplet{ public JavaApplication5() { add(new JLabel("Great!", JLabel.CENTER)); } } 4. Create New project (to create html file) 5. Copy .jar file and paste into current project. 6. Create html file: <html> <head> <title>Java Applet Demo</title> </head> <body> <applet code="javaapplication5.JavaApplication5" archive="JavaApplication5.jar"></applet> </body> </html> 7. Open html file using firefox.
Input/Output package javaapplication8; // DataInputStream, DataOutputStream, IOException /* * TestDataStream.java * * $Id:$ * * $Log:$ */ /* * A sample program that works with the DataStream classes * and demonstrates Binary I/O * * @author Liang-16.8 */ import java.io.*; // DataInputStream, DataOutputStream, IOException public class JavaApplication8 { public static void main(String args[]) throws IOException { // Create data output stream DataOutputStream output = new DataOutputStream(new FileOutputStream("temp.dat")); // Write out some data output.writeUTF("John"); output.writeDouble(85.5); output.writeUTF("Jim"); output.writeDouble(185.5); output.writeUTF("George"); output.writeDouble(105.25); // Close the output stream output.close(); // Create data input stream for the file DataInputStream input = new DataInputStream(new FileInputStream("temp.dat")); // Print student scores for (inti=0; i<3; i++) { System.out.println(input.readUTF() + " " + input.readDouble()); } // Close the input stream input.close(); } // main } // TestDataStream