Java Code Examples for java.awt.Graphics2D.getColor()

The following are Jave code examples for showing how to use getColor() of the java.awt.Graphics2D class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: QN-ACTR-Release   File: QueueDrawer.java   View Source Code Vote up 6 votes
private void drawJobs(Graphics2D g2d) {
	double x = getProcessorXY().x + 2 * PROC_RAD, y = getProcessorXY().y + PROC_RAD * 2 + 4 * ELEMS_GAP;
	Color tmp = g2d.getColor();
	//		System.out.println(nCpu);
	if (nCpu == 1) {
		txtBounds = drawCenteredText("executing cust.:" + donejobs + ", residual time:" + remainingTime[0] + "ms", Color.BLACK, Color.WHITE, x,
				y, g2d, true, false);
		drawCenteredText("executing cust.:" + donejobs + ", residual time:" + remainingTime[0] + "ms", Color.BLACK, Color.WHITE, x
				- txtBounds.getWidth() / 2.0, y, g2d, true, true);
	}
	//		else if(nCpu==2){
	//			txtBounds = drawCenteredText("executing cust.:" + 
	//					donejobs + ", residual time(1):" + remainingTime[0] + "ms"+ ", residual time(2):" + remainingTime[1] + "ms", Color.BLACK, Color.WHITE, x, y, g2d, true, false);
	//			drawCenteredText("executing cust.:" + 
	//					donejobs + ", residual time(1):" + remainingTime[0] + "ms"+ ", residual time(2):" + remainingTime[1] + "ms", Color.BLACK, Color.WHITE, x - txtBounds.getWidth() / 2.0, y, g2d, true, true);
	//
	//		}
	//		else
	//		{
	//			txtBounds = drawCenteredText("executing cust.:" + donejobs , Color.BLACK, Color.WHITE, x, y, g2d, true, false);
	//			drawCenteredText("executing cust.:" + donejobs , Color.BLACK, Color.WHITE, x - txtBounds.getWidth() / 2.0, y, g2d, true, true);
	//		}
	// draw box around text
	g2d.setColor(tmp);
}
 
Example 2
Project: jmt   File: JobsDrawer.java   View Source Code Vote up 6 votes
private Rectangle2D drawCenteredText(String s, Color c, double centerX, double centerY, Graphics2D g2d, boolean draw) {
	Rectangle2D txtBounds;
	double x, y;
	double gap = dCst.getElementsGap();
	g2d.setFont(dCst.getFont());
	txtBounds = dCst.getFont().getStringBounds(s, g2d.getFontRenderContext());
	x = centerX - txtBounds.getWidth() / 2.0;
	y = centerY - txtBounds.getY() - txtBounds.getHeight() / 2;
	txtBounds.setRect(x - gap, y - txtBounds.getHeight() / 2.0 - gap, txtBounds.getWidth() + 2 * gap, txtBounds.getHeight() + 2 * gap);
	Color ctmp = g2d.getColor();
	g2d.setColor(c);
	if (draw) {
		g2d.drawString(s, (float) x, (float) y);
	}
	g2d.setColor(ctmp);
	return txtBounds;
}
 
Example 3
Project: AI-RRT-Motion-Planning   File: VisualisationPanel.java   View Source Code Vote up 6 votes
public void paintState(Graphics2D g2, ASVConfig s) {
	if (s == null) {
		return;
	}
	Path2D.Float path = new Path2D.Float();

	List<Point2D> points = s.getASVPositions();
	Point2D p = points.get(0);
	path.moveTo(p.getX(), p.getY());
	for (int i = 1; i < points.size(); i++) {
		p = points.get(i);
		path.lineTo(p.getX(), p.getY());
	}
	path.transform(transform);
	g2.draw(path);
	if (animating || !displayingSolution) {
		p = transform.transform(points.get(0), null);
		Color color = g2.getColor();
		Stroke stroke = g2.getStroke();
		g2.setColor(Color.BLACK);
		g2.setStroke(new BasicStroke(1));
		g2.draw(new Ellipse2D.Double(p.getX() - 4, p.getY() - 4, 8, 8));
		g2.setColor(color);
		g2.setStroke(stroke);
	}
}
 
