Java network function and programming

zhaozj2021-02-11  202

Java network function and programming

Xu Yingxiao

(Shanghai University Computing Center 25 #)

Summary: Java language is the most popular programming language on the Internet. This article is aimed at Java's network function, which has made a preliminary introduction from the programming method such as image, sound, HTML document and text files from the Internet. The method of resources on the network has been introduced. A large number of concise understandable examples are provided.

Keywords: Java; Internet; network

The Java language is an emerging programming language on the Internet. There are many articles on Java's characteristics and basic programming methods. However, the majority of Java enthusiasts more want to know more about Java more step-by-step programming methods, this article on Java's network function and its programming method

A preliminary introduction.

In order to facilitate the first time to contact Java readers, this article briefly introduces some of Java programming. I. Introduction to Java Programming 1. Programming Environment: For most readers, the following configuration is a more economical option: operating system Win95 compile software JDK1.01 browsing software Netscape 2.0 or more (32-bit) 2. Programming method: first Enter the Java program with the text editor such as Edit, Notepad, etc., with .java as the file name suffix store. Perform the command line: "Javac file name" to compile the Java program. After compiling, generate the character code file that suffix .class. Finally, if it is Java Applitcation, execute the command line: "Java Byte Code File Name" to run the Java program. If it is a java applet, enter the HTML document of the Java Applet with the text editor, with .htm as the file name subsequent replication. Perform the command line: "AppletViewer HTML File Name" to run the Java Applet. Or open the HTML document with Netscape. 3. Description of the procedures in this article In order to make the program to be the most concise programming method, the procedures in this paper generally use the simplest form, omitting the thread and other content. Therefore, the procedure of this article is not a "good" program, but it is easier to understand the beginner. After all the programs in this article, the generated byte code file and the corresponding HTML document are uploaded to http://www.shu.edu.cn/~xyx/test/jvnet, can run correctly. The reader connected to the Internet can open the address with the browser to view the running effect. Readers connecting the Internet can also enter and compile the program in the local hard drive. Open the HTML document with Netscape's File / Open File menu, experience the programming method and view the running effect. If the reader wants to put Java Applet on your host or other FTP server, use the HTTP protocol or FTP protocol in Netscape, which should be modified as follows: If the reader has an account on a WWW host You can do your personal homepage (usually in the user's root directory to create a WWW or public_html directory, HOMEPAGE's address is http: // Hostname / ~ Personal account), you can put the corresponding http://www.shu.edu in this article .cn / ~ xyx / part is modified to reader's own web node address, and then load the generated byte code file and the corresponding HTML document to your own node. If the reader's computer is connected to the Internet, you can also find an FTP node that can be uploaded, such as: ftp: //ftp.shnet.edu.cn/incoming, the corresponding http: //www.shu in this article. The edu.cn/~xyx/ section is changed to the address of the FTP node, and the generated byte code file and the corresponding HTML document are uploaded to the node to view the running effect. If the reader's computer is not connected, it is also possible to run the web service software such as WebStar for Win95 on a single machine to modify the corresponding http: // www. Shu.edu.cn/~xyx/ part of this article to "http: // The local IP address "to simulate network programming.

Second, Java Network Functions and General Steps Java programs for access to networks can obtain resources such as images, sounds, HTML documents, and texts such as network nodes, and can process the obtained resources. For example, a Java program can read the latest data provided by a node every other time, and displayed in the form of a chart. On programming processing, it is generally manually made into a URL type object, and then obtains the resources represented by the object with the corresponding method (Method) in Java. Several examples of Java network functions are described below, and there are several different programming methods. Third, obtain image Java Applet from the network can directly obtain an image directly from the network and display it. In order to understand the programming method and from the local display image, we don't consider the network function first, to see an example of a simple image display: ● Program 1Import java.applet. *;

Import java.awt. *;

Public class imag0 extends applet {

Image image;

Public void init () {

Image = getImage (GetDocumentBase (), "Test.gif");

}

Public void paint (graphics g) {

g.drawImage (image, 0, 0, this);

}

}

This is the simplest acquisition and display image, in this example, first use getImage (getDocumentbase (), image file name to call the image Test.gif from the HTML document, and generate an image Type Object Image, then display the image on the screen with DrawImage (Image, 0, 0, 0, this).

If you want to get images from the other nodes on the network, the key is to create an object corresponding to other nodes on the network. Once the object of the iMage type is obtained, you can make any possible image operations.

Java provides the following ways to create images corresponding to other nodes:

GetImage (New URL)

It can be used in the format:

String URL = "Non-point URL";

Image image;

Try {

Image = GetImage (New URL (URL));

}

Catch (Exception E) {

System.out.println ("Can't Open THE URL");

}

or

URL IMGUR = NULL;

Image image;

Try {

Imgur = New URL ("Nonpare URL");

}

Catch (Malformedurlexcection E) {

System.out.println ("Can't Open THE URL");

}

Image = getImage (IMGUR);

The previous format generates a URL object with "New URL (URL)" and directly as a parameter of GetImage, and the latter format first uses "New URL (URL)" to generate a URL object, and then transmit it to GetImage. The two formats are essentially the same. In both formats, parts of generating URL objects are included

Try {

Get URL objects

}

Catch (Malformedurlexcection E) {

Error prompt

}

in.

For example, to call the image of http://www.shu.edu.cn/~xyx/img/shnet.jpg, the first format is as follows:

● Program 2

Import java.applet. *;

Import java.net. *;

Import java.awt. *;

Public class imag extends applet {image image;

Public void init () {

String Url = "http://www.shu.edu.cn/~xyx/img/shnet.jpg";

Try {

Image = GetImage (New URL (URL));

} catch (exception e) {}

}

Public void paint (graphics g) {

g.drawImage (image, 0, 0, this);

}

}

The second format is complete, as follows:

● Program 3

Import java.applet. *;

Import java.net. *;

Import java.awt. *;

Public class imag2 extends applet {

Image image;

URL IMGUR = NULL;

Public void init () {

Try {

Imgur = New URL ("http://www.shu.edu.cn/~xyx/img/shnet.jpg");

}

Catch (Malformedurlexcection E) {

System.out.println ("Can't Open THE URL");

}

Image = getImage (IMGUR);

}

Public void paint (graphics g) {

g.drawImage (image, 0, 0, this);

}

}

The two programs described above are imag.java and imag2. Java store, execute javac imag.java and javac imagaac2.java, will get the generated image of iMag.class and iMag2.class, and finally create the two Java Applets. HTML documentation, if iMag.class corresponds to the HTML document as follows:

example </ title></p> <p></ hEAD></p> <p><center></p> <p><Applet Code = Imag.class Width = 550 Height = 250></p> <p></ applet></p> <p></ html></p> <p>Install the HTML document into the Test.html file, open with Netscape, if your computer is connected to the Internet, you can see the image from the network displayed from the web. (For other different Java Applets in this article, the corresponding HTML document can be modified as soon as possible "code = imag.class".)</p> <p>Fourth, get a sound from the network</p> <p>Java gets a sound file from the Internet and has two types of programming methods, one is to use Java's Play (URL) and Play (URL, String) to directly play the sound file on the network, and the other is through GetAudioclip (URL) ) Or getAudioClip (URL, String) First obtain sound files from the network and generate an object of the AUDIOCLIP type, and then operate the object.</p> <p>The predecessor's usage format is:</p> <p>String audur = "Nonpode URL";</p> <p>Try {</p> <p>Play (New URL (AUDUR));</p> <p>} catch (exception e) {}</p> <p>or</p> <p>String audur = "Nonpode URL";</p> <p>Try {</p> <p>Play (New URL (AUDUR), sound file name);</p> <p>} The format used by the latter (Exception E) {} is:</p> <p>String audur = "Nonpode URL";</p> <p>Audioclip loopclip;</p> <p>Try {</p> <p>Loopclip = GetAudioclip (New URL (Audur));</p> <p>}</p> <p>Catch (Exception E) {</p> <p>System.out.println ("Can't Open THE URL");</p> <p>}</p> <p>or</p> <p>String audur = "Nonpode URL";</p> <p>Audioclip loopclip;</p> <p>Try {</p> <p>LoopClip = GetAudioclip (New URL (AUDUR), sound file name);</p> <p>}</p> <p>Catch (Exception E) {</p> <p>System.out.println ("Can't Open THE URL");</p> <p>}</p> <p>The above four formats are parameters that generate the URL object part - "New URL (URL)" as a Play or getAudioclip; like the example of the previously handled image, you can also use "New URL (URL)" to get A URL object, then pass it to Play or GetAudioClip. If the format of the first Play (URL), the following programming format can also be used:</p> <p>URL AUDUR = NULL;</p> <p>Try {</p> <p>Audur = New URL ("Node URL");</p> <p>} catch (exception e) {</p> <p>System.out.println ("Can't Open THE URL");</p> <p>}</p> <p>Play (Audur);</p> <p>The following four kinds of formats obtained from the network are given a simple example.</p> <p>For programming:</p> <p>● Program 4 format one</p> <p>Import java.applet. *;</p> <p>Import java.awt. *;</p> <p>Import java.net. *;</p> <p>Public Class Sound1 Extends Applet</p> <p>{Audioclip loopclip;</p> <p>Public void paint (graphics g) {</p> <p>String audur = "http://www.shu.edu.cn/~xyx/java/animator/audio/bark.au";</p> <p>Try {</p> <p>Play (New URL (AUDUR));</p> <p>} catch (exception e) {}</p> <p>}</p> <p>}</p> <p>● Procedure 5 format two</p> <p>Import java.applet. *;</p> <p>Import java.awt. *;</p> <p>Import java.net. *;</p> <p>Public Class Sound2 Extends Applet</p> <p>{Audioclip loopclip;</p> <p>Public void paint (graphics g) {</p> <p>String Audur = "http://www.shu.edu.cn/~xyx/java/animator/audio/";</p> <p>Try {</p> <p>Play (New URL (Audur), "Bark.au");</p> <p>} catch (exception e) {}</p> <p>}</p> <p>}</p> <p>● Procedure 6 format three</p> <p>Import java.applet. *;</p> <p>Import java.awt. *;</p> <p>Import java.net. *;</p> <p>Public class sound extends applet {</p> <p>Audioclip loopclip;</p> <p>Public void init () {</p> <p>String audur = "http://www.shu.edu.cn/~xyx/java/animator/audio/bark.au";</p> <p>Try {</p> <p>Loopclip = getaudioclip (new url);} catch (exception e) {}</p> <p>}</p> <p>Public void paint (graphics g) {</p> <p>Loopclip.loop ();</p> <p>}</p> <p>}</p> <p>● Program 7 format four</p> <p>Import java.applet. *;</p> <p>Import java.awt. *;</p> <p>Import java.net. *;</p> <p>Public Class Sound0 Extends Applet {</p> <p>Audioclip loopclip;</p> <p>URL AUUR;</p> <p>Public void init () {</p> <p>Try {</p> <p>Auur = New URL ("http://www.shu.edu.cn/~xyx/java/animator/audio/");</p> <p>}</p> <p>Catch (Malformedurlexcection E) {</p> <p>System.out.println ("Can't Open THE URL");</p> <p>}</p> <p>LoopClip = GetAudioclip (auur, "bark.au");</p> <p>}</p> <p>Public void paint (graphics g) {</p> <p>Loopclip.loop ();</p> <p>}</p> <p>}</p> <p>5. Display other HTML documents on the network</p> <p>With the GetAppletContext (). Showdocument (URL) provided by Java, there are two formats, there are two formats on the other nodes on the network, and each other is included in the previous display.</p> <p>● Program 8 format one</p> <p>Import java.applet. *;</p> <p>Import java.awt. *;</p> <p>Import java.net. *;</p> <p>Public Class showdoc Extends applet</p> <p>{</p> <p>URL Docur = NULL;</p> <p>Public void paint (graphics g) {</p> <p>Try {</p> <p>Docur = New URL ("http://www.shu.edu.cn/~xyx/doc/manhua.html");</p> <p>}</p> <p>Catch (Malformedurlexcection E) {</p> <p>System.out.println ("Can't Open THE URL");</p> <p>}</p> <p>IF (docur! = null) {</p> <p>GetAppletContext (). showdocument (Docur, "_ blank");</p> <p>}</p> <p>}</p> <p>}</p> <p>● Procedure 9 format two</p> <p>Import java.applet. *;</p> <p>Import java.awt. *;</p> <p>Import java.net. *;</p> <p>Public class showdoc2 extends applet</p> <p>{</p> <p>URL Docur = NULL;</p> <p>Public void paint (graphics g) {</p> <p>Try {</p> <p>GetAppletContext (). showdocument (new url ("http://www.shu.edu.cn/</p> <p>~ XYX / DOC / MANHUA.HTML ");</p> <p>}</p> <p>Catch (Malformedurlexcection E) {</p> <p>System.out.println ("Can't Open THE URL");</p> <p>}</p> <p>}</p> <p>}</p> <p>6. Read the contents of the file on the network</p> <p>The aforementioned network function is just an image, sound and HTML document displayed or played on the network, and does not process its content. In fact, Java can also read the contents of the file on the network, and process their content.</p> <p>The steps to read the contents of the file on the network can be as follows:</p> <p>1. Create an object of a URL type</p> <p>Such as:</p> <p>String url = "ftp://202.120.127.218/incoming/test/readtxt.html";URL fileur</p> <p>Try {</p> <p>Fileur = New URL (URL);</p> <p>Catch (Malformedurlexcection E) {</p> <p>System.out.println ("CAN't Get URL:");</p> <p>}</p> <p>2. Use the OpenStream () of the URL class to obtain the object of the corresponding inputStream class</p> <p>Such as: InputStream Filecon = file.OpenStream ();</p> <p>3. Translate the InputStream object to the object of the DataInputStream class</p> <p>Such as: DataInputStream FileData = New DataInputStream (FileCon);</p> <p>4. Read the content</p> <p>For example, you can read the content with FileData.Readline () or one character with FileData.Readchar character. For the read content, various processes can be performed by the Java Applet, and the processing results are displayed in a variety of ways.</p> <p>The following example is an example of reading http://www.shu.edu.cn/~xyx/doc/manhua.html file content, for the sake of simplicity, this example only reads the contents of the file, and The text area is displayed.</p> <p>● Procedure 10</p> <p>Import java.io. *;</p> <p>Import java.net. *;</p> <p>Import java.awt. *;</p> <p>Import java.applet. *;</p> <p>Public class showfile extends applet {</p> <p>URL fileur;</p> <p>Textarea Showarea = New Textarea ("please wait a while for get</p> <p>TEXT ", 10, 70);</p> <p>Public void init () {</p> <p>String Url = "http://www.shu.edu.cn/~xyx/doc/manhua.html";</p> <p>Try {fileur = new url (url);}</p> <p>Catch (Malformedurlexcection E) {</p> <p>System.out.println ("CAN't Get URL:");</p> <p>}</p> <p>Add (Showarea);</p> <p>}</p> <p>Public void paint (graphics g) {</p> <p>InputStream filecon = null;</p> <p>DataInputStream fileData = null;</p> <p>String fibeline;</p> <p>Try {</p> <p>Filecon = fileur.openStream ();</p> <p>FileData = New DataInputStream (FileCon);</p> <p>While (FileLine = fileData.readline ())! = null) {</p> <p>Showarea.AppendText (fileline "/ n");</p> <p>}</p> <p>}</p> <p>Catch (IOException E) {</p> <p>System.out.println ("Error In I / O:" E.getMessage ());</p> <p>}</p> <p>}</p> <p>}</p> <p>Seven, dynamically use the network resources</p> <p>On the basis of the examples described earlier, resources on the network can be dynamically utilized. Its method is to prepare a thread and automatically read the latest content every other time. This article is no longer expanded in this article, and readers can refer to the following examples or directly.</p> <p>For example, an example of reading http://www.shu.edu.cn/~ww/doc/manhua.html file in the above example is as follows after adding the thread. This example updates the data every 5 seconds. If http://www.shu.edu.cn/~xyx/doc/manhua.html is stored in some change faster information such as the stock market, and there are programs to update their content at any time, then in the Web Add this Java Applet, allows the traffickeeper to get dynamic information. Further, the data can be processed in the program, and the processing result is displayed in a graphical manner. For example, the data of each time is plotted into a curve, and the traffickeeper can see the curve of dynamic changes. // Program 11</p> <p>Import java.io. *;</p> <p>Import java.net. *;</p> <p>Import java.awt. *;</p> <p>Import java.applet. *;</p> <p>Public class Dynashow Extends Java.Applet.Applet</p> <p>Implements runnable {</p> <p>Thread Dthread;</p> <p>URL fileur;</p> <p>Textarea Showarea = New Textarea ("Wait for A While ...", 10, 70);</p> <p>Public void init () {</p> <p>String Url = "http://www.shu.edu.cn/~xyx/doc/manhua.html";</p> <p>Try {fileur = new url (url);}</p> <p>Catch (Malformedurlexcection E) {</p> <p>System.out.println ("CAN't Get URL:");</p> <p>}</p> <p>Add (Showarea);</p> <p>}</p> <p>Public void start () {</p> <p>IF (DTHREAD == NULL)</p> <p>{</p> <p>Dthread = New Thread (this);</p> <p>Dthread.start ();</p> <p>}</p> <p>}</p> <p>Public void stop () {</p> <p>IF (DTHREAD! = null) {</p> <p>Dthread.stop ();</p> <p>Dthread = NULL;</p> <p>}</p> <p>}</p> <p>Public void run () {</p> <p>InputStream filecon = null;</p> <p>DataInputStream fileData = null;</p> <p>String fibeline;</p> <p>While (true) {</p> <p>Try {</p> <p>Filecon = fileur.openStream ();</p> <p>FileData = New DataInputStream (FileCon);</p> <p>While (FileLine = fileData.readline ())! = null) {</p> <p>Showarea.AppendText (fileline "/ n");</p> <p>}</p> <p>}</p> <p>Catch (IOException E) {</p> <p>System.out.println ("Error In I / O:" E.getMessage ());</p> <p>}</p> <p>Try {</p> <p>DThread.sleep (5000);</p> <p>}</p> <p>Catch (InterruptedExcect E) {}</p> <p>Repaint ();</p> <p>}</p> <p>}</p> <p>}</p> <p>Eight, Java network capabilities limit</p> <p>For security, when you use Netscape, Java Applet can only connect to its host, so most of the previous program compiles mostly stored at http://www.shu.edu.cn/~ The top of the XYX corresponds to the host. You need to change the node address in the program when you store other hosts. Otherwise, the browser will display the security error.</p> <p>However, the other HTML documents on the display does not have this limit (such as programs 8, 9), and the reader can compile the program to any WWW server or FTP server, can run. In addition, when the browser opens the HTML document that calls Java Applet from this site, it is not subject to this limit. Therefore, all programs in this article can be stored in this site, as long as the Netscape's File / Open File menu is opened, you can run correctly.</p> <p>For another Java program - Java Application, there is no such limit, such as program 10 for reading file content on the network, the corresponding Java Application can be programmed:</p> <p>● Program 11</p> <p>Import java.io. *;</p> <p>Import java.net. *;</p> <p>Import java.awt. *;</p> <p>Class showfile2 {</p> <p>Public static void main (string args []) {</p> <p>InputStream filecon = null;</p> <p>DataInputStream fileData = null;</p> <p>String fibeline;</p> <p>String Url = "http://www.shu.edu.cn/~xyx/doc/manhua.html";</p> <p>URL fileur;</p> <p>Try {</p> <p>Fileur = New URL (URL);</p> <p>Filecon = fileur.openStream ();</p> <p>FileData = New DataInputStream (FileCon);</p> <p>While (FileLine = fileData.readline ())! = null) {</p> <p>System.out.println (fileline "/ n");</p> <p>}</p> <p>}</p> <p>Catch (IOException E) {</p> <p>System.out.println ("Error In I / O:" E.getMessage ());</p> <p>}</p> <p>}</p> <p>}</p> <p>After using the ShowFile2.java store, after compiling with javac showfile2.java, you can print http://www.shu.edu.cn/~xyx/doc/manhua.html on the screen with Java ShowFile2.java The content of the file.</p> <p>Nine, the method of creating a URL object</p> <p>In the previous example we uniformly create a URL object in the form of a New URL (URL string). In fact, Java provides four forms of creating a URL object:</p> <p>1.New URL (URL String) This format is used in this format, such as:</p> <p>New url ("http://www.shu.edu.cn/~xyx/doc/manhua.html")</p> <p>2.new URL (protocol, host name, file name or path), such as program 2</p> <p>String Url = "http://www.shu.edu.cn/~xyx/img/shnet.jpg";</p> <p>Image = GetImage (New URL (URL)); section can be changed to:</p> <p>Image = GetImage (New URL ("http", "www.shu.edu.cn", "/ ~ xyx /img/shnet.jpg"));</p> <p>3.new URL (protocol, host name, port number, file name or path) 1</p> <p>Such as: New URL ("http", "www.shu.edu.cn", 80, "/ ~xyx/doc/manhua.html")</p> <p>4.NEW URL (Benchmark URL, File Name or Path)</p> <p>Ten, other methods of realizing network functions</p> <p>The above emphasizes the programming method of obtaining sound, image, HTML document, and file data from the network using Java's URL class. Java's network function is very powerful, in addition to the above introduction, you can use the URLConnection class to achieve a wider range of network features, such as sending information to the CGI program on the WWW server; you can write customer software and services yourself by Socket and Serversocket classes. Software, and you can design a communication protocol.</p> <p>〖references〗</p> <p>Laura Lemay, Charles L. Perkins "Teach Yourself Java in 21 Days"</p> <p>Excerpted from "Internet World"</p> <p>Copyright? 1998-2000 Henanfo Port. All Rights Reserved. Henan Info Port is Henan Info Registered Trademark. If you have any comments and suggestions, please pay email to king@email.online.ha.cn</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-5179.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="5179" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.040</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'WXCbcvRl37YtUBIeTJOKmrqhiq8EkmsckV7kqXecWDLa1gypGqP0tJvnG8ZCpe8UZiYNbkqyNrxVvcNc'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>