Java Code Examples for javax.swing.JComponent.getGraphics()

The following are Jave code examples for showing how to use getGraphics() of the javax.swing.JComponent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: FreeCol   File: CanvasMapEditorMouseListener.java   Source Code and License Vote up 8 votes
/**
 * 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);
}
 
Example 2
Project: freecol   File: CanvasMapEditorMouseListener.java   Source Code and License Vote up 6 votes
/**
 * 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);
}
 
Example 3
Project: rapidminer   File: NullCoordinateTransformation.java   Source Code and License Vote up 4 votes
@Override
public Graphics2D getTransformedGraphics(JComponent source) {
	return (Graphics2D) source.getGraphics();
}