Example 4
Project: QN-ACTR-Release   File: StatiDrawer.java   View Source Code Vote up 6 votes
private Rectangle2D drawCenteredText(String s, Color c, double centerX, double centerY, Graphics2D g2d, boolean drawBorder) {
	double x, y;
	g2d.setFont(f);
	txtBounds = f.getStringBounds(s, g2d.getFontRenderContext());
	x = centerX - txtBounds.getWidth() / 2.0;
	y = centerY - txtBounds.getY() - txtBounds.getHeight() / 2;
	txtBounds.setRect(x - ELEMS_GAP, y - txtBounds.getHeight() / 2.0 - ELEMS_GAP, txtBounds.getWidth() + 2 * ELEMS_GAP, txtBounds.getHeight() + 2
			* ELEMS_GAP);
	if (drawBorder) {
		g2d.setColor(invertedColor(c));
		g2d.fill(txtBounds);
		g2d.setColor(c);
		g2d.draw(txtBounds);
	}
	Color ctmp = g2d.getColor();
	g2d.setColor(c);
	g2d.drawString(s, (float) x, (float) y);
	g2d.setColor(ctmp);
	return txtBounds;
}
 
Example 5
Project: litiengine   File: RenderEngine.java   View Source Code Vote up 5 votes
/**
 * PERFORMANCE HINT: The larger the text is, the more time it needs to render
 * especially with antialiasing turned on.
 *
 * @param g
 * @param text
 * @param x
 * @param y
 * @param shadow
 */
public static void drawTextWithShadow(final Graphics2D g, final String text, final double x, final double y, final Color shadow) {
  if (text == null || text.isEmpty()) {
    return;
  }

  final Color old = g.getColor();
  g.setColor(shadow);
  g.drawString(text, (float) x + 1, (float) y + 1);
  g.drawString(text, (float) x + 1, (float) y - 1);
  g.drawString(text, (float) x - 1, (float) y - 1);
  g.drawString(text, (float) x - 1, (float) y + 1);
  g.setColor(old);
  g.drawString(text, (float) x, (float) y);
}
 
Example 6
Project: FreeCol   File: ReportLabourPanel.java   View Source Code Vote up 5 votes
@Override
public void paint(Graphics g) {
    if (selected) {
        Graphics2D g2d = (Graphics2D) g;
        Composite oldComposite = g2d.getComposite();
        Color oldColor = g2d.getColor();
        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
        g2d.setColor(Color.BLACK);
        g2d.fillRect(0, 0, getWidth(), getHeight());
        g2d.setComposite(oldComposite);
        g2d.setColor(oldColor);
    }
    super.paint(g);
}
 
Example 7
Project: freecol   File: ReportLabourPanel.java   View Source Code Vote up 5 votes
@Override
public void paint(Graphics g) {
    if (selected) {
        Graphics2D g2d = (Graphics2D) g;
        Composite oldComposite = g2d.getComposite();
        Color oldColor = g2d.getColor();
        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
        g2d.setColor(Color.BLACK);
        g2d.fillRect(0, 0, getWidth(), getHeight());
        g2d.setComposite(oldComposite);
        g2d.setColor(oldColor);
    }
    super.paint(g);
}
 
Example 8
Project: AWGW   File: ColorEditor.java   View Source Code Vote up 5 votes
public void paintIcon(Component c, Graphics g, int x, int y)
{
    Rectangle r = new Rectangle(x, y, WIDTH - 1, HEIGHT - 1);
    Graphics2D g2 = (Graphics2D) g;
    Color oldColor = g2.getColor();
    g2.setColor(color);
    g2.fill(r);
    g2.setColor(Color.BLACK);
    g2.draw(r);
    g2.setColor(oldColor);
}
 
Example 9
Project: jmt   File: QueueDrawer.java   View Source Code Vote up 5 votes
private RoundRectangle2D drawViewButton(double x, double y, Graphics2D g2d, boolean draw, boolean clicked) {
	Rectangle2D dvR;
	RoundRectangle2D dvRR;
	Color tmp;
	Color fg = Color.BLACK;
	Color bg = Color.LIGHT_GRAY;

	if (clicked) {
		tmp = fg;
		fg = bg;
		bg = tmp;
	}

	if (nCpu > 2) {
		fg = Color.DARK_GRAY.brighter().brighter();
		bg = Color.LIGHT_GRAY;
	}

	dvR = drawCenteredText("change view", fg, bg, x, y, g2d, false, false);
	dvRR = new RoundRectangle2D.Double(x, y, dvR.getWidth(), dvR.getHeight(), 5.0, 5.0);
	if (draw) {
		tmp = g2d.getColor();
		g2d.setColor(bg);
		g2d.fill(dvRR);
		g2d.setColor(fg);
		g2d.draw(dvRR);
		drawCenteredText("change view", fg, bg, x + dvR.getWidth() / 2.0, y + dvR.getHeight() / 2.0, g2d, false, true);
		g2d.setColor(tmp);
	}
	return dvRR;
}
 
