当前位置: 首页>>代码示例>>Java>>正文


Java Graphics类代码示例

本文整理汇总了Java中java.awt.Graphics的典型用法代码示例。如果您正苦于以下问题:Java Graphics类的具体用法?Java Graphics怎么用?Java Graphics使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Graphics类属于java.awt包,在下文中一共展示了Graphics类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: paintComponent

import java.awt.Graphics; //导入依赖的package包/类
@Override
public void paintComponent(Graphics g) {
	super.paintComponent(g);

	GeneralPath arrow = new GeneralPath();
	int w, h;
	h = (int) (2 * sizeFactor);
	w = (int) (4 * sizeFactor);
	arrow.moveTo(getWidth() / 2 - w, getHeight() / 2);
	arrow.lineTo(getWidth() / 2 + w, getHeight() / 2);
	arrow.lineTo(getWidth() / 2, getHeight() / 2 + 2 * h);
	arrow.closePath();
	if (isEnabled()) {
		g.setColor(Color.BLACK);
	} else {
		g.setColor(Color.GRAY);
	}
	((Graphics2D) g).fill(arrow);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:20,代码来源:DropDownButton.java

示例2: guardedPaint

import java.awt.Graphics; //导入依赖的package包/类
private void guardedPaint(Graphics g) {
    if (firstPaint) {
        firstPaint = false;
        calcRowHeight(g);

        //This will generate a repaint, so don't bother continuing with super.paint()
        //but do paint the background color so it doesn't paint gray the first time
        g.setColor(getBackground());
        g.fillRect(0, 0, getWidth(), getHeight());

        return;
    }

    try {
        ExplorerTree.super.paint(g);
    } catch (NullPointerException ex) {
        // #139696: Making this issue more acceptable by not showing a dialog
        // still it deserves more investigation later
       LOG.log(Level.INFO, "Problems while painting", ex);  // NOI18N
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:TreeView.java

示例3: paintFocus

import java.awt.Graphics; //导入依赖的package包/类
protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect,
                          Rectangle textRect, Rectangle iconRect) {
    Graphics2D g2 = (Graphics2D)g;
    g2.setStroke(FOCUS_STROKE);
    g2.setColor(FOCUS_COLOR);
    g2.drawRect(2, 2, b.getWidth() - 5, b.getHeight() - 5);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:HeaderButton.java

示例4: drawRightBorder

import java.awt.Graphics; //导入依赖的package包/类
/** Draws the InternalFrameBorder's right border.
  */
protected boolean drawRightBorder(Component c, Graphics g, int x, int y,
                              int width, int height) {
    if (super.drawRightBorder(c, g, x, y, width, height) &&
        frame.isResizable()) {
        int startX = width - getBorderInsets(c).right;
        g.setColor(getFrameHighlight());
        int topY = y + CORNER_SIZE;
        g.drawLine(startX, topY, width - 2, topY);
        int bottomY = height - CORNER_SIZE;
        g.drawLine(startX + 1, bottomY, startX + 3, bottomY);
        g.setColor(getFrameShadow());
        g.drawLine(startX + 1, topY - 1, width - 2, topY - 1);
        g.drawLine(startX + 1, bottomY - 1, startX + 3, bottomY - 1);
        return true;
    }
    return false;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:MotifBorders.java

示例5: paintComboBoxBackground

import java.awt.Graphics; //导入依赖的package包/类
public void paintComboBoxBackground(SynthContext context, Graphics g,
                                    int x, int y,
                                    int w, int h) {
    for (SynthPainter painter: painters) {
        painter.paintComboBoxBackground(context, g, x, y, w, h);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:ParsedSynthStyle.java

示例6: render

import java.awt.Graphics; //导入依赖的package包/类
public void render() {
    ImageCapabilities imgBackBufCap = new ImageCapabilities(true);
    ImageCapabilities imgFrontBufCap = new ImageCapabilities(true);
    BufferCapabilities bufCap =
        new BufferCapabilities(imgFrontBufCap,
            imgBackBufCap, BufferCapabilities.FlipContents.COPIED);
    try {

        createBufferStrategy(2, bufCap);
    } catch (AWTException ex) {
        createBufferStrategy(2);
    }

    BufferStrategy bs = getBufferStrategy();
    do {
        Graphics g =  bs.getDrawGraphics();
        g.setColor(Color.green);
        g.fillRect(0, 0, getWidth(), getHeight());

        g.setColor(Color.red);
        g.drawString("Rendering test", 20, 20);

        g.drawImage(bi, 50, 50, null);

        g.dispose();
        bs.show();
    } while (bs.contentsLost()||bs.contentsRestored());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:BufferStrategyExceptionTest.java

示例7: paintOr

import java.awt.Graphics; //导入依赖的package包/类
static void paintOr(InstancePainter painter, int width, int height) {
	Graphics g = painter.getGraphics();
	GraphicsUtil.switchToWidth(g, 2);
	/*
	 * The following, used previous to version 2.5.1, didn't use GeneralPath
	 * g.setColor(Color.LIGHT_GRAY); if (width < 40) {
	 * GraphicsUtil.drawCenteredArc(g, -30, -21, 36, -90, 53);
	 * GraphicsUtil.drawCenteredArc(g, -30, 21, 36, 90, -53); } else if (width < 60)
	 * { GraphicsUtil.drawCenteredArc(g, -50, -37, 62, -90, 53);
	 * GraphicsUtil.drawCenteredArc(g, -50, 37, 62, 90, -53); } else {
	 * GraphicsUtil.drawCenteredArc(g, -70, -50, 85, -90, 53);
	 * GraphicsUtil.drawCenteredArc(g, -70, 50, 85, 90, -53); } paintShield(g,
	 * -width, 0, width, height);
	 */

	GeneralPath path;
	if (width < 40) {
		path = PATH_NARROW;
	} else if (width < 60) {
		path = PATH_MEDIUM;
	} else {
		path = PATH_WIDE;
	}
	((Graphics2D) g).draw(path);
	if (height > width) {
		paintShield(g, 0, width, height);
	}
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:29,代码来源:PainterShaped.java

示例8: getWidth

import java.awt.Graphics; //导入依赖的package包/类
public int getWidth() {
    if (shortName == null || shortName.length() <= 1) {
        return Figure.SLOT_WIDTH;
    } else {
        BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
        Graphics g = image.getGraphics();
        g.setFont(figure.getDiagram().getSlotFont().deriveFont(Font.BOLD));
        FontMetrics metrics = g.getFontMetrics();
        return Math.max(Figure.SLOT_WIDTH, metrics.stringWidth(shortName) + 6);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:Slot.java

示例9: getStationIcon

import java.awt.Graphics; //导入依赖的package包/类
public static Image getStationIcon(String type, Rectangle bounds) {
	BufferedImage bi = new BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_4BYTE_ABGR);
	Graphics g = bi.getGraphics();
	int qLength = bounds.width * 3 / 5, height = bounds.height, width = bounds.width;
	for (int i = 0, monoChannel = 0; i < 5; i++, monoChannel = (int) ((1 - Math.exp(-i)) * 50)) {
		g.setColor(new Color(230 - monoChannel, 230 - monoChannel, 230 - monoChannel, 255));
		g.drawPolyline(new int[] { i, i, qLength - i }, new int[] { height - i, i, i }, 3);
		g.fillArc(width - height + i, i, height - 2 * i, height - 2 * i, 45, 180);
		g.setColor(new Color(130 + monoChannel, 130 + monoChannel, 130 + monoChannel, 255));
		g.drawPolyline(new int[] { i, qLength - i, qLength - i }, new int[] { height - i, height - i, i }, 3);
		g.fillArc(width - height + i, i, height - 2 * i, height - 2 * i, 225, 180);
	}
	g.fillRect(5, 5, qLength - 9, height - 9);
	g.fillOval(width - height + 5, 5, height - 10, height - 10);
	return bi;
}
 
开发者ID:HOMlab,项目名称:QN-ACTR-Release,代码行数:17,代码来源:DefaultIcons.java

示例10: paintText

import java.awt.Graphics; //导入依赖的package包/类
@Override
protected void paintText(Graphics g, int tabPlacement, Font font, FontMetrics metrics, int tabIndex, String title,
	Rectangle textRect, boolean isSelected)
{
	g.setFont(font);

	View v = getTextViewForTab(tabIndex);
	if( v != null )
	{
		// html
		v.paint(g, textRect);
	}
	else
	{
		// plain text
		int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);

		if( tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex) )
		{
			g.setColor(isSelected ? Color.white : Color.black);
			BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, textRect.x,
				textRect.y + metrics.getAscent());
		}
		else
		{ // tab disabled
			g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
			BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, textRect.x,
				textRect.y + metrics.getAscent());
			g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
			BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, textRect.x,
				textRect.y + metrics.getAscent());
		}
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:35,代码来源:FlatterTabbedPaneUI.java

示例11: print

import java.awt.Graphics; //导入依赖的package包/类
public int print(Graphics g, PageFormat fmt, int pageNo) {
	if( pageNo>0 ) return NO_SUCH_PAGE;
	Graphics2D g2 = (Graphics2D)g;
	Dimension dim = wwd.getPreferredSize();
	Rectangle r = wwd.getBounds();

	if(r.width>dim.width) r.width = dim.width;
	if(r.height>dim.height) r.height = dim.height;

	org.geomapapp.util.DateFmt df = new org.geomapapp.util.DateFmt();
	int secs = (int)(System.currentTimeMillis()/1000L);
	String date = df.format(secs);
	Font font = new Font("SansSerif", Font.PLAIN, 8);
	g.setFont( font );
	Rectangle2D r2d = font.getStringBounds(date, g2.getFontRenderContext());
//	g2.translate( r.getWidth()-20.-r2d.getWidth(), r.getHeight()+18. );
	g2.setColor( Color.black);

//	g.setClip( new Rectangle( 0, 0, r.width, r.height) );
	double w = fmt.getImageableWidth();
	double h = fmt.getImageableHeight();
	double x = fmt.getImageableX();
	double y = fmt.getImageableY();
	g2.translate(x, y);
	double scale = Math.min( w / r.getWidth(), h / r.getHeight());
	int xd = (int)(scale*r.getWidth()-10.-r2d.getWidth());
	int yd = (int)(scale*r.getHeight()+18.);
	g2.drawString( date, xd, yd);
	g2.translate( -r.getX()*scale, -r.getY()*scale );
	g2.scale( scale, scale);

	wwd.getContext().makeCurrent();
	BufferedImage image = Screenshot.readToBufferedImage(r.width, r.height);
	g2.drawImage(image, 0, 0, this);
	return PAGE_EXISTS;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:37,代码来源:WWMap.java

示例12: drowLine

import java.awt.Graphics; //导入依赖的package包/类
/**
 * 绘制干扰线
 */
private void drowLine(Graphics g) {
	int x = random.nextInt(width);
	int y = random.nextInt(height);
	int x0 = random.nextInt(16);
	int y0 = random.nextInt(16);
	g.drawLine(x, y, x + x0, y + y0);
}
 
开发者ID:jiangzongyao,项目名称:kettle_support_kettle8.0,代码行数:11,代码来源:Captcha.java

示例13: paintComponent

import java.awt.Graphics; //导入依赖的package包/类
@Override
protected void paintComponent(Graphics graphics) {
    Graphics2D g = Config.getDefault().getGraphics(graphics);

    g.setColor(myBackgroundColor);
    g.fillRect(0, 0, myWidth, myHeight);

    int y = 0;

    for (int i = 0; i < myLines.size(); i++) {
        ComponentLine line = myLines.get(i);
        y += myCorrection[i] + myAscent[i];
        line.draw(g, myMinOffset, y);

        y += myDescent[i] + myLeading[i];
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:ComponentDocument.java

示例14: generate

import java.awt.Graphics; //导入依赖的package包/类
public static BufferedImage generate(int width, int height, String message,
		String fontFamily, Color background, Color foreground) {
	BufferedImage bi = new BufferedImage(width, height,
			BufferedImage.TYPE_INT_ARGB);

	Graphics ig2 = null;

	try {
		ig2 = bi.getGraphics();

		ig2.setColor(background);
		ig2.fillRect(0, 0, width, height);

		int fontSize = new Double(height * 0.5d).intValue();
		Font font = new Font(fontFamily, Font.PLAIN, fontSize);
		Map<TextAttribute, Object> map = new Hashtable<TextAttribute, Object>();
		map.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
		font = font.deriveFont(map);
		ig2.setFont(font);
		ig2.setColor(foreground);
		drawCenteredString(message.toUpperCase(), width, height, ig2);
	} finally {
		if (ig2 != null)
			ig2.dispose();
	}

	return bi;
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:29,代码来源:AvatarGenerator.java

示例15: create

import java.awt.Graphics; //导入依赖的package包/类
/**
 * creates a JFrame and a background Thread managing the rendering and the Frame itself.
 */
public static void create(){
if(!running){
	running = true;
	GFrame = new JFrame();
	GFrame.setVisible(true);
	RefreshWindow();
	RegisterInputDevices();
	BStrategy = GFrame.getBufferStrategy();
	setCurrentscreen(new EmptyScreen());
	PhySIX = new Thread(new Runnable(){
		@Override
		public void run() {
			try {
				while(GFrame.isVisible()){
					Graphics g = BStrategy.getDrawGraphics();
					clearScreen(g);
					updateDHs(g);
					renderDHs(g);
					drawDHs(g);
					drawmodels(g);
					UpdateStrat(g);
					Sync();
				}
			} catch (LessThanZeroException e) {
				e.printStackTrace();
			}
		}
	}, "Display-Loop-Thread.");
	PhySIX.start();
}
}
 
开发者ID:PhentixDevs,项目名称:PhySIX,代码行数:35,代码来源:Display.java


注:本文中的java.awt.Graphics类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。