本文整理汇总了Java中java.awt.Graphics.setColor方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics.setColor方法的具体用法?Java Graphics.setColor怎么用?Java Graphics.setColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Graphics
的用法示例。
在下文中一共展示了Graphics.setColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paint
import java.awt.Graphics; //导入方法依赖的package包/类
@Override public void paint(Graphics graphics) {
graphics.setColor(Color.BLACK);
if(output.isCharged()) {
graphics.drawLine(10, 5, 23, 14);
graphics.drawLine(11, 0, 21, 0);
graphics.drawLine(14, 0, 14, 7);
graphics.drawLine(18, 0, 18, 10);
} else {
graphics.drawLine(10, 23, 23, 14);
graphics.drawLine(11, 10, 21, 10);
graphics.drawLine(14, 10, 14, 20);
graphics.drawLine(18, 10, 18, 17);
}
graphics.drawString("1", 0, 10);
graphics.drawString("0", 0, 28);
ContactUtilities.paintSolderingJoints(graphics, contacts);
}
示例2: paintComponent
import java.awt.Graphics; //导入方法依赖的package包/类
public void paintComponent(Graphics g) {
g.setColor(Color.WHITE);
g.fillRect(0, 0, fpd.width, fpd.height);
g.setColor(Color.RED);
FontRenderContext frc = ((Graphics2D)g).getFontRenderContext();
LineMetrics lm = f.getLineMetrics(fps, frc);
int h = (int)(fpd.height - 20 - lm.getAscent());
g.drawLine(20, h, fpd.width - 20, h);
h = fpd.height - 20;
g.drawLine(20, h, fpd.width - 20, h);
h = (int)(fpd.height - 20 + lm.getDescent());
g.drawLine(20, h, fpd.width - 20, h);
g.setColor(Color.BLACK);
g.setFont(f);
g.drawString(fps, 50, fpd.height - 20);
}
示例3: paintBorder
import java.awt.Graphics; //导入方法依赖的package包/类
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
AbstractButton b = (AbstractButton) c;
ButtonModel model = b.getModel();
Color shade = shadow;
Component p = b.getParent();
if (p != null && p.getBackground().equals(shadow)) {
shade = darkShadow;
}
if ((model.isRollover() && !(model.isPressed() && !model.isArmed())) ||
model.isSelected()) {
Color oldColor = g.getColor();
g.translate(x, y);
if (model.isPressed() && model.isArmed() || model.isSelected()) {
// Draw the pressd button
g.setColor(shade);
g.drawRect(0, 0, w-1, h-1);
g.setColor(lightHighlight);
g.drawLine(w-1, 0, w-1, h-1);
g.drawLine(0, h-1, w-1, h-1);
} else {
// Draw a rollover button
g.setColor(lightHighlight);
g.drawRect(0, 0, w-1, h-1);
g.setColor(shade);
g.drawLine(w-1, 0, w-1, h-1);
g.drawLine(0, h-1, w-1, h-1);
}
g.translate(-x, -y);
g.setColor(oldColor);
}
}
示例4: createOverlayImage
import java.awt.Graphics; //导入方法依赖的package包/类
private void createOverlayImage() {
int height = getBounds().height * 2, width = getBounds().width * 2, qLength = width - (height * 4) / 5, qHeight = (height * 4) / 5, yOffs = (height - qHeight) / 2;
overlayedShading = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
Color[] shades = new Color[7], lights = new Color[7];
for (int i = 0; i < shades.length; i++) {
shades[i] = new Color(0, 0, 0, 160 - (i * 160) / shades.length);
lights[i] = new Color(255, 255, 255, 200 - (i * 200) / lights.length);
}
Graphics g = overlayedShading.getGraphics();
for (int i = 0; i < shades.length; i++) {
g.setColor(lights[i]);
g.drawPolyline(new int[] { i, i, qLength - i }, new int[] { height - i - yOffs, i + yOffs, i + yOffs }, 3);
g.drawArc(width - height + i, i, height - 2 * i, height - 2 * i, 45 + 4 * i, 180 - 8 * i);
g.setColor(shades[i]);
g.drawPolyline(new int[] { i, qLength - i, qLength - i }, new int[] { height - i - yOffs, height - i - yOffs, i + yOffs }, 2);
g.drawArc(width - height + i, i, height - 2 * i, height - 2 * i, 225 + 4 * i, 180 - 8 * i);
}
overlayedShading = overlayedShading.getScaledInstance(getBounds().width, getBounds().height, Image.SCALE_SMOOTH);
}
示例5: paintCaret
import java.awt.Graphics; //导入方法依赖的package包/类
protected void paintCaret(Graphics gfx, int line, int y) {
if (textArea.isCaretVisible()) {
int offset = textArea.getCaretPosition() - textArea.getLineStartOffset(line);
int caretX = textArea._offsetToX(line, offset);
int caretWidth = ((blockCaret || textArea.isOverwriteEnabled()) ? fm.charWidth('w') : 1);
y += fm.getLeading() + fm.getMaxDescent();
int height = fm.getHeight();
gfx.setColor(caretColor);
if (textArea.isOverwriteEnabled()) {
gfx.fillRect(caretX, y + height - 1, caretWidth, 1);
} else {
gfx.drawRect(caretX, y, caretWidth - 1, height - 1);
}
}
}
示例6: genRandomCodeImage
import java.awt.Graphics; //导入方法依赖的package包/类
/**
* 生成随机图片
*/
public BufferedImage genRandomCodeImage(StringBuffer randomCode) {
// BufferedImage类是具有缓冲区的Image类
BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_BGR);
// 获取Graphics对象,便于对图像进行各种绘制操作
Graphics g = image.getGraphics();
// 设置背景色
// g.setColor(getRandColor(200, 250));
g.fillRect(0, 0, width, height);
// 设置干扰线的颜色
g.setColor(getRandColor(110, 133));
// 绘制干扰线
for (int i = 0; i <= lineNum; i++) {
drowLine(g);
}
// 绘制随机字符
g.setFont(getRandomFont());
for (int i = 1; i <= strNum; i++) {
randomCode.append(drowString(g, i));
}
g.dispose();
return image;
}
示例7: draw
import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void draw(Graphics g) {
Value v = canvas.getCircuitState().getValue(wire.getEnd0());
RadixOption radix1 = RadixOption.decode(AppPreferences.POKE_WIRE_RADIX1.get());
RadixOption radix2 = RadixOption.decode(AppPreferences.POKE_WIRE_RADIX2.get());
if (radix1 == null)
radix1 = RadixOption.RADIX_2;
String vStr = radix1.toString(v);
if (radix2 != null && v.getWidth() > 1) {
vStr += " / " + radix2.toString(v);
}
FontMetrics fm = g.getFontMetrics();
g.setColor(caretColor);
g.fillRect(x + 2, y + 2, fm.stringWidth(vStr) + 4, fm.getAscent() + fm.getDescent() + 4);
g.setColor(Color.BLACK);
g.drawRect(x + 2, y + 2, fm.stringWidth(vStr) + 4, fm.getAscent() + fm.getDescent() + 4);
g.fillOval(x - 2, y - 2, 5, 5);
g.drawString(vStr, x + 4, y + 4 + fm.getAscent());
}
示例8: render
import java.awt.Graphics; //导入方法依赖的package包/类
public void render() {
//creates place for image to be rendered behind screen then shown
BufferStrategy bs = getBufferStrategy();
if (bs == null) {
createBufferStrategy(3); //3 "screens"
return;
}
screen.clear();
int xScroll = player.x - screen.width / 2;
int yScroll = player.y - screen.height / 2;
level.render(xScroll, yScroll, screen);
player.render(screen);
for (int i = 0; i < pixels.length; i++) {
pixels[i] = screen.pixels[i];
}
Graphics g = bs.getDrawGraphics(); //linking buffer with graphics
g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
g.setColor(Color.WHITE);
g.setFont(new Font("Verdena", 0, 20));
g.drawString("X: " + (player.x >> 4) + ", Y: " + (player.y >> 4), 0, 16);
g.dispose(); //remove graphics that are not used
bs.show(); //swapping out the buffers
}
示例9: paint
import java.awt.Graphics; //导入方法依赖的package包/类
@Override public void paint(Graphics graphics) {
graphics.setColor(Color.BLACK);
((Graphics2D)graphics).draw(shape);
graphics.setFont(graphics.getFont().deriveFont(10f));
graphics.drawString("Register", 20, 30);
graphics.setFont(graphics.getFont().deriveFont(8f));
for(int output=0;output<outputs.getContactsCount();output++) {
int top = 40+output*20;
graphics.drawRect(5, top, size.width-10, 20);
graphics.drawString("+", size.width-12, top+13);
}
}
示例10: PaintFlightLog
import java.awt.Graphics; //导入方法依赖的package包/类
private void PaintFlightLog(Graphics g)
{
int paintsCount = -1;
int textSize = 0;
for(int i = 0; i < window.paintText.size(); i++)
for(int k = 0; k < window.paintText.get(i).split("\n").length; k++)
textSize++;
g.clearRect(0, 0, window.button_abort.getBounds().x-1, getHeight());
for(int i = 0; i < window.paintText.size(); i++)
{
String text = window.paintText.get(i);
if(text.substring(0, 5).equals("ALERT")) g.setColor(Color.RED);
String[] texts = text.split("\n");
for(int k = 0; k < texts.length; k++)
{
paintsCount++;
g.drawString(texts[k], window.paintStartPos.width, getHeight() - (window.paintStartPos.height + window.paintDistance*(textSize -paintsCount)));
}
g.setColor(Color.BLACK);
}
}
示例11: paintComponent
import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g) {
int w =getWidth();
int h = getHeight();
for (int x=0;x<w; x+=8) {
for (int y=0;y<h; y+=8) {
g.setColor((((x>>3)+(y>>3))%2==0)?Color.white:Color.gray);
g.fillRect(x,y,8,8);
}
}
g.setColor(getBackground());
g.fillRect(0,0,w,h);
}
示例12: paint
import java.awt.Graphics; //导入方法依赖的package包/类
public void paint(Graphics g) {
assertSetup();
if (!isselected) {
g.drawImage(image, 0, 0, tabPanel);
if (imageMask != null) {
g.drawImage(imageMask, 0, 0, tabPanel);
//g.setColor(new Color(100,100,100));
//g.drawLine(0, image.getHeight(tabPanel)-1, 0, 0);
//g.drawLine(0,0,image.getWidth(tabPanel)-1,0);
//g.drawLine(image.getWidth(tabPanel)-1, 0,
// image.getWidth(tabPanel)-1, image.getHeight(tabPanel)-1);
}
g.setColor(Color.black);
g.drawLine(0, image.getHeight(tabPanel) - 1, image
.getWidth(tabPanel), image.getHeight(tabPanel) - 1);
} else {
g.drawImage(image, 0, 0, tabPanel);
g.drawImage(selectedImageMask, 0, 0, tabPanel);
if (customFlag) {
//g.drawLine(0, image.getHeight(tabPanel)-1, 0, 0);
//g.drawLine(0,0,image.getWidth(tabPanel)-1,0);
//g.drawLine(image.getWidth(tabPanel)-1, 0,
// image.getWidth(tabPanel)-1, image.getHeight(tabPanel)-1);
}
}
g.drawString(text, advance, 30);
}
示例13: ScreenRegionGrab
import java.awt.Graphics; //导入方法依赖的package包/类
public ScreenRegionGrab(int n)
{
super("");
num = n;
setUndecorated(true);
setSize(BUBBLE_RADIUS*2+1,BUBBLE_RADIUS*2+1);
jp = new JPanel(){
private static final long serialVersionUID = 1L;
public void paintComponent(Graphics g) {
g.setColor(new Color(1,1,1,1));
g.fillOval(0,0,BUBBLE_RADIUS*2,BUBBLE_RADIUS*2);
g.setColor(Color.RED);
g.drawOval(0,0,BUBBLE_RADIUS*2,BUBBLE_RADIUS*2);
}
};
setBackground(new Color(0, 0, 0, 0));
setContentPane(jp);
setLocationRelativeTo(null);
setVisible(true);
t = new Timer(10, this);
t.start();
addMouseListener(this);
if(num==1)
{
win1 = this;
}
else
{
win2 = this;
}
this.setAlwaysOnTop(true);
}
示例14: paintComponent
import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g) {
g.setColor(Color.black);
g.fillRect(0, 0, getWidth(), getHeight());
if (img != null) {
g.drawImage(img, (getWidth() - img.getWidth()) / 2, (getHeight() - img.getHeight()) / 2, this);
}
}
示例15: drawTiledImage
import java.awt.Graphics; //导入方法依赖的package包/类
/**
* Draw a (usually small) background image into a (usually larger)
* space specified by a component, tiling the image to fill up the
* space. If the image is not available, just fill with the background
* colour.
*
* @param resource The name of the {@code ImageResource} to tile with.
* @param g The {@code Graphics} to draw to.
* @param c The {@code JComponent} that defines the space.
* @param insets Optional {@code Insets} to apply.
*/
public static void drawTiledImage(String resource, Graphics g,
JComponent c, Insets insets) {
int width = c.getWidth();
int height = c.getHeight();
int xmin, ymin;
if (insets == null) {
xmin = 0;
ymin = 0;
} else {
xmin = insets.left;
ymin = insets.top;
width -= insets.left + insets.right;
height -= insets.top + insets.bottom;
}
if (ResourceManager.hasImageResource(resource)) {
BufferedImage image = ResourceManager.getImage(resource);
// FIXME: Test and profile if calling fillTexture is better.
int dx = image.getWidth();
int dy = image.getHeight();
int xmax = xmin + width;
int ymax = ymin + height;
for (int x = xmin; x < xmax; x += dx) {
for (int y = ymin; y < ymax; y += dy) {
g.drawImage(image, x, y, null);
}
}
} else {
g.setColor(c.getBackground());
g.fillRect(xmin, ymin, width, height);
}
}