Java Code Examples for java.awt.Graphics.setColor()

The following are Jave code examples for showing how to use setColor() of the java.awt.Graphics 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: JDigitalSimulator   File: PushSwitch.java   View Source Code Vote up 7 votes
@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);
}
 
Example 2
Project: openjdk-jdk10   File: UnderlineTest.java   View Source Code Vote up 7 votes
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);
}
 
Example 3
Project: OpenJSharp   File: BasicBorders.java   View Source Code Vote up 6 votes
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);
    }
}
 
Example 4
Project: jmt   File: SampleQNAnimation.java   View Source Code Vote up 6 votes
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);
}
 
Example 5
Project: rapidminer   File: TextAreaPainter.java   View Source Code Vote up 6 votes
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);
		}
	}
}
 
Example 6
Project: kettle_support_kettle8.0   File: Captcha.java   View Source Code Vote up 6 votes
/**
 * 生成随机图片
 */
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;
}
 
Example 7
Project: Logisim   File: PokeTool.java   View Source Code Vote up 6 votes
@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());
}
 
Example 8
Project: KingdomKing   File: Game.java   View Source Code Vote up 6 votes
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
}
 
Example 9
Project: JDigitalSimulator   File: Register.java   View Source Code Vote up 5 votes
@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);
	}
}
 
Example 10
Project: New-Kepard   File: JWindow.java   View Source Code Vote up 5 votes
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);
	}
}
 
Example 11
Project: DicomViewer   File: SVColorPreviewPanel.java   View Source Code Vote up 5 votes
@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);
}
 
Example 12
Project: myster   File: Tab.java   View Source Code Vote up 5 votes
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);
    }
 
Example 13
Project: MTG-Card-Recognizer   File: ScreenRegionGrab.java   View Source Code Vote up 5 votes
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);
}
 
Example 14
Project: DicomViewer   File: CLEditor.java   View Source Code Vote up 5 votes
@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);
    }
}
 
Example 15
Project: FreeCol   File: ImageLibrary.java   View Source Code Vote up 5 votes
/**
 * 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);
    }
}
 
Example 16
Project: OpenDA   File: PlotBox.java   View Source Code Vote up 5 votes
private int _drawLegend(Graphics graphics, int urx, int ury) {
    // Ignore if there is no graphics object to draw on.
    if (graphics == null) return 0;

    // FIXME: consolidate all these for efficiency
    Font previousFont = graphics.getFont();
    graphics.setFont(_labelFont);
    int spacing = _labelFontMetrics.getHeight();

    Enumeration v = _legendStrings.elements();
    Enumeration i = _legendDatasets.elements();
    int ypos = ury + spacing;
    int maxwidth = 0;
    while (v.hasMoreElements()) {
        String legend = (String) v.nextElement();
        // NOTE: relies on _legendDatasets having the same num. of entries.
        int dataset = ((Integer) i.nextElement()).intValue();
        if (dataset >= 0) {
            if (_usecolor) {
                // Points are only distinguished up to the number of colors
                int color = dataset % _colors.length;
                graphics.setColor(_colors[color]);
            }
            _drawPoint(graphics, dataset, urx-3, ypos-3, false);

            graphics.setColor(_foreground);
            int width = _labelFontMetrics.stringWidth(legend);
            if (width > maxwidth) maxwidth = width;
            graphics.drawString(legend, urx - 15 - width, ypos);
            ypos += spacing;
        }
    }
    graphics.setFont(previousFont);
    return 22 + maxwidth;  // NOTE: subjective spacing parameter.
}
 
Example 17
Project: OpenJSharp   File: MetalBorders.java   View Source Code Vote up 5 votes
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
    g.translate( x, y );

    g.setColor( MetalLookAndFeel.getControlDarkShadow() );
    g.drawLine( w-1, 0, w-1, h-1 );
    g.drawLine( 1, h-1, w-1, h-1 );
    g.setColor( MetalLookAndFeel.getControlHighlight() );
    g.drawLine( 0, 0, w-2, 0 );
    g.drawLine( 0, 0, 0, h-2 );

    g.translate( -x, -y );
}
 
Example 18
Project: Jasovacs_fire   File: EvacuationGUI.java   View Source Code Vote up 4 votes
private void draw_danger(Graphics g, int x, int y) {
	g.setColor(Color.RED);
	g.fillOval(x*cellSizeW+cellSizeW/8, y*cellSizeH+cellSizeH/8, cellSizeW-cellSizeW/4, cellSizeH-cellSizeH/4);
	
}
 
Example 19
Project: incubator-netbeans   File: AbstractWinEditorTabDisplayerUI.java   View Source Code Vote up 4 votes
@Override
public void paintBackground (Graphics g) {
    g.setColor (displayer.getBackground());
    g.fillRect (0, 0, displayer.getWidth(), displayer.getHeight());
}
 
Example 20
Project: etomica   File: DisplayBoxCanvas1D.java   View Source Code Vote up 4 votes
/**
    * doPaint is the method that handles the drawing of the box to the screen.
    * Several variables and conditions affect how the image is drawn.  First,
    * the Unit.Length.Sim class variable <code>TO_PIXELS</code> performs the conversion between simulation
    * length units (Angstroms) and pixels.  The default value is 10 pixels/Angstrom
    * reflecting the default size of the box (300 pixels by 300 pixels) and the
    * default box size (30 by 30 A).  
    * The field <code>scale</code> is a multiplicative factor that directly
    * scales up or down the size of the image; this value is adjusted automatically
    * whenever shells of periodic images are drawn, to permit the central image and all 
    * of the specified periodic images to fit in the drawing of the box.  
    *
    * @param g The graphic object to which the image of the box is drawn
    */
    public void doPaint(Graphics g) {
        if(!isVisible() || displayBox.getBox() == null) {return;}
        int w = getSize().width;
        int h = getSize().height;
            
        g.setColor(getBackground());
        g.fillRect(0,0,w,h);
        displayBox.computeImageParameters2(w, h);

        //Draw other features if indicated
//        if(drawBoundary>DRAW_BOUNDARY_NONE) {displayBox.getBox().boundary().draw(g, displayBox.getOrigin(), displayBox.getScale());}
//        if(displayBox.getDrawBoundary()) {displayBox.getBox().boundary().draw(g, displayBox.getOrigin(), displayBox.getScale());}

        //do drawing of all drawing objects that have been added to the display
        for(Iterator iter=displayBox.getDrawables().iterator(); iter.hasNext(); ) {
            Drawable obj = (Drawable)iter.next();
            obj.draw(g, displayBox.getOrigin(), displayBox.getToPixels());
        }
           
        int [] origin = displayBox.getOrigin();
        atomOrigin[0] =origin[0] + (int)(0.5*displayBox.getToPixels()*displayBox.getBox().getBoundary().getBoxSize().getX(0));
        atomOrigin[1] =origin[1];
        
        //Draw all atoms
        if(displayBox.getColorScheme() instanceof ColorSchemeCollective) {
            ((ColorSchemeCollective)displayBox.getColorScheme()).colorAllAtoms();
        }
        IAtomList leafList = displayBox.getBox().getLeafList();
        int nLeaf = leafList.getAtomCount();
        AtomFilter atomFilter = displayBox.getAtomFilter();
        if (atomFilter instanceof AtomFilterCollective) {
            ((AtomFilterCollective)atomFilter).resetFilter();
        }
        for (int iLeaf=0; iLeaf<nLeaf; iLeaf++) {
            IAtom a = leafList.getAtom(iLeaf);
            if(atomFilter != null && atomFilter.test(a)) continue;
            drawAtom(g, atomOrigin, a);
        }
            
        //Draw overflow images if so indicated
        //This needs some work to make more general
///        for(Atom a=displayBox.getBox().firstAtom(); a!=null; a=a.nextAtom()) {
///            if(computeShiftOrigin(a, boundary)) {
///                drawAtom(g, shiftOrigin, a);
///            }
///        }

        //Draw periodic images if indicated ONLY for an etomica Boundary
        if(displayBox.getBox().getBoundary() instanceof Boundary) {
	        if(displayBox.getImageShells() > 0) {
	            double[][] origins = ((Boundary)displayBox.getBox().getBoundary()).imageOrigins(displayBox.getImageShells());  //more efficient to save rather than recompute each time
	            for(int i=0; i<origins.length; i++) {
	                g.copyArea(displayBox.getOrigin()[0],displayBox.getOrigin()[1],displayBox.getDrawSize()[0],displayBox.getDrawSize()[1],(int)(displayBox.getToPixels()*origins[i][0]),(int)(displayBox.getToPixels()*origins[i][1]));
	            }
	        }
        }
        //Draw bar showing scale if indicated
        if(writeScale) {
            g.setColor(Color.lightGray);
            g.fillRect(0,getSize().height-annotationHeight,getSize().width,annotationHeight);
            g.setColor(Color.black);
            g.setFont(font);
            g.drawString("Scale: "+Integer.toString((int)(100*displayBox.getScale()))+"%", 0, getSize().height-3);
        }
    }