本文整理汇总了Java中javax.swing.JComponent.getGraphics方法的典型用法代码示例。如果您正苦于以下问题:Java JComponent.getGraphics方法的具体用法?Java JComponent.getGraphics怎么用?Java JComponent.getGraphics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JComponent
的用法示例。
在下文中一共展示了JComponent.getGraphics方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawBox
import javax.swing.JComponent; //导入方法依赖的package包/类
/**
* Draw a box on screen.
*
* @param component The {@code JComponent} to draw on.
* @param startPoint The starting {@code Point}.
* @param endPoint The end {@code Point}.
*/
private void drawBox(JComponent component,
Point startPoint, Point endPoint) {
if (startPoint == null || endPoint == null
|| startPoint.distance(endPoint) == 0
|| getFreeColClient().getMapEditorController() == null)
return;
Graphics2D graphics = (Graphics2D)component.getGraphics();
graphics.setColor(Color.WHITE);
int x = Math.min(startPoint.x, endPoint.x);
int y = Math.min(startPoint.y, endPoint.y);
int width = Math.abs(startPoint.x - endPoint.x);
int height = Math.abs(startPoint.y - endPoint.y);
graphics.drawRect(x, y, width, height);
}
示例2: getTransformedGraphics
import javax.swing.JComponent; //导入方法依赖的package包/类
@Override
public Graphics2D getTransformedGraphics(JComponent source) {
return (Graphics2D) source.getGraphics();
}