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

📄 page_marketstatus.java

📁 一份java写的期货交易程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        int x = pos[i][j].x;
                        int y = pos[i][j].y;
                        if(j == 0 || j == 1 && i >= 0 && i < 2 * iCount)
                            paintRankData(g, value, 0, x, y);
                        else
                        if(i >= 2 * iCount && i < 3 * iCount && j == 1)
                            paintRankData(g, value, 5, x, y);
                        else
                        if(i >= 2 * iCount && i < 3 * iCount && j == 2)
                            paintRankData(g, value, 8, x, y);
                        else
                            paintRankData(g, value, 6, x, y);
                    }
                }

            }

        }
    }

    void paintRankData(Graphics g, MarketStatusVO value, int rankType, int x, int y)
    {
        Font font = new Font("宋体", 0, 16);
        FontMetrics fm = g.getFontMetrics(font);
        g.setFont(font);
        String strCode = value.code;
        CodeTable stockTable = (CodeTable)m_applet.m_htProduct.get(strCode);
        String strName = "";
        if(stockTable != null)
            strName = stockTable.sName;
        int iPrecision = m_applet.GetPrecision(strCode);
        boolean showPercent = true;
        if(rankType == 8 || rankType == 5)
            showPercent = false;
        String strCur = formatRankData(g, value.cur, iPrecision, false);
        String strValue = formatRankData(g, value.value, 2, showPercent);
        g.setColor(HQApplet.rhColor.clProductName);
        g.drawString(strCode, x + 3, y + fm.getAscent());
        switch(value.status)
        {
        case 0: // '\0'
            g.setColor(HQApplet.rhColor.clIncrease);
            break;

        case 1: // '\001'
            g.setColor(HQApplet.rhColor.clDecrease);
            break;

        case 2: // '\002'
            g.setColor(HQApplet.rhColor.clEqual);
            break;
        }
        int spare = m_rc.width / 3 - 128;
        if(spare > 64)
        {
            int gap = (spare - 64) / 2;
            g.drawString(strCur, (x + m_rc.width / 3) - 64 - gap - fm.stringWidth(strCur), y + fm.getAscent());
        } else
        {
            g.drawString(strCur, (x + 128) - fm.stringWidth(strCur), y + fm.getAscent());
        }
        switch(rankType)
        {
        case 5: // '\005'
            g.setColor(HQApplet.rhColor.clVolume);
            break;

        case 6: // '\006'
            g.setColor(HQApplet.rhColor.clNumber);
            break;

        case 8: // '\b'
            g.setColor(HQApplet.rhColor.clNumber);
            break;

        case 7: // '\007'
        default:
            if(value.value > 0.0F)
            {
                g.setColor(HQApplet.rhColor.clIncrease);
                break;
            }
            if(value.value == 0.0F)
                g.setColor(HQApplet.rhColor.clEqual);
            else
                g.setColor(HQApplet.rhColor.clDecrease);
            break;
        }
        g.drawString(strValue, (x + m_rc.width / 3) - fm.stringWidth(strValue) - 3, y + fm.getAscent());
    }

    String formatRankData(Graphics g, float num, int iPrecision, boolean isPercent)
    {
        StringBuffer buf = new StringBuffer();
        if(!isPercent)
        {
            buf.append(Common.FloatToString(num, iPrecision));
        } else
        {
            if(num >= 0.0F)
                buf.append("+");
            buf.append(Common.FloatToString(num, iPrecision));
            buf.append("%");
        }
        return buf.toString();
    }

    boolean MouseLeftClicked(int x, int y)
    {
        if(packetInfo == null || statusData == null)
        {
            return false;
        } else
        {
            selectStock(x, y);
            return false;
        }
    }

    private void selectStock(int x, int y)
    {
        int fontHeight = fm.getHeight();
        for(int i = 0; i < iCount * 3; i++)
        {
            for(int j = 0; j < 3; j++)
            {
                int left = pos[i][j].x;
                int top = pos[i][j].y;
                if(x > left && x < left + m_rc.width / 3 && y > top && y < top + fontHeight && (iHighlightRowIndex != i || iHighlightColIndex != j) && getIndexOfStatusDataArray(i, j) >= 0)
                    paintHighlight(i, j);
            }

        }

    }

    boolean MouseLeftDblClicked(int x, int y)
    {
        if(packetInfo == null || statusData == null)
            return false;
        for(int i = 0; i < iCount * 3; i++)
        {
            for(int j = 0; j < 3; j++)
            {
                int left = pos[i][j].x;
                int top = pos[i][j].y;
                int fontHeight = fm.getHeight();
                if(x > left && x < left + m_rc.width / 3 && y > top && y < top + fontHeight)
                {
                    int rows = statusData.length / 9;
                    int index = getIndexOfStatusDataArray(i, j);
                    if(index >= 0)
                        m_applet.QueryStock(statusData[index].code);
                    return true;
                }
            }

        }

        return false;
    }

    int getIndexOfStatusDataArray(int i, int j)
    {
        if(i % iCount >= packetInfo.iCount)
            return -1;
        int rows = statusData.length / 9;
        if(i >= 0 && i < iCount)
            return j * 3 * rows + i;
        if(i >= iCount && i < 2 * iCount)
            return ((j * 3 + 1) * rows + i) - iCount;
        if(i >= 2 * iCount && i < 3 * iCount)
            return ((j * 3 + 2) * rows + i) - 2 * iCount;
        else
            return -1;
    }

    void makeMenus()
    {
        menuQuote = new MenuItem(m_applet.getShowString("MultiQuote") + "  F2");
        menuQuote.setActionCommand("cmd_XX");
        menuQuote.addActionListener(this);
        menuMinLine = new MenuItem(m_applet.getShowString("MinLine") + "  F5");
        menuMinLine.setActionCommand("minline");
        menuMinLine.addActionListener(this);
        menuKLine = new MenuItem(m_applet.getShowString("Analysis"));
        menuKLine.setActionCommand("kline");
        menuKLine.addActionListener(this);
    }

    void processMenuEvent(PopupMenu popupMenu, int x, int y)
    {
        selectStock(x, y);
        popupMenu.removeAll();
        popupMenu.add(menuMinLine);
        popupMenu.add(menuKLine);
        popupMenu.add(menuQuote);
        processCommonMenuEvent(popupMenu, this);
        popupMenu.show(m_applet, x, y);
    }

    public void actionPerformed(ActionEvent e)
    {
        String cmd = e.getActionCommand();
        if(cmd.indexOf("cmd_") >= 0)
            executeCommand();
        else
        if(cmd.indexOf("STOCK_") >= 0)
        {
            byte stockType = getStockType(cmd);
            changeStockType(stockType);
        } else
        if(cmd.equals("minline"))
        {
            int index = getIndexOfStatusDataArray(iHighlightRowIndex, iHighlightColIndex);
            if(index >= 0)
            {
                String code = statusData[index].code;
                m_applet.showPageMinLine(code);
            }
        } else
        if(cmd.equals("kline"))
        {
            int index = getIndexOfStatusDataArray(iHighlightRowIndex, iHighlightColIndex);
            if(index >= 0)
            {
                String code = statusData[index].code;
                m_applet.showPageKLine(code);
            }
        } else
        {
            super.actionPerformed(e);
        }
    }

    private void changeStockType(byte stockType)
    {
        if(stockType == currentStockType || stockType == -1)
        {
            return;
        } else
        {
            setMenuEnable(currentStockType, true);
            setMenuEnable(stockType, false);
            currentStockType = stockType;
            AskForDataOnTimer();
            return;
        }
    }

    void setMenuEnable(byte byte0, boolean flag)
    {
    }

    private byte getStockType(String name)
    {
        return !name.equals("PRODUCT_COMMON") ? -1 : 1;
    }

    private void executeCommand()
    {
        switch(currentStockType)
        {
        case 1: // '\001'
            m_applet.UserCommand("60");
            break;
        }
    }
}

⌨️ 快捷键说明

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