Example usage for java.awt Color RED

List of usage examples for java.awt Color RED

Introduction

In this page you can find the example usage for java.awt Color RED.

Prototype

Color RED

To view the source code for java.awt Color RED.

Click Source Link

Document

The color red.

Usage

From source file:Main.java

public void paintIcon(Component c, Graphics g, int x, int y) {
    g.setColor(Color.RED);
    if (c.isEnabled()) {
        g.fillOval(x, y, getIconWidth(), getIconHeight());
    } else {//from ww  w  . j a va 2  s. c o  m
        g.drawOval(x, y, getIconWidth(), getIconHeight());
    }
}

From source file:MainClass.java

public MainClass() {
    Container cp = new Box(BoxLayout.X_AXIS);
    setContentPane(cp);/*from  www . j a  v  a 2s  . c  om*/
    JPanel firstPanel = new JPanel();
    propertyComboBox = new JComboBox();
    propertyComboBox.addItem("text");
    propertyComboBox.addItem("font");
    propertyComboBox.addItem("background");
    propertyComboBox.addItem("foreground");
    firstPanel.add(propertyComboBox);
    cp.add(firstPanel);
    cp.add(Box.createGlue());

    tf = new JTextField("Hello");
    tf.setForeground(Color.RED);
    tf.setDragEnabled(true);
    cp.add(tf);

    cp.add(Box.createGlue());

    l = new JLabel("Hello");
    l.setBackground(Color.YELLOW);
    cp.add(l);

    cp.add(Box.createGlue());

    JSlider stryder = new JSlider(SwingConstants.VERTICAL);
    stryder.setMinimum(10);
    stryder.setValue(14);
    stryder.setMaximum(72);
    stryder.setMajorTickSpacing(10);
    stryder.setPaintTicks(true);

    cp.add(stryder);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(500, 300);

    setMyTransferHandlers((String) propertyComboBox.getSelectedItem());

    MouseListener myDragListener = new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            JComponent c = (JComponent) e.getSource();
            TransferHandler handler = c.getTransferHandler();
            handler.exportAsDrag(c, e, TransferHandler.COPY);
        }
    };
    l.addMouseListener(myDragListener);

    propertyComboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ce) {
            JComboBox bx = (JComboBox) ce.getSource();
            String prop = (String) bx.getSelectedItem();
            setMyTransferHandlers(prop);
        }
    });

    tf.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            JTextField jtf = (JTextField) evt.getSource();
            String fontName = jtf.getText();
            Font font = new Font(fontName, Font.BOLD, 18);
            tf.setFont(font);
        }
    });

    stryder.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent evt) {
            JSlider sl = (JSlider) evt.getSource();
            Font oldf = tf.getFont();
            Font newf = oldf.deriveFont((float) sl.getValue());
            tf.setFont(newf);
        }
    });
}

From source file:org.jfree.chart.demo.GradientPaintTransformerDemo1.java

public static JPanel createDemoPanel() {
    JPanel jpanel = new JPanel(new GridLayout(2, 2));
    jpanel.setPreferredSize(new Dimension(800, 600));
    CategoryDataset categorydataset = createDataset();
    JFreeChart jfreechart = createChart("Type: VERTICAL", categorydataset);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setDrawBarOutline(false);
    barrenderer.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow));
    barrenderer.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green));
    barrenderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    jpanel.add(chartpanel);/*from  w w  w .  j  av a2s.co  m*/
    JFreeChart jfreechart1 = createChart("Type: HORIZONTAL", categorydataset);
    CategoryPlot categoryplot1 = (CategoryPlot) jfreechart1.getPlot();
    BarRenderer barrenderer1 = (BarRenderer) categoryplot1.getRenderer();
    barrenderer1.setDrawBarOutline(false);
    barrenderer1.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow));
    barrenderer1.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green));
    barrenderer1.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));
    ChartPanel chartpanel1 = new ChartPanel(jfreechart1);
    jpanel.add(chartpanel1);
    JFreeChart jfreechart2 = createChart("Type: CENTER_VERTICAL", categorydataset);
    CategoryPlot categoryplot2 = (CategoryPlot) jfreechart2.getPlot();
    BarRenderer barrenderer2 = (BarRenderer) categoryplot2.getRenderer();
    barrenderer2.setDrawBarOutline(false);
    barrenderer2.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow));
    barrenderer2.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green));
    barrenderer2.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_VERTICAL));
    ChartPanel chartpanel2 = new ChartPanel(jfreechart2);
    jpanel.add(chartpanel2);
    JFreeChart jfreechart3 = createChart("Type: CENTER_HORIZONTAL", categorydataset);
    CategoryPlot categoryplot3 = (CategoryPlot) jfreechart3.getPlot();
    BarRenderer barrenderer3 = (BarRenderer) categoryplot3.getRenderer();
    barrenderer3.setDrawBarOutline(false);
    barrenderer3.setSeriesPaint(0, new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, Color.yellow));
    barrenderer3.setSeriesPaint(1, new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, Color.green));
    barrenderer3.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL));
    ChartPanel chartpanel3 = new ChartPanel(jfreechart3);
    jpanel.add(chartpanel3);
    return jpanel;
}

