Java application skills

zhaozj2021-02-17  145

---- 1. Applet and Application ---- Java is a technique for building a score application. It is the best show for the network programming. Enable the Internet to extend from the communication tools to the network that can operate into a mature application program. ---- Java has two types: Applet and Application. Simply speaking, applet is the program embedded in the web document, and Application is the program of all its type. ---- For Java, there is no limit to the big and complexity of Applet and Application, but because the Applet is used for network communication, it is limited by the communication speed. The time is longer, because Applet is small, and there is no concern to Application. ---- The technical difference between applet and Application is coming from the difference in its operational environment. Applets need to come from a large amount of information from the browser: the location and size of the guest house machine, embedded into the parameter of the main HTML document, initialization process (init), start process (START), stop process, Destation, Paint, etc., and Application is much more simple, it comes from the only world. One input is the command line parameter. ---- A subclass for the applet must be a Java.Applet.applet, and Application must have a public square main (). Second, the main thread of the two is not true. Applet is initialized by the method init () to the Applets, and the Application is from the method main () to initiate the program. In general, Java's Applet and Application are completely compiled by the original, but, we can write the applet and the program of Applet is the program. In this way, you can make it more advanced to the inner structure of Java and can make the same order to operate in different ways of transportation, and you can improve Java Interest.

---- The routine is as follows: import java.applet. *; Import java.awt. *; Import java.awt.event. *; Public class example {// # 1 public static void main (String ") ActionListener {// # 1 public static void main [] Args) {frame win = new frame ("eXample"); example example = new example (); win.add (揅 enter ", example); example.init (); // # 2 Win.setsize (600, 360 Win.setVisible;} public void init () {// # 3 Button button; label label; button = new button ("OK"): Button.SetBounds (280, 200, 100, 20); Button.AddActionListener (THIS) ); Label = new label (); label.setbounds (260, 100, 200, 20); add (button); add (label);} public void actionPerformed (ActionEvent E) {Object Source = E.GetSource (); if (Source = = Button) {label.settext ("IT IS A Example!"); }} ---- In the program # 1, you must let the program relay Java.applet.applet class This is the necessary condition for applet, in # 2, you need to have a class An example of example EXAMPLE, incorporates the init () method, and # 3 is the init () method. ---- If you look at the applet, it just covers the init () method and the actionperformed () method to respond to the Button event. If you make Application, it is started by the main () method, the example of the first generation of the program is added to the window, and then the init () method is then adjusted. To compile this approach, you can use it as an Application direct operation as an appLication, and you can send an applet to any browser. ---- 2. Java's sound indication ---- Java as a network programming language, you can act in the browser, can also be played Sound.

In the interaction of the human machine, it is necessary to add a strong effect or to the action to be added. ---- Java's bag java.applet has an AudioClip interface, which is seal some common methods for the shutter. Usage is as follows: AudioClip Audio; Audio = GetAudioClip (getcodebase (), "hi.au"); Audio.Play (); ---- The first line of generating interface Audioclip one variable, second line Use this variable to obtain the sound file Hi.au, this article is in the same object of the program, and the getCodeBase () method is used to obtain the URL address of the applet's Class file. The third line is the broadcast sound file. This usage can be emitted in the browser in the applet. So, can I use this method to send sound in Application? Not available. Because the interface AUDIOCLIP is in the package java.applet, this package is only available for Applet. Yes Yes I can use it to realize it? We can use the skills of 1 to write a program for the applet and the procedure of the Application. Fruit, or not. This is because the Play () method can only be implemented in the applet, and it is not possible to be called for the ApplicationPlay () method. ---- What is it in the application of the presentation in Application? ---- Remember that there is a BEEP statement in VB to enable system speaker, then, Java should also have similar methods. ---- In Java's java.awt.toolkit class, it is possible to realize this feature. Class Toolkit is an abstract class that is the parent class of all tools that implement AWT. The abstract classes in Java cannot be unregistered, but it is generally, the abstract class can be generated, and then this kind of this class is used to take such a method in the abstract class. alternatives . In Toolkit, it is real in the GetDefaultToolkit () method. Now give an example: this is an Application of a guest / server. When the service machine is running, there is a customer and the server, the server will automatically send the sound alarm to make the user's use of the household. .

---- The program is as follows: server: import java.util. *; Import java.io. *; Import java.net. *; Import java.awt. *; Public class server {public static void main String [] args) {Server server; String clientRequest; boolean quit = false; server = new Server (8001); while (quit) {DataInputStream keyboard = new DataInputStream (System.in);! try {clientRequest = server.in. Readline (); if (ClientRequest.trim (). Equals ("close")) {system.out.println ("Client Says:" ClientRequest; system.exit (1);} system.out.println (" Client Says: " ClientRequest); Server.out.Println (Keyboard.Readline ());} catch (ioException e) {system.out.println (" IOException in server.in.readline () " e); system .exit (1);}}}} class Server {private ServerSocket server; private Socket socket; public DataInputStream in; public PrintStream out; public Server (int port) {try {server = new ServerSocket (port); System.out. Println ("/ n *************** ********************************* "); system.out.println (" / n @ (#) net Applecation Version 1.00 97/12/30 "); System.out.Println (" Copyright (C) 1997 (Lui Dongbing) All Rights Reserved. "); System.out.Println (" / N ******* ********************************* "); System.out .println ("/ N Server IS: / N" Server; socket = server.accept (); for (int i = 0; i <260; i ) {// Voice prompt Toolkit.getDefaultToolkit (). Beep );} System.out.println ("/ N Server is Ready! / N"); in = New DataInputStream (Socket.getInputStream ()); OUT =

转载请注明原文地址:https://www.9cbs.com/read-31427.html

New Post(0)