Total members 11894 |It is currently Fri Nov 22, 2024 7:10 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





deal with colors in java
Code:
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.Ellipse2D;
import java.awt.image.BufferedImage;
import javax.swing.*;
import javax.swing.event.*;

public class ColorCompositeExample extends JFrame {
  Canvas1 canvas;
  JTextField textField;
  JPanel panel;
  JSlider slider;
  JLabel label;
  float value = 0.65f;

  public ColorCompositeExample() {
    super("Color-composite Example");
    Container container = getContentPane();
  canvas = new Canvas1();
    container.add(canvas);
     panel = new JPanel();
     label = new JLabel("Color-Composite Slider: ");
     slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 65);
     slider.addChangeListener(new ChangeListener() {
     public void stateChanged(ChangeEvent e) {
        JSlider tempSlider = (JSlider) e.getSource();
        value = (float) (tempSlider.getValue() / 100.0);
        textField.setText(Float.toString(value));
        canvas.repaint();
      }
    });
    textField = new JTextField("0.70", 4);
    panel.add(label);
    panel.add(slider);
    panel.add(textField);
  container.add(BorderLayout.NORTH, panel);
    addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });
    setSize(450,400);
    setVisible(true);
  }
   public static void main(String arg[]) {
    new ColorCompositeExample();
  }
   class Canvas1 extends JLabel {
   Ellipse2D.Float oval1, oval2, oval3, oval4;

    Canvas1() {
      oval1 = new Ellipse2D.Float(155, 60, 120, 150);
      oval2 = new Ellipse2D.Float(75, 125, 120, 50);
      oval3 = new Ellipse2D.Float(225, 125, 125, 75);
      oval4 = new Ellipse2D.Float(120, 35, 120, 80);
     setBackground(Color.white);
     setSize(350, 300);
    }
   public void paint(Graphics g) {
      Graphics2D g2D = (Graphics2D) g;
      AlphaComposite alphaComp = AlphaComposite.getInstance(
      AlphaComposite.SRC_OVER, value);
      g2D.setComposite(alphaComp);
      g2D.setStroke(new BasicStroke(6.0f));
   GradientPaint gp = new GradientPaint(120f, 20f, Color.yellow, 220f,
      120f, Color.blue);
      g2D.setPaint(gp);
      g2D.fill(oval1);

      BufferedImage image=  new BufferedImage(5, 5,
            BufferedImage.TYPE_INT_RGB);
      Graphics2D g2 = image.createGraphics();
      g2.fillOval(0, 0, 5, 5);
      g2D.setColor(Color.yellow);
      g2D.fill(oval2);
      g2D.setColor(Color.green);
      g2D.fill(oval3);
      g2D.setColor(Color.red);
      g2D.fill(oval4);
    }
  }
}
 





Attachments:
File comment: screen shot
colorCom2.gif
colorCom2.gif [ 9.22 KiB | Viewed 4678 times ]

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada
Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : deal with colors in java
 Image Colors Frequencies Histogram in Java     -  
 could you help me to deal with this watermark?     -  
 Video for learning how to deal with registry keys     -  
 Video for learning how to deal with registry keys     -  
 Video For Learning how to deal with (Open, Save dialogs) , f     -  
 two Different background colors     -  
 show Rainbow Colors     -  
 Drawing a triangle with colors     -  
 Making Colors Transparent with imagecolortransparent()     -  
 Table Border Colors for PHPBB3     -  



Topic Tags

Java Graphics






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com