⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 draw_kline.java

📁 一份java写的期货交易程序
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    }

    boolean MouseDragged(int x, int y)
    {
        return MouseLeftClicked(x, y);
    }

    private void DrawCursor(int iNewPos)
    {
        Graphics g = ((MenuListener) (parent)).m_applet.getGraphics();
        g.setColor(HQApplet.rhColor.clBackGround);
        g.setXORMode(HQApplet.rhColor.clCursor);
        if(m_iPos != -1)
        {
            int x = m_rcPane[0].x + (int)(m_pos.m_Ratio / 2.0F + (float)m_iPos * m_pos.m_Ratio);
            g.drawLine(x, m_rcPane[0].y + 1, x, (m_rcPane[2].y + m_rcPane[2].height) - 1);
            m_indicator[0].DrawCursor(g, m_iPos);
        }
        if(iNewPos != -1)
        {
            m_iPos = iNewPos;
            int x = m_rcPane[0].x + (int)(m_pos.m_Ratio / 2.0F + (float)m_iPos * m_pos.m_Ratio);
            g.drawLine(x, m_rcPane[0].y + 1, x, (m_rcPane[2].y + m_rcPane[2].height) - 1);
            m_indicator[0].DrawCursor(g, m_iPos);
        }
        g.setPaintMode();
    }

    private void DrawLabel()
    {
        if(m_kData == null || m_kData.length == 0)
            return;
        Graphics g = ((MenuListener) (parent)).m_applet.getGraphics();
        int iIndex;
        if(m_iPos < 0)
            iIndex = m_kData.length - 1;
        else
            iIndex = m_pos.m_Begin + m_iPos;
        for(int i = 0; i < 3; i++)
            m_indicator[i].DrawTitle(g, iIndex);

        if(m_iPos < 0)
            return;
        g.clearRect(m_rcLabel.x, m_rcLabel.y, m_rcLabel.width, m_rcLabel.height);
        g.setColor(HQApplet.rhColor.clNumber);
        g.drawRect(m_rcLabel.x, m_rcLabel.y, m_rcLabel.width, m_rcLabel.height);
        g.setFont(new Font("宋体", 0, 14));
        FontMetrics fm = g.getFontMetrics();
        int x = m_rcLabel.x + 1;
        int y = m_rcLabel.y + fm.getAscent() + 1;
        g.setColor(HQApplet.rhColor.clItem);
        g.drawString(((MenuListener) (parent)).m_applet.getShowString("Date"), x, y);
        y += fm.getHeight();
        String str = String.valueOf(m_kData[iIndex].date);
        switch(((MenuListener) (parent)).m_applet.m_iKLineCycle)
        {
        case 1: // '\001'
        case 2: // '\002'
            break;

        case 3: // '\003'
            if(str.length() >= 6)
                str = str.substring(0, 6);
            break;

        default:
            if(str.length() >= 4)
                str = str.substring(0, 8);
            break;
        }
        x = (m_rcLabel.x + m_rcLabel.width) - fm.stringWidth(str) - 1;
        g.setColor(HQApplet.rhColor.clEqual);
        g.drawString(str, x, y);
        if(((MenuListener) (parent)).m_applet.m_iKLineCycle >= 4 && ((MenuListener) (parent)).m_applet.m_iKLineCycle <= 7)
        {
            str = String.valueOf(m_kData[iIndex].date);
            str = str.substring(8, 10) + ":" + str.substring(10);
            y += fm.getHeight();
            x = (m_rcLabel.x + m_rcLabel.width) - fm.stringWidth(str) - 1;
            g.drawString(str, x, y);
        }
        x = m_rcLabel.x + 1;
        y += fm.getHeight();
        g.setColor(HQApplet.rhColor.clItem);
        g.drawString(((MenuListener) (parent)).m_applet.getShowString("Open"), x, y);
        float fPreClose;
        if(iIndex > 0)
            fPreClose = m_kData[iIndex - 1].balancePrice;
        else
            fPreClose = m_kData[iIndex].openPrice;
        y += fm.getHeight();
        str = Common.FloatToString(m_kData[iIndex].openPrice, m_iPrecision);
        if(m_kData[iIndex].openPrice > fPreClose)
            g.setColor(HQApplet.rhColor.clIncrease);
        else
        if(m_kData[iIndex].openPrice < fPreClose)
            g.setColor(HQApplet.rhColor.clDecrease);
        else
            g.setColor(HQApplet.rhColor.clEqual);
        x = (m_rcLabel.x + m_rcLabel.width) - fm.stringWidth(str) - 1;
        g.drawString(str, x, y);
        x = m_rcLabel.x + 1;
        y += fm.getHeight();
        g.setColor(HQApplet.rhColor.clItem);
        g.drawString(((MenuListener) (parent)).m_applet.getShowString("High"), x, y);
        y += fm.getHeight();
        str = Common.FloatToString(m_kData[iIndex].highPrice, m_iPrecision);
        if(m_kData[iIndex].highPrice > fPreClose)
            g.setColor(HQApplet.rhColor.clIncrease);
        else
        if(m_kData[iIndex].highPrice < fPreClose)
            g.setColor(HQApplet.rhColor.clDecrease);
        else
            g.setColor(HQApplet.rhColor.clEqual);
        x = (m_rcLabel.x + m_rcLabel.width) - fm.stringWidth(str) - 1;
        g.drawString(str, x, y);
        x = m_rcLabel.x + 1;
        y += fm.getHeight();
        g.setColor(HQApplet.rhColor.clItem);
        g.drawString(((MenuListener) (parent)).m_applet.getShowString("Low"), x, y);
        y += fm.getHeight();
        str = Common.FloatToString(m_kData[iIndex].lowPrice, m_iPrecision);
        if(m_kData[iIndex].lowPrice > fPreClose)
            g.setColor(HQApplet.rhColor.clIncrease);
        else
        if(m_kData[iIndex].lowPrice < fPreClose)
            g.setColor(HQApplet.rhColor.clDecrease);
        else
            g.setColor(HQApplet.rhColor.clEqual);
        x = (m_rcLabel.x + m_rcLabel.width) - fm.stringWidth(str) - 1;
        g.drawString(str, x, y);
        x = m_rcLabel.x + 1;
        y += fm.getHeight();
        g.setColor(HQApplet.rhColor.clItem);
        g.drawString(((MenuListener) (parent)).m_applet.getShowString("Close"), x, y);
        y += fm.getHeight();
        str = Common.FloatToString(m_kData[iIndex].closePrice, m_iPrecision);
        if(m_kData[iIndex].closePrice > fPreClose)
            g.setColor(HQApplet.rhColor.clIncrease);
        else
        if(m_kData[iIndex].closePrice < fPreClose)
            g.setColor(HQApplet.rhColor.clDecrease);
        else
            g.setColor(HQApplet.rhColor.clEqual);
        x = (m_rcLabel.x + m_rcLabel.width) - fm.stringWidth(str) - 1;
        g.drawString(str, x, y);
        boolean bShowBalance = true;
        if(((MenuListener) (parent)).m_applet.m_iKLineCycle != 1 && (((MenuListener) (parent)).m_applet.getProductType(m_product.sCode) == 2 || ((MenuListener) (parent)).m_applet.getProductType(m_product.sCode) == 3))
            bShowBalance = false;
        x = m_rcLabel.x + 1;
        y += fm.getHeight();
        if(bShowBalance)
        {
            g.setColor(HQApplet.rhColor.clItem);
            g.drawString(((MenuListener) (parent)).m_applet.getShowString("Balance"), x, y);
        }
        y += fm.getHeight();
        if(bShowBalance)
        {
            str = Common.FloatToString(m_kData[iIndex].balancePrice, m_iPrecision);
            if(m_kData[iIndex].balancePrice > fPreClose)
                g.setColor(HQApplet.rhColor.clIncrease);
            else
            if(m_kData[iIndex].balancePrice < fPreClose)
                g.setColor(HQApplet.rhColor.clDecrease);
            else
                g.setColor(HQApplet.rhColor.clEqual);
            x = (m_rcLabel.x + m_rcLabel.width) - fm.stringWidth(str) - 1;
            g.drawString(str, x, y);
        }
        x = m_rcLabel.x + 1;
        y += fm.getHeight();
        g.setColor(HQApplet.rhColor.clItem);
        g.drawString(((MenuListener) (parent)).m_applet.getShowString("Volume"), x, y);
        y += fm.getHeight();
        str = String.valueOf(m_kData[iIndex].totalAmount);
        g.setColor(HQApplet.rhColor.clVolume);
        x = (m_rcLabel.x + m_rcLabel.width) - fm.stringWidth(str) - 1;
        g.drawString(str, x, y);
        x = m_rcLabel.x + 1;
        y += fm.getHeight();
        g.setColor(HQApplet.rhColor.clItem);
        g.drawString(((MenuListener) (parent)).m_applet.getShowString("Money"), x, y);
        y += fm.getHeight();
        str = String.valueOf((long)(m_kData[iIndex].totalMoney / 100D));
        g.setColor(HQApplet.rhColor.clVolume);
        x = (m_rcLabel.x + m_rcLabel.width) - fm.stringWidth(str) - 1;
        g.drawString(str, x, y);
        x = m_rcLabel.x + 1;
        y += fm.getHeight();
        g.setColor(HQApplet.rhColor.clItem);
        g.drawString(((MenuListener) (parent)).m_applet.getShowString("Order"), x, y);
        y += fm.getHeight();
        str = String.valueOf(m_kData[iIndex].reserveCount);
        g.setColor(HQApplet.rhColor.clReserve);
        x = (m_rcLabel.x + m_rcLabel.width) - fm.stringWidth(str) - 1;
        g.drawString(str, x, y);
    }

    void CreateIndicator()
    {
        int iPrecision = ((MenuListener) (parent)).m_applet.GetPrecision(((MenuListener) (parent)).m_applet.strCurrentCode);
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("ASI"))
            m_indicator[2] = new ASI(m_pos, iPrecision);
        else
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("BIAS"))
            m_indicator[2] = new BIAS(m_pos, iPrecision);
        else
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("BRAR"))
            m_indicator[2] = new BRAR(m_pos, iPrecision);
        else
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("BOLL"))
            m_indicator[2] = new BOLL(m_pos, iPrecision);
        else
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("CCI"))
            m_indicator[2] = new CCI(m_pos, iPrecision);
        else
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("CR"))
            m_indicator[2] = new CR(m_pos, iPrecision);
        else
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("DMA"))
            m_indicator[2] = new DMA(m_pos, iPrecision);
        else
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("DMI"))
            m_indicator[2] = new DMI(m_pos, iPrecision);
        else
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("EMV"))
            m_indicator[2] = new EMV(m_pos, iPrecision);
        else
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("EXPMA"))
            m_indicator[2] = new EXPMA(m_pos, iPrecision);
        else
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("KDJ"))
            m_indicator[2] = new KDJ(m_pos, iPrecision);
        else
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("MACD"))
            m_indicator[2] = new MACD(m_pos, iPrecision);
        else
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("MIKE"))
            m_indicator[2] = new MIKE(m_pos, iPrecision);
        else
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("OBV"))
            m_indicator[2] = new OBV(m_pos, iPrecision);
        else
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("ORDER"))
            m_indicator[2] = new Reserve(m_pos, iPrecision);
        else
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("PSY"))
            m_indicator[2] = new PSY(m_pos, iPrecision);
        else
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("ROC"))
            m_indicator[2] = new ROC(m_pos, iPrecision);
        else
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("RSI"))
            m_indicator[2] = new RSI(m_pos, iPrecision);
        else
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("SAR"))
            m_indicator[2] = new SAR(m_pos, iPrecision);
        else
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("TRIX"))
            m_indicator[2] = new TRIX(m_pos, iPrecision);
        else
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("VR"))
            m_indicator[2] = new VR(m_pos, iPrecision);
        else
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("W%R"))
            m_indicator[2] = new W_R(m_pos, iPrecision);
        else
        if(((MenuListener) (parent)).m_applet.m_strIndicator.equals("WVAD"))
            m_indicator[2] = new WVAD(m_pos, iPrecision);
    }

    void ChangeIndicator(boolean bDown)
    {
        int iCur = -1;
        for(int i = 0; i < IndicatorBase.INDICATOR_NAME.length; i++)
        {
            if(!IndicatorBase.INDICATOR_NAME[i][0].equals(((MenuListener) (parent)).m_applet.m_strIndicator))
                continue;
            iCur = i;
            break;
        }

        if(bDown)
            iCur = (iCur + 1) % IndicatorBase.INDICATOR_NAME.length;
        else
        if(iCur < 1)
            iCur = IndicatorBase.INDICATOR_NAME.length - 1;
        else
            iCur = (iCur - 1) % IndicatorBase.INDICATOR_NAME.length;
        ((MenuListener) (parent)).m_applet.m_strIndicator = IndicatorBase.INDICATOR_NAME[iCur][0];
        CreateIndicator();
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -