java.awt.Color Java Examples

The following examples show how to use java.awt.Color. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MultiFrequencyDistributionHistogram.java    From systemsgenetics with GNU General Public License v3.0 8 votes vote down vote up
private void determineColor(int i) {
    Color[] colors = {
        new Color(0, 0, 0, 128),
        new Color(128, 128, 128, 128),
        new Color(192, 192, 192, 64),
        new Color(0, 0, 255, 128),
        new Color(255, 255, 0, 128),
        new Color(0, 255, 255, 128),
        new Color(255, 0, 255, 128),};

    while (i > colors.length - 1) {
        i -= colors.length - 1;
    }

    setColor(colors[i]);

}
 
Example #2
Source File: ThemePackagePresets.java    From JCommunique with MIT License 6 votes vote down vote up
public static ThemePackage cleanDark() {
	ThemePackage pack = new ThemePackage();

	WindowTheme window = new WindowTheme();
	window.background = new Color(0, 0, 0);
	window.foreground = new Color(16, 124, 162);
	window.opacity = 0.8f;
	window.width = 300;
	window.height = 100;

	TextTheme text = new TextTheme();
	text.title = new Font("Arial", Font.BOLD, 22);
	text.subtitle = new Font("Arial", Font.PLAIN, 16);
	text.titleColor = new Color(200, 200, 200);
	text.subtitleColor = new Color(200, 200, 200);

	pack.setTheme(WindowTheme.class, window);
	pack.setTheme(TextTheme.class, text);

	return pack;
}
 
Example #3
Source File: ColorPane.java    From patchwork-patcher with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void append(Color color, String string) {
	if (color != null) {
		StyleConstants.setForeground(oneStyleToRuleThemAll, color);
	}

	try {
		this.getDocument().insertString(this.getDocument().getLength(), string, oneStyleToRuleThemAll);
	} catch (BadLocationException e) {
		PatchworkUI.LOGGER.throwing(Level.ERROR, e);
	}
}
 
Example #4
Source File: Test6849805.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    Minimbus laf = new Minimbus();
    laf.test(Color.WHITE, Color.BLACK, 0f);
    laf.test(Color.WHITE, Color.BLACK, 1f);
    laf.test(Color.BLACK, Color.WHITE, 0f);
    laf.test(Color.BLACK, Color.WHITE, 1f);
    laf.test(Color.RED, Color.GREEN, 0f);
    laf.test(Color.RED, Color.GREEN, 1f);
    laf.test(new Color(127, 127, 127), new Color(51, 151, 212), 0f);
    laf.test(new Color(127, 127, 127), new Color(51, 151, 212), 1f);
    laf.test(new Color(221, 63, 189), new Color(112, 200, 89), 0f);
    laf.test(new Color(221, 63, 189), new Color(112, 200, 89), 1f);

    if (! pass) {
        throw new RuntimeException("Some testcases failed, see above");
    }
}
 
Example #5
Source File: GeometryDrawer.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * The inherited drawing method. Applies the rotation, translation and scaling declared in the draw statement,
 * computes a number of properties attached to the geometry object, and calls the main drawing method
 */
@Override
protected final void _draw(final GeometryObject object) {
	gl.pushMatrix();
	try {

		applyRotation(object);
		applyTranslation(object);
		applyScaling(object);
		final boolean solid = object.isFilled() || gl.isTextured();
		final Color border = !solid && object.getAttributes().getBorder() == null
				? object.getAttributes().getColor() : object.getAttributes().getBorder();
		final Geometry geometry = object.getObject();
		final double height = object.getAttributes().getHeight() == null ? 0d : object.getAttributes().getHeight();
		final IShape.Type type = object.getAttributes().getType();
		drawGeometry(geometry, solid, border, height, type);
	} finally {
		gl.popMatrix();
	}
}
 
