Post statistical curve on the webpage

zhaozj2021-02-11  152

First, introduction in the NTERNET to make a very personal home page, promptly publish the heartbeat information, in order to attract the world's different skin tones, people in different occupations to watch "foot" to watch, forgetting, and even generosity, It is the dream of the INTERNET surfers. With the formatting of the form, list, fonts, and paragraphs provided by HTML scripting languages, multimedia support, etc., can make the webpage content, clear level, strong readability, these already have many texts, and will not be described here. We know that in various information, statistical information is used to have more information, and the most intuitive way to express statistics is based on these data to draw curves based on these data. Literature [1] describes how to write a statistical curve plotting tool with OLE server capabilities in the Window S operating system, and this theme is: how to use Java to support the drawing, write a statistics The Plot of the Curve is embedded in the HTML script by embedding the PLOT compiled byte code file plot.class to the HTML script, thereby implementing the purpose of posting a statistical curve on the web page. Second, Java Programming Overview 1.java language specification Java inherits C basic syntax, abandoning some outdated features, such as pre-compiled header files, macros, condition compilation, data structures, enumerators, and consisters, It is easy to lead to a pointer to security issues, as well as a molten multi-inheritance, etc., draw on the interface of Objectiv E C and Ada's package, and the basic characteristics needed to built into the Internet network: structure neutral (any chip, any The operating system can run the same version of Java program), security (avoiding infectious viruses and preventing illegal access), multithreading and network communication. In fact, the above-mentioned features, such as pointers and multiple inherits of the pointers and classes, are cursed by C programmers; and new developments, such as structural neutral, safety, multi-threading and network communication, etc. It is a feature of the C programmer to achieve and very difficult to implement. 2. JDK Windows programmer must know how to develop Windows SDK (software development tools), now, the programmer for JA VA development also knows that writing Java applets should be used with JDK (Java development tools). However, the SDK provides a WINDOWS programming interface that is mainly used as a process such as structures and functions such as structures and functions, and the JDK provides Java programming interfaces with packets, interfaces, and classes. In this sense, JDK is similar to Microsoft Visu Al C MFC, or the BOR LAND C OWL is similar: it is a class library, an application framework, a seamlessly integrated solution. The first JDK is JDK should be JDK 1.0.3α, which is issued with Hotjava 1.0.3α in the 1995 Sun's Java Program Design Grand Prix in 1995. In this version, the general package is relatively small, only java.lang, J ava.util and java.io, while other packages related to user interfaces and network communication are available in Hotjava. After the release of version 1.0, this is to provide all Java platform development companies, including all independent, total eight: java.applet, ja va.awt, java.awt.image, java.awt.p Eer, Java.io, Java.lang, Java.net and Java. Util and a Sun. Tools.debug. This article is based on version 1.0 version. Since the package arrangement of 1.0.3α and 1.0 is very large, the program written in the previous version is compiled in the latter version of the compilation tool, but must be modified. At the end of August 1996, Sun has released a version 1.1 version on the Internet, and 1.1 version is slightly improved on the three, design goals and procedures 1.0, and two versions remain completely compatible. Now let's go back to this article. First, consider writing a Java applet, its interface and feature can be described: statistical title and statistics are provided by HTML PARAM label, and the number of statistics is not limited; the X-rays of statistics are not limited, and X-Zhen is drawn according to the value of the data. , Y axis; the coordinate value of the point is marked while connecting each data point in line; provides a selection of three sets of curves.

