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:ColorComboBox.java

public static void main(String args[]) {
    Color colors[] = { Color.black, Color.blue, Color.cyan, Color.darkGray, Color.gray, Color.green,
            Color.lightGray, Color.magenta, Color.orange, Color.pink, Color.red, Color.white, Color.yellow };
    JFrame frame = new JFrame("Color JComboBox");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    final JComboBox comboBox = new JComboBox(colors);
    comboBox.setMaximumRowCount(5);//from   w ww.  j a  v  a  2  s .  co m
    comboBox.setEditable(true);
    comboBox.setRenderer(new ColorCellRenderer());
    Color color = (Color) comboBox.getSelectedItem();
    ComboBoxEditor editor = new ColorComboBoxEditor(color);
    comboBox.setEditor(editor);
    contentPane.add(comboBox, BorderLayout.NORTH);

    final JLabel label = new JLabel();
    label.setOpaque(true);
    label.setBackground((Color) comboBox.getSelectedItem());
    contentPane.add(label, BorderLayout.CENTER);

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Color selectedColor = (Color) comboBox.getSelectedItem();
            label.setBackground(selectedColor);
        }
    };
    comboBox.addActionListener(actionListener);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:ColorAction.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setTitle("SeparateGUITest");
    frame.setSize(300, 200);//  ww w  .j a  v  a2s .  c om
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    JPanel panel = new JPanel();

    Action blueAction = new ColorAction("Blue", new ImageIcon("blue-ball.gif"), Color.blue, panel);
    Action yellowAction = new ColorAction("Yellow", new ImageIcon("yellow-ball.gif"), Color.yellow, panel);
    Action redAction = new ColorAction("Red", new ImageIcon("red-ball.gif"), Color.red, panel);

    panel.add(new JButton(yellowAction));
    panel.add(new JButton(blueAction));
    panel.add(new JButton(redAction));

    panel.registerKeyboardAction(yellowAction, KeyStroke.getKeyStroke(KeyEvent.VK_Y, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);
    panel.registerKeyboardAction(blueAction, KeyStroke.getKeyStroke(KeyEvent.VK_B, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);
    panel.registerKeyboardAction(redAction, KeyStroke.getKeyStroke(KeyEvent.VK_R, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);

    Container contentPane = frame.getContentPane();
    contentPane.add(panel);

    JMenu m = new JMenu("Color");
    m.add(yellowAction);
    m.add(blueAction);
    m.add(redAction);
    JMenuBar mbar = new JMenuBar();
    mbar.add(m);
    frame.setJMenuBar(mbar);

    frame.show();
}

From source file:ComplexCellRenderer.java

public static void main(String args[]) {
    Object elements[][] = { { new Font("Helvetica", Font.PLAIN, 20), Color.RED, new MyIcon(), "A" },
            { new Font("TimesRoman", Font.BOLD, 14), Color.BLUE, new MyIcon(), "A" },
            { new Font("Courier", Font.ITALIC, 18), Color.GREEN, new MyIcon(), "A" },
            { new Font("Helvetica", Font.BOLD | Font.ITALIC, 12), Color.GRAY, new MyIcon(), "A" },
            { new Font("TimesRoman", Font.PLAIN, 32), Color.PINK, new MyIcon(), "A" },
            { new Font("Courier", Font.BOLD, 16), Color.YELLOW, new MyIcon(), "A" },
            { new Font("Helvetica", Font.ITALIC, 8), Color.DARK_GRAY, new MyIcon(), "A" } };

    JFrame frame = new JFrame("Complex Renderer");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    ListCellRenderer renderer = new ComplexCellRenderer();
    JComboBox comboBox = new JComboBox(elements);
    comboBox.setRenderer(renderer);/* ww  w .  jav  a 2  s  .c om*/
    frame.add(comboBox, BorderLayout.NORTH);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:ComplexCellRenderer.java

public static void main(String args[]) {
    Object elements[][] = { { new Font("Helvetica", Font.PLAIN, 20), Color.RED, new MyIcon(), "A" },
            { new Font("TimesRoman", Font.BOLD, 14), Color.BLUE, new MyIcon(), "A" },
            { new Font("Courier", Font.ITALIC, 18), Color.GREEN, new MyIcon(), "A" },
            { new Font("Helvetica", Font.BOLD | Font.ITALIC, 12), Color.GRAY, new MyIcon(), "A" },
            { new Font("TimesRoman", Font.PLAIN, 32), Color.PINK, new MyIcon(), "A" },
            { new Font("Courier", Font.BOLD, 16), Color.YELLOW, new MyIcon(), "A" },
            { new Font("Helvetica", Font.ITALIC, 8), Color.DARK_GRAY, new MyIcon(), "A" } };

    JFrame frame = new JFrame("Complex Renderer");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JList jlist = new JList(elements);
    ListCellRenderer renderer = new ComplexCellRenderer();
    jlist.setCellRenderer(renderer);/*w  w w. j  a va2 s  .co m*/
    JScrollPane scrollPane = new JScrollPane(jlist);
    frame.add(scrollPane, BorderLayout.CENTER);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:JButtonKnowsBgColor.java

public static void main(String[] args) {
    JButtonKnowsBgColor jbkbc = new JButtonKnowsBgColor("choose back", Color.RED, true);
    JButtonKnowsBgColor jbkbc1 = new JButtonKnowsBgColor("choose fore", Color.BLUE, false);
    JFrame jf = new JFrame();
    jf.setLayout(new BorderLayout());
    jf.getContentPane().add(jbkbc, BorderLayout.NORTH);
    jf.getContentPane().add(jbkbc1, BorderLayout.CENTER);
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jf.setSize(100, 200);/*from  ww w . j  a v  a  2s .c  om*/
    jf.setVisible(true);
}

From source file:FullScreen.java

public static void main(String args[]) {
    GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice graphicsDevice = graphicsEnvironment.getDefaultScreenDevice();
    DisplayMode originalDisplayMode = graphicsDevice.getDisplayMode();

    try {//  ww w .ja v  a  2 s. com
        Frame frame = new Frame();
        frame.setUndecorated(true);
        frame.setIgnoreRepaint(true);
        graphicsDevice.setFullScreenWindow(frame);
        if (graphicsDevice.isDisplayChangeSupported()) {
            graphicsDevice.setDisplayMode(getBestDisplayMode(graphicsDevice));
        }
        frame.createBufferStrategy(2); // 2 buffers
        Rectangle bounds = frame.getBounds();
        BufferStrategy bufferStrategy = frame.getBufferStrategy();
        while (!done()) {
            Graphics g = null;
            try {
                g = bufferStrategy.getDrawGraphics();
                if ((counter <= 2)) { // 2 buffers
                    g.setColor(Color.CYAN);
                    g.fillRect(0, 0, bounds.width, bounds.height);
                }
                g.setColor(Color.RED);
                // redraw prior line, too, since 2 buffers
                if (counter != 1) {
                    g.drawLine(counter - 1, (counter - 1) * 5, bounds.width, bounds.height);
                }
                g.drawLine(counter, counter * 5, bounds.width, bounds.height);
                bufferStrategy.show();
            } finally {
                if (g != null) {
                    g.dispose();
                }
            }
            try {
                Thread.sleep(250);
            } catch (InterruptedException ignored) {
            }
        }
    } finally {
        graphicsDevice.setDisplayMode(originalDisplayMode);
        graphicsDevice.setFullScreenWindow(null);
    }
    System.exit(0);
}

From source file:be.vdab.util.Programma.java

public static void main(String[] args) {
    SortedSet<Voertuig> voertuigen = new TreeSet<Voertuig>();
    Datum datum = null;/*from   w w  w  .  java2 s  .c  om*/
    Volume volumePickup = null;
    Volume volumeVrachtwagen = null;
    try {
        datum = new Datum(21, 11, 2012);
    } catch (DatumException de) {
        System.out.println(de.getMessage());
    }
    Mens bestuurder_BC = new Mens("Albert", Rijbewijs.B, Rijbewijs.C);
    Mens inzittende_A = new Mens("Karolien", Rijbewijs.A);
    Mens inzittende = new Mens("Zora");
    Mens inzittende_B = new Mens("David", Rijbewijs.B);
    Mens inzittende_DDE = new Mens("Evert", Rijbewijs.D, Rijbewijs.DE);
    Mens bestuurder_DE = new Mens("Boris", Rijbewijs.DE);
    Personenwagen wagen1Opel = new Personenwagen("Opel", datum, 250000, 4, Color.blue, bestuurder_BC,
            inzittende_A, inzittende);
    Personenwagen wagen2 = new Personenwagen("Mazda", datum, 27000, 5, Color.blue, bestuurder_BC, inzittende_A);

    try {
        volumePickup = new Volume(3, 3, 2, Maat.meter);
        volumeVrachtwagen = new Volume(3, 6, 2, Maat.meter);
    } catch (VolumeException ve) {
        System.out.println(ve.getMessage());
    }

    Pickup pickup1Opel = new Pickup("Opel", datum, 400000, 5, Color.RED, volumePickup, bestuurder_BC,
            inzittende_B, inzittende_DDE, inzittende_A);
    Pickup pickup2 = new Pickup("Toyota", datum, 39000, 4, Color.blue, volumePickup, bestuurder_BC);
    Vrachtwagen vrachtwagen1 = new Vrachtwagen("BMW", datum, 90000, 2, volumeVrachtwagen, 3000, 6,
            bestuurder_BC, inzittende_A);
    Vrachtwagen vrachtwagen2 = new Vrachtwagen("Mercedes", datum, 120000, 3, volumeVrachtwagen, 2000, 8,
            bestuurder_BC, inzittende);
    voertuigen.add(wagen1Opel); //gesorteerd op nummerplaat
    voertuigen.add(wagen2);
    voertuigen.add(pickup1Opel);
    voertuigen.add(pickup2);
    voertuigen.add(vrachtwagen1);
    voertuigen.add(vrachtwagen2);

    print(voertuigen);

    /*
    //copy manier1
    //copy (niet nodig dadelijk naar list omzetten, maar dan zit het niet in een SortedSet, oplossing: zelf copy uitvoeren, maar niet enkel referenties
    Set<Voertuig> voertuigen2=null;//=new TreeSet<Voertuig>(voertuigen); //new TreeSet<Voertuig>( org.apache.commons.collections.ComparatorUtils.reversedComparator( Voertuig.getAankoopprijsComparator()));
    //transformeren naar List, ook een copy
    List<Voertuig> lijst=new ArrayList<Voertuig>(voertuigen);//niet voertuigen 2
    //sort
      Collections.sort(lijst, org.apache.commons.collections.ComparatorUtils.reversedComparator( Voertuig.getAankoopprijsComparator()));
      print(lijst);
    */
    Set<Voertuig> voertuigen2 = new TreeSet<Voertuig>(org.apache.commons.collections.ComparatorUtils
            .reversedComparator(Voertuig.getAankoopprijsComparator()));
    voertuigen2.addAll(voertuigen);
    print(voertuigen2);

    //Copy manier 2: beter
    Set<Voertuig> voertuigen3 = new TreeSet<Voertuig>(Voertuig.getMerkComparator());
    voertuigen3.addAll(voertuigen);//deep copy of niet , staat niet in de api. Maakt het uit hier? wanneer wel?als je de vrachtwagens gaat wijzigen en je wil dat die alleen in de copy gewijzigd zijn dan deep copy nodig
    print(voertuigen3);

    try {
        schrijweg((TreeSet) voertuigen3, "wagenpark.ser");
    } catch (FileNotFoundException fnfe) {
        System.out.println(fnfe.getMessage());
    } catch (IOException ioe) {
        System.out.println(ioe.getMessage());
    }
    TreeSet<Voertuig> voertuigen4 = lees("wagenpark.ser");
    System.out.println("Voertuigen4");
    print(voertuigen4);

}

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

/**
 * Starting point for the demo.//from w  w  w.j ava2 s  .  co  m
 * 
 * @param args  ignored.
 * 
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
    BufferedImage image = new BufferedImage(600, 400, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = image.createGraphics();
    ImageIcon icon = new ImageIcon(BufferedImageDemo.class.getResource("jfree_chart_1.jpg"));
    g2.rotate(Math.PI / 12);
    g2.setStroke(new BasicStroke(2.0f));
    g2.setPaint(Color.WHITE);
    g2.fill(new Rectangle(0, 0, 600, 400));
    g2.setPaint(Color.RED);
    g2.draw(new Rectangle(0, 0, 600, 400));
    g2.drawImage(icon.getImage(), 10, 20, null);
    ImageIO.write(image, "png", new File("image-test.png"));
}

From source file:CreateColorSamplePopup.java

public static void main(String args[]) {
    JFrame frame = new JFrame("JColorChooser Create Popup Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    final JButton button = new JButton("Pick to Change Background");

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Color initialBackground = button.getBackground();

            final JColorChooser colorChooser = new JColorChooser(initialBackground);
            //        colorChooser.setPreviewPanel(new JPanel());
            final JLabel previewLabel = new JLabel("I Love Swing", JLabel.CENTER);
            previewLabel.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 48));
            colorChooser.setPreviewPanel(previewLabel);
            // Bug workaround
            colorChooser.updateUI();//from   w  ww.  ja  va 2  s.c o m

            // For okay button selection, change button background to
            // selected color
            ActionListener okActionListener = new ActionListener() {
                public void actionPerformed(ActionEvent actionEvent) {
                    Color newColor = colorChooser.getColor();
                    if (newColor.equals(button.getForeground())) {
                        System.out.println("Color change rejected");
                    } else {
                        button.setBackground(colorChooser.getColor());
                    }
                }
            };

            // For cancel button selection, change button background to red
            ActionListener cancelActionListener = new ActionListener() {
                public void actionPerformed(ActionEvent actionEvent) {
                    button.setBackground(Color.red);
                }
            };

            final JDialog dialog = JColorChooser.createDialog(null, "Change Button Background", true,
                    colorChooser, okActionListener, cancelActionListener);

            // Wait until current event dispatching completes before showing
            // dialog
            Runnable showDialog = new Runnable() {
                public void run() {
                    dialog.show();
                }
            };
            SwingUtilities.invokeLater(showDialog);
        }
    };
    button.addActionListener(actionListener);
    contentPane.add(button, BorderLayout.CENTER);

    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:MakeFades.java

public static void main(String[] args) throws IOException, NumberFormatException {

    // Create from and to colors based on those arguments
    Color from = Color.RED; // transparent
    Color to = Color.BLACK; // opaque

    // Loop through the sizes and directions, and create an image for each
    for (int s = 0; s < sizes.length; s++) {
        for (int d = 0; d < directions.length; d++) {
            // This is the size of the image
            int size = sizes[s];

            // Create a GradientPaint for this direction and size
            Paint paint = new GradientPaint(directions[d][0] * size, directions[d][1] * size, from,
                    directions[d][2] * size, directions[d][3] * size, to);

            // Start with a blank image that supports transparency
            BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);

            // Now use fill the image with our color gradient
            Graphics2D g = image.createGraphics();
            g.setPaint(paint);/*from   w  w  w  .j  av  a 2s  .  c om*/
            g.fillRect(0, 0, size, size);

            // This is the name of the file we'll write the image to
            File file = new File("fade-to-" + sizeNames[s] + "-" + directionNames[d] + ".png");

            // Save the image in PNG format using the javax.imageio API
            javax.imageio.ImageIO.write(image, "png", file);

            // Show the user our progress by printing the filename
            System.out.println(file);
        }
    }
}