Example 10
Project: QN-ACTR-Release   File: QueueDrawer.java   View Source Code Vote up 5 votes
private RoundRectangle2D drawViewButton(double x, double y, Graphics2D g2d, boolean draw, boolean clicked) {
	Rectangle2D dvR;
	RoundRectangle2D dvRR;
	Color tmp;
	Color fg = Color.BLACK;
	Color bg = Color.LIGHT_GRAY;

	if (clicked) {
		tmp = fg;
		fg = bg;
		bg = tmp;
	}

	if (nCpu > 2) {
		fg = Color.darkGray.brighter().brighter();
		bg = Color.LIGHT_GRAY;
	}

	dvR = drawCenteredText("change view", fg, bg, x, y, g2d, false, false);
	dvRR = new RoundRectangle2D.Double(x, y, dvR.getWidth(), dvR.getHeight(), 5.0, 5.0);
	if (draw) {
		tmp = g2d.getColor();
		g2d.setColor(bg);
		g2d.fill(dvRR);
		g2d.setColor(fg);
		g2d.draw(dvRR);
		drawCenteredText("change view", fg, bg, x + dvR.getWidth() / 2.0, y + dvR.getHeight() / 2.0, g2d, false, true);
		g2d.setColor(tmp);
	}
	return dvRR;
}
 
Example 11
Project: freecol   File: FreeColButtonUI.java   View Source Code Vote up 5 votes
@Override
protected void paintButtonPressed(Graphics g, AbstractButton c) {
    if (c.isContentAreaFilled()) {
        Graphics2D g2d = (Graphics2D) g;
        Dimension size = c.getSize();
        Composite oldComposite = g2d.getComposite();
        Color oldColor = g2d.getColor();
        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
        g2d.setColor(Color.BLACK);
        g2d.fillRect(0, 0, size.width, size.height);
        g2d.setComposite(oldComposite);
        g2d.setColor(oldColor);

    }
}
 
Example 12
Project: jmt   File: StatiDrawer.java   View Source Code Vote up 5 votes
public void drawMoreStatus(Graphics2D g2d) {
	double x = 2.0 * (2.0 * STATUS_RAD + ELEMS_GAP) * (queueLength() - 2) + START_GAP;
	Color ctmp = g2d.getColor();
	g2d.setPaint(Color.BLACK);
	drawCenteredText(" . . . ", Color.BLACK, x + STATUS_RAD, panelH / 2.0, g2d, false);
	g2d.setColor(ctmp);
}
 
Example 13
Project: open-java-trade-manager   File: ChartLayerUI.java   View Source Code Vote up 5 votes
@Override
protected void paintLayer(Graphics2D g2, JXLayer<? extends V> layer) {
    super.paintLayer(g2, layer);
    
    if (this.mainTraceInfo.getPoint() == null) {
        return;
    }

    final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    final Color oldColor = g2.getColor();

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(COLOR_BLUE);
    final int BALL_RADIUS = 8;
    g2.fillOval((int)(this.mainTraceInfo.getPoint().getX() - (BALL_RADIUS >> 1) + 0.5), (int)(this.mainTraceInfo.getPoint().getY() - (BALL_RADIUS >> 1) + 0.5), BALL_RADIUS, BALL_RADIUS);

    for (TraceInfo indicatorTraceInfo : this.indicatorTraceInfos) {
        final Point2D point = indicatorTraceInfo.getPoint();
        if (null == point) {
            continue;
        }
        g2.fillOval((int)(point.getX() - (BALL_RADIUS >> 1) + 0.5), (int)(point.getY() - (BALL_RADIUS >> 1) + 0.5), BALL_RADIUS, BALL_RADIUS);
    }

    g2.setColor(oldColor);
    
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias);
    this.drawInformationBox(g2, layer);
}
 
