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

📄 navpanel.java

📁 该系统是一个基于p2p的即时聊天系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        }        return index;    }    /**     * 绘制父按钮     *     * @param i 父按钮的索引     * @param rectangle 父按钮的边界     * @param g the specified Graphics context     */    private void drawParentButton(int i, Rectangle rectangle, Graphics g) {        g.setColor(getBackground());        g.fillRect(rectangle.x, rectangle.y,            rectangle.width, rectangle.height);        //鼠标在某一父按钮的上面        if (getButtonIndex(mousePoint) == -i - 2) {            g.setColor(ColorShop.OVER_PARENT_BG_COLOR);        } else {            g.setColor(ColorShop.EXIT_PARENT_BG_COLOR);        }        g.fillRect(rectangle.x + 2, rectangle.y + 2,            rectangle.width - 4, rectangle.height - 4);        //鼠标在某一父按钮的上面        if (getButtonIndex(mousePoint) == -i - 2) {            g.setColor(ColorShop.OVER_PARENT_FG_COLOR);        } else {            g.setColor(ColorShop.EXIT_PARENT_FG_COLOR);        }        String s = getParentButton(i).getLabel();        g.setFont(BUTTON_FONT);        FontMetrics fontmetrics = g.getFontMetrics();        int j = fontmetrics.stringWidth(s);        g.drawString(s, (rectangle.x + rectangle.width / 2) - j / 2,            (rectangle.y + rectangle.height - 7));        g.setColor(ColorShop.PARENT_BORDER_COLOR);        g.drawRect(rectangle.x + 2, rectangle.y + 2,            rectangle.width - 4, rectangle.height - 4);    }    /**     * 按下“slideDownButton”触发的动作     */    private void pressedSlideDownButton() {        int j = (getSonButtonWidth() + deltaBetweenSonButtons) / slideStep;        try {            for (int i = 0; i < slideStep; i++) {                slideIndex += j;                Thread.sleep(30);                paint(getGraphics());            }        } catch (InterruptedException e) {            e.printStackTrace();        }        theFirstDisplaySonButton++;        slideIndex = 0;        repaint();    }    /**     * 按下“slideUpButton”触发的动作     */    private void pressedSlideUpButton() {        if (theFirstDisplaySonButton > 0) {            int j = (getSonButtonWidth() + deltaBetweenSonButtons) / slideStep;            try {                for (int i = 0; i < slideStep; i++) {                    slideIndex -= j;                    Thread.sleep(30);                    paint(getGraphics());                }            } catch (InterruptedException e) {                e.printStackTrace();            }            theFirstDisplaySonButton--;            slideIndex = 0;            repaint();        }    }    /**     * 按下指定子按钮触发的动作     *     * @param index 子按钮的索引     */    private void pressedSonButton(int index) {        SonButtonClickedEvent event = new SonButtonClickedEvent(this,            sonButtonLabels[selectedParentButtonIndex][index],            selectedParentButtonIndex);        for (int i = 0; i < listeners.size(); i++) {            SonButtonClickedListener listener = (SonButtonClickedListener)                listeners.get(i);            listener.sonButtonClicked(event);        }        pressedSonButton = index;        repaint();    }    /**     * 重置所有父按钮的边界     */    private void resetParentButtonsBounds() {        int j = numberOfParentButton;        int k = selectedParentButtonIndex;        for (int i = 0; i < j; i++) {            getParentButton(i).setVisible(false);            if (i <= k) {                getParentButton(i).setBounds(2, 2 + heightOfParentButton * i,                    getWidth() - 4, heightOfParentButton);            } else {                getParentButton(i).setBounds(2,                    (getHeight() - (j - k) * heightOfParentButton)                    + heightOfParentButton * (i - k) - 2,                    getWidth() - 4, heightOfParentButton);            }        }    }    /*------------------------------------------------------------------------*     *                                覆盖方法                                *     *------------------------------------------------------------------------*/    /**     * 覆盖超类JComponent的方法     *     * @param g the specified Graphics context     */    public void paint(Graphics g) {        resetParentButtonsBounds();        int i = getSize().width;        int j = getSize().height;        if (numberOfParentButton == 0) {            g.setColor(getBackground());            g.fillRect(0, 0, i, j);            g.setColor(getForeground());            return;        }        //先将子按钮画在image对象上        int i1 = i - 4;        int j1 = j - numberOfParentButton * heightOfParentButton;        Image image = createImage(i1, j1);        Graphics g1 = image.getGraphics();        g1.setColor(ColorShop.NAVPANEL_BG_COLOR);        g1.fillRect(0, 0, i1, j1);        g1.setColor(getForeground());        int k1 = (j1 - deltaBetweenSonButtons)            / (getSonButtonWidth() + deltaBetweenSonButtons);        int l1 = k1 + 1;        if (l1 + theFirstDisplaySonButton            > numberOfSonButton[selectedParentButtonIndex]) {            l1 = numberOfSonButton[selectedParentButtonIndex]                - theFirstDisplaySonButton;        }        for (int i2 = theFirstDisplaySonButton;            i2 < theFirstDisplaySonButton + l1; i2++) {            Rectangle rectangle = getSonButtonRectangle(i2);            rectangle.translate(0, -((selectedParentButtonIndex + 1)                * heightOfParentButton) - slideIndex);            g1.drawImage(sonButtons[selectedParentButtonIndex][i2],                rectangle.x, rectangle.y, rectangle.width, rectangle.height,                this);            if (getButtonIndex(mousePoint) == i2) {                if (pressedSonButton == -1) {                    g1.setColor(ColorShop.SON_LIGHT_COLOR);                } else {                    g1.setColor(ColorShop.SON_SHADOW_COLOR);                }                g1.drawLine(rectangle.x, rectangle.y,                    rectangle.x + rectangle.width, rectangle.y);                g1.drawLine(rectangle.x, rectangle.y,                    rectangle.x, rectangle.y + rectangle.height);                if (pressedSonButton == -1) {                    g1.setColor(ColorShop.SON_SHADOW_COLOR);                } else {                    g1.setColor(ColorShop.SON_LIGHT_COLOR);                }                g1.drawLine(rectangle.x + rectangle.width, rectangle.y,                    rectangle.x + rectangle.width,                    rectangle.y + rectangle.height);                g1.drawLine(rectangle.x, rectangle.y + rectangle.height,                    rectangle.x + rectangle.width,                    rectangle.y + rectangle.height);            }            if (getButtonIndex(mousePoint) == i2) {                g1.setColor(ColorShop.OVER_SON_LABEL_COLOR);            } else {                g1.setColor(ColorShop.EXIT_SON_LABEL_COLOR);            }            String s = sonButtonLabels[selectedParentButtonIndex][i2];            g1.setFont(BUTTON_FONT);            FontMetrics fontmetrics = g1.getFontMetrics();            int k2 = fontmetrics.stringWidth(s);            g1.drawString(s, (rectangle.x + rectangle.width / 2) - k2 / 2,                rectangle.y + rectangle.height + 12);        }        if (l1 > k1) {            Rectangle rectangle1 = getSlideDownButtonRect();            rectangle1.translate(-2,                -((selectedParentButtonIndex + 1) * heightOfParentButton));            g1.drawImage(slideDownButton, rectangle1.x, rectangle1.y,                rectangle1.width, rectangle1.height, this);            showSlideDownButton = true;        } else {            showSlideDownButton = false;        }        if (theFirstDisplaySonButton > 0) {            Rectangle rectangle2 = getSlideUpButtonRect();            rectangle2.translate(-2,                -((selectedParentButtonIndex + 1) * heightOfParentButton));            g1.drawImage(slideUpButton, rectangle2.x, rectangle2.y,                rectangle2.width, rectangle2.height, this);        }        g.drawImage(image, 2,            heightOfParentButton * (selectedParentButtonIndex + 1), this);        g.setColor(ColorShop.NAVPANEL_BG_COLOR);        g.drawLine(0, 0, i, 0);        g.drawLine(0, 0, 0, j);        g.drawLine(1, 1, i - 1, 1);        g.drawLine(1, 1, 1, j - 1);        g.drawLine(2, j - 1, i - 1, j - 1);        g.drawLine(i - 1, j - 1, i - 1, 1);        g.drawLine(2, j - 2, i - 2, j - 2);        g.drawLine(i - 2, j - 2, i - 2, 2);        for (int l2 = 0; l2 < numberOfParentButton; l2++) {            Rectangle rectangle3 = getParentButton(l2).getBounds();            drawParentButton(l2, rectangle3, g);        }    }    /*------------------------------------------------------------------------*     *                                实现方法                                *     *------------------------------------------------------------------------*/    /**     * 实现接口ActionListener的方法     *     * @param event ActionEvent对象     */    public void actionPerformed(ActionEvent event) {        for (int i = 0; i < numberOfParentButton; i++) {            if (getParentButton(i) == event.getSource()) {                setSelectedParentButton(i);                break;            }        }    }    /**     * 实现接口ActionListener的方法     *     * @param event MouseEvent对象     */    public void mouseClicked(MouseEvent event) {            }    /**     * 实现接口ActionListener的方法     *     * @param event MouseEvent对象     */    public void mouseEntered(MouseEvent event) {            }    /**     * 实现接口ActionListener的方法     *     * @param event MouseEvent对象     */    public void mouseExited(MouseEvent event) {        mousePoint = event.getPoint();        repaint();    }    /**     * 实现接口ActionListener的方法     *     * @param event MouseEvent对象     */    public void mousePressed(MouseEvent event) {        Point point = event.getPoint();        Rectangle rectangle = getSlideUpButtonRect();        if (rectangle.contains(point) == true) {            pressedSlideUpButton();        } else {            if (showSlideDownButton == true                && getSlideDownButtonRect().contains(point)) {                pressedSlideDownButton();            } else {                int i = getButtonIndex(point);                if (i >= 0) {                    pressedSonButton(i);                } else {                    for (int j = 0; j < numberOfParentButton; j++) {                        Rectangle rectangle2 = getParentButton(j).getBounds();                        if (rectangle2.contains(point)) {                            setSelectedParentButton(j);                            break;                        }                    }                }            }        }    }    /**     * 实现接口ActionListener的方法     *     * @param event MouseEvent对象     */    public void mouseReleased(MouseEvent event) {        if (pressedSonButton >= 0) {            pressedSonButton = -1;            repaint();        }    }    /**     * 实现接口MouseMotionListener的方法     *     * @param event MouseEvent对象     */    public void mouseDragged(MouseEvent event) {            }    /**     * 实现接口MouseMotionListener的方法     *     * @param event MouseEvent对象     */    public void mouseMoved(MouseEvent event) {        Point point = mousePoint;        mousePoint = event.getPoint();        if (getButtonIndex(point) != getButtonIndex(mousePoint)) {            repaint();        }    }}

⌨️ 快捷键说明

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