Example #6
Source File: MotifIconFactory.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
public void drawCheckBezelOut(Graphics g, int x, int y, int csize){
    Color controlShadow = UIManager.getColor("controlShadow");

    int w = csize;
    int h = csize;
    Color oldColor = g.getColor();

    g.translate(x,y);
    g.setColor(highlight);    // inner 3D border
    g.drawLine(0, 0, 0, h-1);
    g.drawLine(1, 0, w-1, 0);

    g.setColor(shadow);         // black drop shadow  __|
    g.drawLine(1, h-1, w-1, h-1);
    g.drawLine(w-1, h-1, w-1, 1);
    g.translate(-x,-y);
    g.setColor(oldColor);
}
 
Example #7
Source File: DisplayChangeVITest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
void render(Graphics g) {
    do {
        // volatile images validated here
        initBackbuffer();

        g.setColor(Color.black);
        g.fillRect(0, 0, getWidth(), getHeight());

        Graphics gg = bb.getGraphics();
        gg.setColor(new Color(rnd.nextInt(0x00ffffff)));
        gg.fillRect(0, 0, bb.getWidth(), bb.getHeight());
        for (int x = 0; x < 10; x++) {
            gg.drawImage(sprite, x*200, 0, null);
            gg.drawImage(volSprite, x*200, 500, null);
        }

        g.drawImage(bb, 0, 0, null);
    } while (bb.contentsLost());
}
 
Example #8
Source File: NimbusStyle.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>Overridden to cause this style to populate itself with data from
 * UIDefaults, if necessary.</p>
 *
 * <p>In addition, NimbusStyle handles ColorTypes slightly differently from
 * Synth.</p>
 * <ul>
 *  <li>ColorType.BACKGROUND will equate to the color stored in UIDefaults
 *      named "background".</li>
 *  <li>ColorType.TEXT_BACKGROUND will equate to the color stored in
 *      UIDefaults named "textBackground".</li>
 *  <li>ColorType.FOREGROUND will equate to the color stored in UIDefaults
 *      named "textForeground".</li>
 *  <li>ColorType.TEXT_FOREGROUND will equate to the color stored in
 *      UIDefaults named "textForeground".</li>
 * </ul>
 */
@Override protected Color getColorForState(SynthContext ctx, ColorType type) {
    String key = null;
    if (type == ColorType.BACKGROUND) {
        key = "background";
    } else if (type == ColorType.FOREGROUND) {
        //map FOREGROUND as TEXT_FOREGROUND
        key = "textForeground";
    } else if (type == ColorType.TEXT_BACKGROUND) {
        key = "textBackground";
    } else if (type == ColorType.TEXT_FOREGROUND) {
        key = "textForeground";
    } else if (type == ColorType.FOCUS) {
        key = "focus";
    } else if (type != null) {
        key = type.toString();
    } else {
        return DEFAULT_COLOR;
    }
    Color c = (Color) get(ctx, key);
    //if all else fails, return a default color (which is a ColorUIResource)
    if (c == null) c = DEFAULT_COLOR;
    return c;
}
 
Example #9
Source File: VTDualListingHighlightProvider.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a darker shade of the color passed-in, based on the given amount.
 * 
 * algorithm: 1) grab individual rgb elements
 *            2) multiply each by a factor.
 *            
 *            ie: int newRed = (int)(oldRed * 0.85);
 * 
 * @param color the color to shade
 * @param amount number between 0..1 (the smaller the number, the darker the shade)
 * @return
 */
private static Color shade(Color color, double amount) {
	if (color != null) {
	
		int r = color.getRed();
		int g = color.getGreen();
		int b = color.getBlue();
		
		double newR = (r * amount);
		double newG = (g * amount);
		double newB = (b * amount);
		
		return new Color((int)newR, (int)newG, (int)newB);
	}
	
	return null;
}
 
Example #10
Source File: MyCursor.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override public void paint(Graphics gr) {
    gr.setColor(Color.GREEN);
    ((Graphics2D)gr).setStroke(new BasicStroke(3));

    gr.drawLine(0, 0, width, height);
    gr.drawLine(0, 0, width/2, 0);
    gr.drawLine(0, 0, 0, height/2);
}
 