From source file:org.jfree.graphics2d.demo.ImageTest.java

private static void drawOldLinearGradientPaintTest(Graphics2D g2) {
    // top left/*  w w w. jav a2  s.c o m*/
    GradientPaint lgp = new GradientPaint(10, 30, Color.RED, 50, 30, Color.BLUE);
    g2.setPaint(lgp);
    g2.fill(new Rectangle2D.Double(10, 10, 40, 40));

    // top right
    lgp = new GradientPaint(80, 10, Color.RED, 80, 50, Color.BLUE);
    g2.setPaint(lgp);
    g2.fill(new Rectangle2D.Double(60, 10, 40, 40));

    // bottom left
    lgp = new GradientPaint(10, 100, Color.RED, 50, 60, Color.BLUE);
    g2.setPaint(lgp);
    g2.fill(new Rectangle2D.Double(10, 60, 40, 40));

    // bottom right
    lgp = new GradientPaint(70, 70, Color.RED, 90, 90, Color.BLUE);
    g2.setPaint(lgp);
    g2.fill(new Rectangle2D.Double(60, 60, 40, 40));

}

From source file:controller.DrawCurve.java

private JPanel createChart() {
    String chartTitle = "Camera Response Curve";
    String xAxisLabel = "log Exposure G(Z)";
    String yAxisLabel = "Intensity pixel Z";

    XYDataset dataset = createDataset();

    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, xAxisLabel, yAxisLabel, dataset);

    //Set custom color and thickness for line curve
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);

    // sets paint color for each series
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.GREEN);
    renderer.setSeriesPaint(2, Color.BLUE);

    // sets thickness for series (using strokes)
    renderer.setSeriesStroke(0, new BasicStroke(1.5f));
    renderer.setSeriesStroke(1, new BasicStroke(1.5f));
    renderer.setSeriesStroke(2, new BasicStroke(1.5f));

    XYPlot plot = chart.getXYPlot();/*from w ww.  j  a  v a2  s  .co  m*/
    plot.setRenderer(renderer);

    return new ChartPanel(chart);
}

From source file:dataminning2.KmeanGraphplot.java

protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    int w = getWidth();
    int h = getHeight();
    // Draw ordinate.
    g2.draw(new Line2D.Double(PAD, PAD, PAD, h - PAD));
    // Draw abcissa.
    g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD, h - PAD));
    double xInc = (double) (w - 2 * PAD) / (data.length - 1);
    double scale = (double) (h - 2 * PAD) / 88;
    // Mark data points.

    g2.setPaint(Color.red);

    for (int i = 0; i < cluster0.length; i++) {
        double x = PAD + i * dataX[i];
        double y = h - PAD - scale * dataY[i];
        g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4));
    }//from   w  w w .j  a va2  s  .  co  m

    g2.setPaint(Color.BLUE);

    for (int i = 0; i < cluster1.length; i++) {
        double x = PAD + i * dataX[i];
        double y = h - PAD - scale * dataY[i];
        g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4));
    }
    g2.setPaint(Color.YELLOW);

    for (int i = 0; i < cluster2.length; i++) {
        double x = PAD + i * dataX[i];
        double y = h - PAD - scale * dataY[i];
        g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4));
    }
}

From source file:view.FuzzySetView.java

private void initColors() {
    colors = new Color[] { Color.BLUE, Color.RED, Color.GREEN, Color.ORANGE, Color.MAGENTA };
}

From source file:IHM.NewClass.java

/**
 *
 * @param title/*from w ww  .j  a v a  2s .co  m*/
 */
