cubemenu.java
来自「一段很好的绘制图形控件的java源代码!很具有学习价值!」· Java 代码 · 共 40 行
JAVA
40 行
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 + =
减小字号Ctrl + -
显示快捷键?