Draw the K-line in Java (turn)

Source: Internet
Author: User
Tags thread class
Draw the K-line in Java
Wang Zhe, Mudanjiang City, Heilongjiang Province
----applets in the Java language (Java applets) and application (Java applications) are two different ways of programming that differ greatly in structure and functionality. Applets are applied to Web pages to make colorful page effects and to Tim the site; application, like other programming languages, such as VB, VC, can produce a variety of applications.
----This article discusses the first case of drawing chart with Java applets on a Web page.
----K-line is a stock market analysis of a parameter index, with the stock daily opening, the highest price, the lowest price, closing prices and volume of data such as mapping, with the 5th, 10th EMA can reflect a phase of the stock's ups and downs trend.
----Java applets do chart more to the security type of Web site, to facilitate the analysis of online investors operation. However, due to the relationship between the speed of our country, some securities websites have made chart into pictures to save time for downloading. Of course, the tools (Java applets) and drawing methods used to draw the K-line are the same.
----When writing a Java applet to draw a K-line, there are several key issues to solve: 1 multithreading use, 2 Layout manager selection, 3 data input, output stream application, 4 settings, monitor mouse and keyboard events.
----below, an example is given to elaborate on the entire programming process and methodology.
----One, use multithreading
----A complete Java applet contains four methods, Init (), Start (), Stop (), Destroy () (that is, initialization, start, stop, purge), constitute a complete lifecycle, and the order of operations is executed from top to bottom.
----in the process of drawing chart, in addition to drawing the form and representing the stock movements of the Yin, Yang line rectangle, but also to monitor the mouse events and draw a free moving "cross" cursor, to locate the retrieved stock of the daily price values (such as opening, closing prices, etc.); In order to avoid flicker and reduce the waiting time for recalculation, in addition to redrawing the "cross" cursor that follows the mouse movement, the layout of the page and the Yin and Yang line rectangles are not redrawn; This requires the application of multithreading to accomplish this task.
----1. Some basic concepts about multithreading:
----multithreading is actually starting another process that runs independently of the main program and is loaded from the start () method of the main program and executed by the run () method call. There are two ways to implement multithreading: creating subclasses of the thread class (inheritance of classes) and implementing runnable interfaces.
----for ease of use, Java encapsulates the functionality of all the threads involved in a class in a Java class library: Java.lang.Thread. With this class, Java can create, control, and terminate threads to complete all the operations on multithreading.
----In the Java language, a subclass can inherit only a superclass (parent class), because the Java applet we are writing is applied to the Web page. The browser class (Java.applet) must be inherited first, so in this example we implement multithreading by implementing the Runnable interface, and the following statements are implemented:
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.