Example 14
Project: ramus   File: PIDEF0painter.java   View Source Code Vote up 5 votes
public void paint(final Graphics2D g, final double x, final double y,
                  final boolean fill, int partNumber, int hPageCount) {
    if (!function.isHaveChilds())
        return;

    final ArrowPainter painter = new ArrowPainter(movingArea);
    final int y1 = movingArea.getIntOrdinate(movingArea.TOP_PART_A);

    final int y2 = movingArea.getIntOrdinate(movingArea.CLIENT_HEIGHT);
    final int height = movingArea.getIntOrdinate(movingArea.BOTTOM_PART_A);
    final int x0 = (int) x + 1;
    final int y0 = (int) y + 1;

    if (fill) {
        final Color c = g.getColor();
        g.setColor(IDEFPanel.DEFAULT_BACKGROUND);
        g.fillRect(x0, y0,
                movingArea.getIntOrdinate(movingArea.MOVING_AREA_WIDTH), y1
                        + y2 + height);
        g.setColor(c);
    }

    g.setStroke(ArrowPainter.THIN_STROKE);
    g.translate(x0, y0);
    g.setColor(Color.BLACK);
    painter.paintTop(
            g// (Graphics2D)g.create(x0,y0,size.width,y1)
            , movingArea.getIntOrdinate(movingArea.TOP_PART_A), movingArea,
            partNumber, hPageCount);
    g.translate(0, y1);
    movingArea.paint(g);// g.create(x0,y0+y1,size.width,y2));

    g.setStroke(ArrowPainter.THIN_STROKE);

    g.translate(0, y2);
    g.setColor(Color.BLACK);
    painter.paintBottom(g, height, movingArea, partNumber, hPageCount);
}
 
Example 15
Project: incubator-netbeans   File: FoldView.java   View Source Code Vote up 4 votes
@Override
public void paint(Graphics2D g, Shape alloc, Rectangle clipBounds) {
    Rectangle2D.Double allocBounds = ViewUtils.shape2Bounds(alloc);
    if (allocBounds.intersects(clipBounds)) {
        Font origFont = g.getFont();
        Color origColor = g.getColor();
        Color origBkColor = g.getBackground();
        Shape origClip = g.getClip();
        try {
            // Leave component font
            
            g.setBackground(getBackgroundColor());

            int xInt = (int) allocBounds.getX();
            int yInt = (int) allocBounds.getY();
            int endXInt = (int) (allocBounds.getX() + allocBounds.getWidth() - 1);
            int endYInt = (int) (allocBounds.getY() + allocBounds.getHeight() - 1);
            g.setColor(getBorderColor());
            g.drawRect(xInt, yInt, endXInt - xInt, endYInt - yInt);
            
            g.setColor(getForegroundColor());
            g.clearRect(xInt + 1, yInt + 1, endXInt - xInt - 1, endYInt - yInt - 1);
            g.clip(alloc);
            TextLayout textLayout = getTextLayout();
            if (textLayout != null) {
                EditorView.Parent parent = (EditorView.Parent) getParent();
                float ascent = parent.getViewRenderContext().getDefaultAscent();
                String desc = fold.getDescription(); // For empty desc a single-space text layout is returned
                float x = (float) (allocBounds.getX() + EXTRA_MARGIN_WIDTH);
                float y = (float) allocBounds.getY();
                if (desc.length() > 0) {
                    
                    textLayout.draw(g, x, y + ascent);
                }
            }
        } finally {
            g.setClip(origClip);
            g.setBackground(origBkColor);
            g.setColor(origColor);
            g.setFont(origFont);
        }
    }
}
 
