本文整理匯總了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();
}