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

📄 cubemenu.java

📁 一段很好的绘制图形控件的java源代码!很具有学习价值!
💻 JAVA
字号:
import javax.swing.*;
import java.awt.*;

/*
 * Created on 2005-6-17
 *
 */

/**
 * @author zhangjian http://www.ismyway.com
 */

public class CubeMenu extends JMenu {

    protected final void paintComponent(Graphics g) {
        Graphics2D graphics = (Graphics2D) g;
        Object oldHint = graphics
                .getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
        graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        super.paintComponent(graphics);
        graphics
                .setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, oldHint);

        graphics.setColor(ImageCreator.mainMidColor);
        graphics.setBackground(ImageCreator.mainMidColor);
        graphics.fillRect(0, 0, this.getWidth(), this.getHeight());

        int x = (this.getWidth() - graphics.getFontMetrics().stringWidth(
                this.getText())) / 4;
        int y = (int) (graphics.getFontMetrics().getLineMetrics(this.getText(),
                graphics).getHeight());

        graphics.setColor(Color.black);
        graphics.drawString(this.getText(), x + 1, y + 1);
        graphics.setColor(Color.white);
        graphics.drawString(this.getText(), x, y);
    }
}

⌨️ 快捷键说明

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