Example 16
Project: Logisim   File: TransmissionGate.java   View Source Code Vote up 4 votes
private void drawInstance(InstancePainter painter, boolean isGhost) {
	Bounds bds = painter.getBounds();
	Object powerLoc = painter.getAttributeValue(Wiring.ATTR_GATE);
	Direction facing = painter.getAttributeValue(StdAttr.FACING);
	boolean flip = (facing == Direction.SOUTH || facing == Direction.WEST) == (powerLoc == Wiring.GATE_TOP_LEFT);

	int degrees = Direction.WEST.toDegrees() - facing.toDegrees();
	if (flip)
		degrees += 180;
	double radians = Math.toRadians((degrees + 360) % 360);

	Graphics2D g = (Graphics2D) painter.getGraphics().create();
	g.rotate(radians, bds.getX() + 20, bds.getY() + 20);
	g.translate(bds.getX(), bds.getY());
	GraphicsUtil.switchToWidth(g, Wire.WIDTH);

	Color gate0 = g.getColor();
	Color gate1 = gate0;
	Color input = gate0;
	Color output = gate0;
	Color platform = gate0;
	if (!isGhost && painter.getShowState()) {
		gate0 = painter.getPort(GATE0).getColor();
		gate1 = painter.getPort(GATE0).getColor();
		input = painter.getPort(INPUT).getColor();
		output = painter.getPort(OUTPUT).getColor();
		platform = computeOutput(painter).getColor();
	}

	g.setColor(flip ? input : output);
	g.drawLine(0, 20, 11, 20);
	g.drawLine(11, 13, 11, 27);

	g.setColor(flip ? output : input);
	g.drawLine(29, 20, 40, 20);
	g.drawLine(29, 13, 29, 27);

	g.setColor(gate0);
	g.drawLine(20, 35, 20, 40);
	GraphicsUtil.switchToWidth(g, 1);
	g.drawOval(18, 30, 4, 4);
	g.drawLine(10, 30, 30, 30);
	GraphicsUtil.switchToWidth(g, Wire.WIDTH);

	g.setColor(gate1);
	g.drawLine(20, 9, 20, 0);
	GraphicsUtil.switchToWidth(g, 1);
	g.drawLine(10, 10, 30, 10);

	g.setColor(platform);
	g.drawLine(9, 12, 31, 12);
	g.drawLine(9, 28, 31, 28);
	if (flip) { // arrow
		g.drawLine(18, 17, 21, 20);
		g.drawLine(18, 23, 21, 20);
	} else {
		g.drawLine(22, 17, 19, 20);
		g.drawLine(22, 23, 19, 20);
	}

	g.dispose();
}
 
Example 17
Project: freecol   File: Canvas.java   View Source Code Vote up 4 votes
/**
 * {@inheritDoc}
 */
@Override
public void paintComponent(Graphics g) {
    updateSizes();
    Graphics2D g2d = (Graphics2D) g;
    chatDisplay.removeOldMessages();
    Dimension size = getSize();

    if (freeColClient.isMapEditor()) {
        if (hasMap()) {
            mapViewer.displayMap(g2d);
        } else {
            g2d.setColor(Color.BLACK);
            g2d.fillRect(0, 0, size.width, size.height);
        }

    } else if (freeColClient.isInGame() && hasMap()) {
        mapViewer.displayMap(g2d);

        // Grey out the map if it is not my turn (and a multiplayer game).
        if (!freeColClient.currentPlayerIsMyPlayer()) {
            if (greyLayer == null) {
                greyLayer = new GrayLayer(freeColClient);
            }
            if (greyLayer.getParent() == null) {
                add(greyLayer, JLayeredPane.DRAG_LAYER);
            }
            greyLayer.setBounds(0, 0, size.width, size.height);
            greyLayer.setPlayer(freeColClient.getGame().getCurrentPlayer());
        } else {
            if (greyLayer != null && greyLayer.getParent() != null) {
                removeFromCanvas(greyLayer);
            }
        }

        // paint chat display
        chatDisplay.display(g2d, mapViewer.getImageLibrary(), size);

    } else {
        /* main menu */
        // TODO: Check if its right to sometimes have an unfocused map
        //       ingame and end up here after clicking outside map.
        final String bgImageKey = "image.flavor.Canvas.map";
        if (ResourceManager.hasImageResource(bgImageKey)) {
            // Get the background without scaling, to avoid wasting
            // memory needlessly keeping an unbounded number of rescaled
            // versions of the largest image in FreeCol, forever.
            final Image bgImage = ResourceManager.getImage(bgImageKey);
            // Draw background image with scaling.
            g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            g2d.drawImage(bgImage, 0, 0, size.width, size.height, this);
            String versionStr = "v. " + FreeCol.getVersion();
            Font oldFont = g2d.getFont();
            Color oldColor = g2d.getColor();
            Font newFont = oldFont.deriveFont(Font.BOLD);
            TextLayout layout = new TextLayout(versionStr, newFont,
                g2d.getFontRenderContext());
            Rectangle2D bounds = layout.getBounds();
            float x = size.width - (float) bounds.getWidth() - 5;
            float y = size.height - (float) bounds.getHeight();
            g2d.setColor(Color.white);
            layout.draw(g2d, x, y);
            g2d.setFont(oldFont);
            g2d.setColor(oldColor);
        } else {
            g2d.setColor(Color.BLACK);
            g2d.fillRect(0, 0, size.width, size.height);
        }
    }
}
 