Example #11
Source File: ColorChooserPanel.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void updateChooser() {
    Color color = getColorFromModel();
    if (color != null) {
        this.panel.setColor(color);
        this.text.setValue(Integer.valueOf(color.getRGB()));
        this.slider.repaint();
        this.diagram.repaint();
    }
}
 
Example #12
Source File: ColorPalette.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Returns Color by mapping a given value to a common log palette.
     *
     * @param value  the value.
     *
     * @return The color.
     */
    public Color getColorLog(double value) {
        int izV;
        double minZtmp = this.minZ;
        double maxZtmp = this.maxZ;
        if (this.minZ <= 0.0) {
//          negatives = true;
            this.maxZ = maxZtmp - minZtmp + 1;
            this.minZ = 1;
            value = value - minZtmp + 1;
        }
        double minZlog = Math.log(this.minZ) / log10;
        double maxZlog = Math.log(this.maxZ) / log10;
        value = Math.log(value) / log10;
        //  value = Math.pow(10,value);
        if (this.stepped) {
            int numSteps = this.tickValues.length;
            int steps = 256 / (numSteps - 1);
            izV = steps * (int) (numSteps * (value - minZlog)
                    / (maxZlog - minZlog)) + 2;
            //  izV = steps*numSteps*(int)((value/minZ)/(maxZlog-minZlog)) + 2;
        }
        else {
            izV = (int) (253 * (value - minZlog) / (maxZlog - minZlog)) + 2;
        }
        izV = Math.min(izV, 255);
        izV = Math.max(izV, 2);

        this.minZ = minZtmp;
        this.maxZ = maxZtmp;

        return getColor(izV);
    }
 
Example #13
Source File: HexMap.java    From Rails with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void paintImage(Graphics2D g) {
    try {
        // Abort if called too early.
        Rectangle rectClip = g.getClipBounds();
        if (rectClip == null) {
            return;
        }

        // paint train paths
        if (hexMap.getTrainPaths() != null) {
            Stroke oldStroke = g.getStroke();
            Color oldColor = g.getColor();
            Stroke trainStroke =
                    new BasicStroke((int) (STROKE_WIDTH * hexMap.getZoomFactor()),
                            STROKE_CAP, STROKE_JOIN);
            g.setStroke(trainStroke);

            Color[] trainColors =
                    new Color[] { colour1, colour2, colour3, colour4 };
            int color = 0;
            for (GeneralPath path:hexMap.getTrainPaths()) {
                g.setColor(trainColors[color++ % trainColors.length]);
                g.draw(path);
            }
            g.setStroke(oldStroke);
            g.setColor(oldColor);
        }
    } catch (NullPointerException ex) {
        // If we try to paint before something is loaded, just retry
        // later.
        log.debug("Premature call to RoutesLayer.paintImage(Graphics g)");
    }
}
 
Example #14
Source File: SurfaceDataProxy.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isSupportedOperation(SurfaceData srcData,
                                    int txtype,
                                    CompositeType comp,
                                    Color bgColor)
{
    return false;
}
 
Example #15
Source File: ColorMapper.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts a double to a color.
 * @param value
 * @return the color
 */
public Color doubleToColor(double value) { // Changed by Paco to use doubleToIndex
  int index = doubleToIndex(value);
  if(index<0) return floorColor;
  if(index>=colors.length) return ceilColor;
  return colors[index];
}
 
Example #16
Source File: InfiniteValidationLoopTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void runTest(Graphics g) {
    int status = IMAGE_OK;
    int count1 = 0;
    do {
        GraphicsConfiguration gc = getGraphicsConfiguration();
        int count2 = 0;
        while (vi == null || (status = vi.validate(gc)) != IMAGE_OK) {
            if (++count2 > LOOP_THRESHOLD) {
                System.err.println("Infinite loop detected: count2="+count2);
                failed = true;
                return;
            }
            if (vi == null || status == IMAGE_INCOMPATIBLE) {
                if (vi != null) { vi.flush(); vi = null; }
                vi = gc.createCompatibleVolatileImage(100, 100);
                continue;
            }
            if (status == IMAGE_RESTORED) {
                Graphics gg = vi.getGraphics();
                gg.setColor(Color.green);
                gg.fillRect(0, 0, vi.getWidth(), vi.getHeight());
                break;
            }
        }
        g.drawImage(vi, getInsets().left, getInsets().top, null);
        if (++count1 > LOOP_THRESHOLD) {
            System.err.println("Infinite loop detected: count1="+count1);
            failed = true;
            return;
        }
    } while (vi.contentsLost());
}
 
Example #17
Source File: BlockBorderTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    BlockBorder b1 = new BlockBorder(new RectangleInsets(1.0, 2.0, 3.0,
            4.0), new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
            Color.yellow));
    BlockBorder b2 = (BlockBorder) TestUtilities.serialised(b1);
    assertEquals(b1, b2);
}
 
Example #18
Source File: Test6978482.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Component c = new Component() {};
    c.setBackground(Color.WHITE);
    c.setForeground(Color.BLACK);
    Graphics g = new BufferedImage(1024, 768, BufferedImage.TYPE_INT_RGB).getGraphics();
    g.setClip(0, 0, 1024, 768);
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        border.getBorderInsets(c);
        border.paintBorder(c, g, 0, 0, 1024, 768);
    }
}
 
Example #19
Source File: DataDetails.java    From chipster with MIT License 5 votes vote down vote up
public void focusGained(FocusEvent e) {
	if (e.getComponent() == notesField) {
		setNotesActive(true);
		// user starts writing notes, so remove "please add notes" if needed
		if (PLEASE_ADD_NOTES.equals(notesField.getText())) {
			notesField.setSelectionStart(0);
			notesField.setSelectionEnd(notesField.getText().length());
			notesField.setBorder(new LineBorder(Color.gray));
		}
	} else if (e.getComponent() == titleField) {
		setTitleActive(true);
	}
}
 
Example #20
Source File: MinMaxCategoryRenderer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Provides serialization support.
 *
 * @param stream  the input stream.
 *
 * @throws IOException  if there is an I/O error.
 * @throws ClassNotFoundException  if there is a classpath problem.
 */
private void readObject(ObjectInputStream stream)
    throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    this.groupStroke = SerialUtilities.readStroke(stream);
    this.groupPaint = SerialUtilities.readPaint(stream);

    this.minIcon = getIcon(new Arc2D.Double(-4, -4, 8, 8, 0, 360,
            Arc2D.OPEN), null, Color.black);
    this.maxIcon = getIcon(new Arc2D.Double(-4, -4, 8, 8, 0, 360,
            Arc2D.OPEN), null, Color.black);
    this.objectIcon = getIcon(new Line2D.Double(-4, 0, 4, 0), false, true);
}
 
Example #21
Source File: PPTXCanvas.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void setProperty( Color color, int width, int style )
{
	//module for outline line style
	writer.openTag( "a:ln" );
	writer.attribute( "w", width );
	if(style == org.eclipse.birt.report.engine.nLayout.area.style.BorderInfo.BORDER_STYLE_DOUBLE){
		writer.attribute( "cmpd", "dbl" );
	}
	setBackgroundColor( color );

	// the other line styles, e.g. 'ridge', 'outset', 'groove', 'insert'
	// is NOT supported now and all regarded with default style, i.e, solid.
	switch(style)
	{
		case org.eclipse.birt.report.engine.nLayout.area.style.BorderInfo.BORDER_STYLE_DOUBLE:
			setStyle( "solid" );
			break;
		case org.eclipse.birt.report.engine.nLayout.area.style.BorderInfo.BORDER_STYLE_DASHED:
			setStyle( "dash" );
			break;
		case org.eclipse.birt.report.engine.nLayout.area.style.BorderInfo.BORDER_STYLE_DOTTED:
			setStyle( "sysDash" );
			break;
		default:
			setStyle( "solid" );
			break;
	}
	writer.closeTag( "a:ln" );
}
 
Example #22
Source File: PlayerInfoConfig.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@ConfigItem(
	keyName = "colorLow",
	name = "Color Low",
	description = "The color displayed for low values.",
	position = 7,
	titleSection = "colorsTitle"
)
default Color colorLow()
{
	return Color.RED;
}
 
Example #23
Source File: EmojiParser.java    From ChatGameFontificator with The Unlicense 5 votes vote down vote up
private void parseTwitchBadges(TypedEmojiMap badgeMap, String jsonData) throws IOException
{
    JsonElement jsonElement = new JsonParser().parse(jsonData);

    Gson gson = new Gson();

    Type emoteType = new TypeToken<Map<String, TwitchBadges>>()
    {
    }.getType();
    Map<String, TwitchBadges> jsonMap = gson.fromJson(jsonElement, emoteType);

    final Color subBgColor = new Color(0x6441A4);
    int badgeCount = 0;
    for (Entry<String, TwitchBadges> badge : jsonMap.entrySet())
    {
        if (badge.getValue() != null && badge.getValue().getImage() != null)
        {
            // Sub badge color is a background color hack to make the sub badge visible against black backgrounds until the new Twitch badge system is implemented
            final boolean isSubBadge = "subscriber".equals(badge.getKey());
            badgeCount++;
            LazyLoadEmoji llBadge = new LazyLoadEmoji(badge.getKey(), badge.getValue().getImage(), TWITCH_BADGE_PIXEL_SIZE, TWITCH_BADGE_PIXEL_SIZE, isSubBadge ? subBgColor : null, EmojiType.TWITCH_BADGE);
            badgeMap.put(badge.getKey(), llBadge);
        }
    }

    logBox.log(badgeCount + " Twitch badge" + (badgeCount == 1 ? "" : "s") + " loaded");
}
 
Example #24
Source File: SampleTreeCellRenderer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * paint is subclassed to draw the background correctly.  JLabel
 * currently does not allow backgrounds other than white, and it
 * will also fill behind the icon.  Something that isn't desirable.
 */
@Override
public void paint(Graphics g) {
    Color bColor;
    Icon currentI = getIcon();

    if (selected) {
        bColor = SELECTED_BACKGROUND_COLOR;
    } else if (getParent() != null) /* Pick background color up from parent (which will come from
    the JTree we're contained in). */ {
        bColor = getParent().getBackground();
    } else {
        bColor = getBackground();
    }
    g.setColor(bColor);
    if (currentI != null && getText() != null) {
        int offset = (currentI.getIconWidth() + getIconTextGap());

        if (getComponentOrientation().isLeftToRight()) {
            g.fillRect(offset, 0, getWidth() - 1 - offset,
                    getHeight() - 1);
        } else {
            g.fillRect(0, 0, getWidth() - 1 - offset, getHeight() - 1);
        }
    } else {
        g.fillRect(0, 0, getWidth() - 1, getHeight() - 1);
    }
    super.paint(g);
}
 
Example #25
Source File: OptionPanel.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public JComboBox addChoice(String label, String[] items, int selected, Setter setter) {
	addLabel(label);
	JComboBox choice = new JComboBox(items);
	choice.setBackground(Color.white);
	choice.setSelectedIndex(selected);
	choice.addActionListener(tl);
	all.add(choice);
	addField(choice, setter);
	return choice;
}
 
Example #26
Source File: XComponentPeer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an array of Colors similar to getGUIcolors(), but using the
 * System colors.  This is useful if pieces of a Component (such as
 * the integrated scrollbars of a List) should retain the System color
 * instead of the background color set by Component.setBackground().
 */
static Color[] getSystemColors() {
    if (systemColors == null) {
        systemColors = new Color[4];
        systemColors[BACKGROUND_COLOR] = SystemColor.window;
        systemColors[HIGHLIGHT_COLOR] = SystemColor.controlLtHighlight;
        systemColors[SHADOW_COLOR] = SystemColor.controlShadow;
        systemColors[FOREGROUND_COLOR] = SystemColor.windowText;
    }
    return systemColors;
}
 
Example #27
Source File: StyleConstants.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the foreground color setting from the attribute list.
 *
 * @param a the attribute set
 * @return the color, Color.black as the default
 */