public NewClass(String title /*,*JInternalFrame jp*/) {
    super(title);
    // jp = new JInternalFrame("courbes");

    JFreeChart chart = createChart(createDataset());
    ChartPanel panel = new ChartPanel(chart);
    panel.setPreferredSize(new Dimension(500, 300));
    setContentPane(panel);
    //  jp.add(panel, BorderLayout.EAST);
    //  jp.setVisible(true);
    panel.setVisible(true);
    XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.GREEN);
    renderer.setSeriesPaint(2, Color.YELLOW);
    // sets thickness for series (using strokes)
    renderer.setSeriesStroke(0, new BasicStroke(4.0f));
    renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    renderer.setSeriesStroke(2, new BasicStroke(2.0f));
    plot.setRenderer(renderer);
    plot.setOutlinePaint(Color.BLUE);
    plot.setOutlineStroke(new BasicStroke(2.0f));
    plot.setBackgroundPaint(Color.DARK_GRAY);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.BLACK);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.BLACK);

}

From source file:contactangle.ImageControl.java

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (img != null)
        g.drawImage(img, 0, 0, this);
    else/*  w ww .  jav a2 s . c om*/
        g.drawString("NO IMAGE", 0, 15);

    g.setColor(Color.RED);

    if (x1 < x2 && y1 < y2)
        g.drawRect(x1, y1, x2 - x1, y2 - y1);
    else if (x1 >= x2 && y1 < y2)
        g.drawRect(x2, y1, x1 - x2, y2 - y1);
    else if (x1 < x2 && y1 >= y2)
        g.drawRect(x1, y2, x2 - x1, y1 - y2);
    else
        g.drawRect(x2, y2, x1 - x2, y1 - y2);

    if (valid && img != null) {

        if (x1 >= x2) {
            int temp = x1;
            x1 = x2;
            x2 = temp;
        }
        if (y1 >= y2) {
            int temp = y1;
            y1 = y2;
            y2 = temp;
        }

        choosenPoints = new ArrayList<Point>();
        for (int y = y1; y < y2; y++) {
            for (int x = x1; x < x2; x++) {
                int pixelData = img.getRGB(x, y);
                if (pixelData == -1)
                    choosenPoints.add(new Point(x, y));
            }
        }

        SimpleRegression reg = new SimpleRegression();
        for (Point p : choosenPoints) {
            reg.addData(p.x, p.y);
        }

        int firstX = choosenPoints.get(0).x;
        int firstY = choosenPoints.get(0).y;
        double slope = reg.getSlope();
        g.setColor(Color.GREEN);
        g.drawLine(firstX, firstY, firstX + (70), firstY + (int) (slope * (70)));
        g.drawLine(firstX, firstY, firstX - (70), firstY - (int) (slope * (70)));

        double contactDegrees = (Math.atan(reg.getSlope()) / (2 * Math.PI)) * 360.0;

        DecimalFormat d = new DecimalFormat("##.###");

        g.drawString("Contact Angle = ", 25, 25);
        g.drawString(d.format(contactDegrees) + " degrees", 25, 38);
    }

}

From source file:org.jfree.chart.demo.StackedXYBarChartDemo3.java

private static JFreeChart createChart(TableXYDataset tablexydataset) {
    DateAxis dateaxis = new DateAxis("Year");
    dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    dateaxis.setLowerMargin(0.01D);/*from  w  ww.ja  v a  2  s. co  m*/
    dateaxis.setUpperMargin(0.01D);
    NumberAxis numberaxis = new NumberAxis("Tonnes");
    numberaxis.setNumberFormatOverride(new DecimalFormat("0.0%"));
    StackedXYBarRenderer stackedxybarrenderer = new StackedXYBarRenderer(0.29999999999999999D);
    stackedxybarrenderer.setRenderAsPercentages(true);
    GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, new Color(64, 0, 0), 0.0F, 0.0F, Color.red);
    GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, new Color(0, 64, 0), 0.0F, 0.0F, Color.green);
    stackedxybarrenderer.setSeriesPaint(0, gradientpaint);
    stackedxybarrenderer.setSeriesPaint(1, gradientpaint1);
    stackedxybarrenderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));
    stackedxybarrenderer.setDrawBarOutline(false);
    stackedxybarrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0} : {1} = {2} tonnes",
            new SimpleDateFormat("yyyy"), new DecimalFormat("#,##0")));
    XYPlot xyplot = new XYPlot(tablexydataset, dateaxis, numberaxis, stackedxybarrenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    JFreeChart jfreechart = new JFreeChart("Waste Management", xyplot);
    jfreechart.setBackgroundPaint(Color.white);
    jfreechart.addSubtitle(new TextTitle("St Albans City and District Council"));
    return jfreechart;
}