Example 18
Project: jmt   File: StatiDrawer.java   View Source Code Vote up 4 votes
public void drawArc(int from, int to, boolean bold, String txt, Graphics2D g2d, Color c) {
	Color oldc = g2d.getColor();
	g2d.setColor(c);
	arrow = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
	double x1, x2, ctrlx, ctrly, y;
	if (bold) {
		g2d.setStroke(strokeB);
	}
	if (from > to) {

		// arc settings
		x2 = to * (4 * STATUS_RAD + 2 * ELEMS_GAP) + START_GAP + STATUS_RAD * 2;//+ ELEMS_GAP;
		x1 = from * (4 * STATUS_RAD + 2 * ELEMS_GAP) + START_GAP;// - ELEMS_GAP;				
		y = (panelH) / 2.0 + STATUS_RAD;
		ctrly = y + STATUS_RAD;

		// arrow settings
		arrow.moveTo((float) x2, (float) y);
		arrow.lineTo((float) x2 + arroww, (float) y);
		arrow.lineTo((float) x2, (float) y + arroww);
		arrow.closePath();
	} else {

		// arc settings
		x1 = from * (4 * STATUS_RAD + 2 * ELEMS_GAP) + START_GAP + STATUS_RAD * 2;//+ ELEMS_GAP;
		x2 = to * (4 * STATUS_RAD + 2 * ELEMS_GAP) + START_GAP;// - ELEMS_GAP;
		y = (panelH - STATUS_RAD * 2) / 2.0;
		ctrly = y - STATUS_RAD;

		// arrow settings
		arrow.moveTo((float) x2, (float) y);
		arrow.lineTo((float) x2 - arroww, (float) y);
		arrow.lineTo((float) x2, (float) y - arroww);
		arrow.closePath();
	}
	ctrlx = (x1 + x2) / 2;

	arc[from][to] = new QuadCurve2D.Double(x1, y, ctrlx, ctrly, x2, y);
	g2d.draw(arc[from][to]);
	g2d.draw(arrow);
	g2d.fill(arrow);
	g2d.setColor(oldc);
	g2d.setStroke(stroke);
}
 
Example 19
Project: javase   File: Sinx.java   View Source Code Vote up 4 votes
@Override  
    public void paint(Graphics g) {  
        super.paint(g);  
        Graphics2D g2d = (Graphics2D) g;  
        Color source = g2d.getColor();  
          
        g2d.setColor(Color.WHITE);  
        g2d.drawString("sinx/x 的图像", 50, 50);  
          
  
        // 画 X 轴  
        g2d.drawLine(INCREMENT, (int)HEIGHT/2, (int)WIDTH-INCREMENT, (int)HEIGHT/2);  
        g2d.drawLine((int)WIDTH-2*INCREMENT, (int)HEIGHT/2-5, (int)WIDTH-10, (int)HEIGHT/2);
        g2d.drawLine((int)WIDTH-2*INCREMENT, (int)HEIGHT/2+5, (int)WIDTH-10, (int)HEIGHT/2);
          
  
        // 画 Y 轴  
        g2d.drawLine((int)WIDTH/2, 40, (int)WIDTH/2, (int)HEIGHT-50);  
        g2d.drawLine((int)WIDTH/2, 40, (int)WIDTH/2-10, 50);  
        g2d.drawLine((int)WIDTH/2, 40, (int)WIDTH/2+10, 50);  
          
        // 将当前画笔移动到中心  
        g2d.translate((int) WIDTH / 2, (int) HEIGHT / 2);  
  
        // 利用GeneralPath类来画曲线  
        GeneralPath gp = new GeneralPath();  
  
        // 将GeneralPath的实例gp的画笔移动到当前画面的中心,但是这个点是相对于g2d画笔的中心的  
        gp.moveTo(0, 0);  
  
        // 画sin(x)/x 的图像  
//      drawSinxDX(gp, g2d);  
  
        // sin(x)的图像  
        drawSinx(gp, g2d);  
     // cos(x)的图像  
      // drawCosx(gp, g2d);  
  
        // tan(x)的图像  
//      drawTanx(gp, g2d);  
        g2d.setColor(source);  
    }
 
Example 20
Project: parabuild-ci   File: MeterNeedle.java   View Source Code Vote up 3 votes
/**
 * Draws the needle.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param rotate  the rotation point.
 * @param angle  the angle.
 */
public void draw(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) {

    Paint savePaint = g2.getColor();
    Stroke saveStroke = g2.getStroke();

    drawNeedle(g2, plotArea, rotate, Math.toRadians(angle));

    g2.setStroke(saveStroke);
    g2.setPaint(savePaint);

}