public static Color getForeground(AttributeSet a) {
    Color fg = (Color) a.getAttribute(Foreground);
    if (fg == null) {
        fg = Color.black;
    }
    return fg;
}
 
Example #28
Source File: View.java    From desktopclient-java with GNU General Public License v3.0 5 votes vote down vote up
void showPasswordDialog(boolean wasWrong) {
    WebPanel passPanel = new WebPanel();
    WebLabel passLabel = new WebLabel(Tr.tr("Please enter your key password:"));
    passPanel.add(passLabel, BorderLayout.NORTH);
    final WebPasswordField passField = new WebPasswordField();
    passPanel.add(passField, BorderLayout.CENTER);
    if (wasWrong) {
        WebLabel wrongLabel = new WebLabel(Tr.tr("Wrong password"));
        wrongLabel.setForeground(Color.RED);
        passPanel.add(wrongLabel, BorderLayout.SOUTH);
    }
    WebOptionPane passPane = new WebOptionPane(passPanel,
            WebOptionPane.QUESTION_MESSAGE,
            WebOptionPane.OK_CANCEL_OPTION);
    JDialog dialog = passPane.createDialog(mMainFrame, Tr.tr("Enter password"));
    dialog.setModal(true);
    dialog.addWindowFocusListener(new WindowAdapter() {
        @Override
        public void windowGainedFocus(WindowEvent e) {
            passField.requestFocusInWindow();
        }
    });
    // blocking
    LOGGER.info("asking for password…");
    dialog.setVisible(true);

    Object value = passPane.getValue();
    if (value != null && value.equals(WebOptionPane.OK_OPTION))
        mControl.connect(passField.getPassword());
}
 
Example #29
Source File: ImageUtil.java    From SimpleBBS with Apache License 2.0 5 votes vote down vote up
/**
 * 生成随机验证码及图片
 * Object[0]:验证码字符串;
 * Object[1]:验证码图片。
 */
public static Object[] createImage() {
    StringBuffer sb = new StringBuffer();
    // 1.创建空白图片
    BufferedImage image = new BufferedImage(
            WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
    // 2.获取图片画笔
    Graphics graphic = image.getGraphics();
    // 3.设置画笔颜色
    graphic.setColor(Color.LIGHT_GRAY);
    // 4.绘制矩形背景
    graphic.fillRect(0, 0, WIDTH, HEIGHT);
    // 5.画随机字符
    Random ran = new Random();
    for (int i = 0; i < SIZE; i++) {
        // 取随机字符索引
        int n = ran.nextInt(chars.length);
        // 设置随机颜色
        graphic.setColor(getRandomColor());
        // 设置字体大小
        graphic.setFont(new Font(
                null, Font.BOLD + Font.ITALIC, FONT_SIZE));
        // 画字符
        graphic.drawString(
                chars[n] + "", i * WIDTH / SIZE, HEIGHT * 2 / 3);
        // 记录字符
        sb.append(chars[n]);
    }
    // 6.画干扰线
    for (int i = 0; i < LINES; i++) {
        // 设置随机颜色
        graphic.setColor(getRandomColor());
        // 随机画线
        graphic.drawLine(ran.nextInt(WIDTH), ran.nextInt(HEIGHT),
                ran.nextInt(WIDTH), ran.nextInt(HEIGHT));
    }
    // 7.返回验证码和图片
    return new Object[]{sb.toString(), image};
}
 
Example #30
Source File: PlayerDetailsPanel.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
private void setLookAndFeel(final Color foreColor) {
    setOpaque(false);
    setForeground(foreColor);
    setLayout(migLayout);
    // player name label
    playerNameLabel.setFont(FontsAndBorders.FONT3);
    playerNameLabel.setForeground(foreColor);
    playerNameLabel.setVerticalAlignment(SwingConstants.TOP);
    // player type label
    playerTypeLabel.setFont(FontsAndBorders.FONT0);
    playerTypeLabel.setForeground(foreColor);
    // player attributes label
    playerAttributesLabel.setFont(FontsAndBorders.FONT0);
    playerAttributesLabel.setForeground(foreColor);
}