本文整理汇总了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);
}
示例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
}
}
示例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);
}
示例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;
}
示例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);
}
}
示例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());
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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());
}
}
}
示例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;
}
示例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);
}
示例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];
}
}
示例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;
}
示例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();
}
}