For the above requirements, consider the construction of two classes to complete: CURVE class is used to implement various aspects of the statistical curve; the PLO T is derived from Applet, which is a small program class of this program, and completes the statistical curve by using the Curve class. draw. In view of the space, the implementation points and their procedures are given below. If you need readers in all source code, please contact the author. 1. Curve Curve class construction is based primarily on the following considerations. (1) base class. Curve derived from the base class Object of all classes of Java, then it could not explicitly declare. Class Curve {...} (2) Drawing Environment. Drawing of output devices such as Windows and other window operating systems, drawing to the display, the printer, etc. is implemented by the drawing environment. Since Java is facing all platforms, including Windows, UNIX, and Macintosh, their drawing environments (such as the display) concept is very different. So, how does Java implement a drawing? It turns out that Java provides an abstract class package for the equipment environment of various drawing devices through the Graphics class in the J Ava.awt package. Programming with Window S is comparison, the concept represented by Graphics is the Device Context, which is the CDC class or OWL TDC class in the MFC. With this comparison, it is better to understand the graphics. That is, all of the ways to draw straight, rectangles, ellipses, polygons, set fonts, plotted text, etc., call the corresponding methods in the G RAPHICS class. The following code is passed to CURVE via the CURVE constructor to use the device environment object G of the small program class Plot to use by other drawings: public curve (graphics g) {mygc = g; ......} (3) Drawing algorithm. Drawing algorithm is a method of implementing a statistical curve, including drawing title, coordinate axis, data link, marking data point coordinates, etc., and its reverse process: clearing these drawings (because when drawing other curves, it is guaranteed to draw the previous draw before All content). In view of the space, only the method of displaying data is given to showdata. Public synchronized void showdata (Vector v) {float maxY = 0; Mygc.SetColor; int XPoint; int ypoint; file: // Determine The maximum value. For (int i = 0; i maxy) {maxy = Temp;}} File: / / Determine the X coordinate of the first data point. XPoint = xorigin (xSpacing / 2); int = 0; int = 0; file: // Draw a small circle at the data point. For (int J = 0; j

IF ((Oldx! = 0) && (Oldy! = 0)) {Mygc.drawline (Oldx-xspacing, oldy, xpoint, ypoint);} mygc.setcolor (color.blue); file: // On the data point Write the data value. String coordstring = float.tostring ((float) v.Elementat (j)). Floatvalue ()); MYGC.DrawString (CoRDString, Xpoint 5, Ypoint - 4); Mygc.SetColor (Color.red); XPoint = xspacing; oldx = xpoint; oldy = ypoint;}} 2. PLOT class PLOT class construct is based primarily on the following considerations. (1) Delicate a Java applet for Applet, and only one class is derived from applet, which is like in the MFC, must have only one class is derived from CWINAPP. In addition, the MFC program is not the same, regardless of why the source program file (.java) containing derived from the Applet class, the generated bytecode file (.class) used by the web page is only the same name with the party, and Source file names have nothing to do, this is easy to confuse. For an alteration, if the file containing the PLOT class is PL Ottest.java, and the build-generated byte code file is named plot.class, not Plott Est.class. Finally, PLOT must be declared as public because an editing unit must have some and have only one class declaration as public. Public Class Plot Extends Applet {... (2) User Interface Currently, Java provides interfaces and classes required for user interfaces required in Java.aw (42 classes and 2 interfaces), of which A variety of user interfaces we see in Windows, such as menus, dialogs, and various controls, such as buttons, list boxes, checkboxes, radio boxes, edit boxes, combo boxs, etc. In view of this program, a set of set box controls is required from the 3 sets of data. The radio box is integrated with CHECKBOX and CheckboxGroup in java.awt: When Checkbox is used separately, it is a check box; and it is added to checkboxgroup. Public void init () {... cbg = new checkboxgroup (); file: // radio button. CB1 = New CHECKBOX ("Data 1", CBG, FALSE); CB2 = New Checkbox ("Data 2", CBG, FALSE); CB3 = New Checkbox ("Data 3", CBG, FALSE);} (3) Layout Manager In Java, in order to make the applet have a consistent look in the user interface in various operating systems, the Layout Manager is used to manage the relative positions of the user interface. Java contains Flow Layout Manager (BorderLayout), Border Manager (GridBagLayout), GridBagLayout,, GridBagLayout, GridBagLayout 5 layout manager.

If you want 3 single-selection box buttons to be placed below in a line, how to write code? You can implement it: First set the PLOT applet as boundary layout, then create a panel object for 3 single-selection box buttons. CBPANEL, for organizing 3 controls, and sets CBPANEL to grid layout, and finally adds CBPANEL to the PLOT class and sets its direction as South. Public void init () {... file: // Sets PLOT as boundary layout. SetLayout (New BorderLayout ()); file: / / For 3 control application panel objects Cbpanel. CBPANEL = new panel (); file: // Sets the grid layout manager and is arranged in 1 × 3. Cbpanel.setLayout (New GridLayout (1, 3)); file: / / Apply for each button to apply for 1 panel. CB1PANEL = New Panel (); CB1PANEL.ADD (CB2PANEL = New Panel (); CB2PANEL.ADD (CB2); CB3PANEL = New Panel (); cb3Panel.Add (CB3); file: // Add to a unified One panel CBPANEL. CBPANEL.ADD (CB1PANEL); CBPANEL.ADD (CB2PANEL); CBPANEL.ADD (CB3PANEL); file: // Add CBPANEL to PLOT, direction is: graphic in north, buttons in south. Add ("South", CBPANEL);} (4) Read the HTML parameter Because this program uses the statistics and statistical headings as the parameters of the applet in the HTML document, you need to read from HTML before starting drawing graphics. These parameters are taken before they begin to display the title and draw statistics. Among them, reading statistical titles and statistics are respectively implemented. 1 Statistics title, its format can be: 1-Desc Represents the statistical title of the first set of data, "Monthly Visitor Statistics" is the title content . public String readStringData (String s) {String tempString = null; Integer param; boolean datapresent = true; int i = 0; try {tempString = getParameter (s "-DESC");} catch (Exception e) {System.out .println (e);} Return Tempstring;} 2 statistics, format can be: 1-2 represents the second data point of the first set of data, 14 Indicates the value of the data point.

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

New Post(0)