Tudo sobre JAVA



Postagem do dono do blog: (10/09/2010 20:31:32)
Tratando eventos com uma classe anônima:    
  component.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent evt) {


Postagem do dono do blog: (10/09/2010 20:30:13)
Tratando mudanças de focus:
  component.addFocusListener(new MyFocusListener());
    public class MyFocusListener extends FocusAdapter {
        public void focusGained(FocusEvent evt) {
            // The component gained the focus
        public void focusLost(FocusEvent evt) {
            // The component lost the focus

Postagem do dono do blog: (10/09/2010 20:27:47)
Combinando Shapes :  
  Area shape = new Area(shape1);
    shape.add(new Area(shape2));
    shape.subtract(new Area(shape3));
    shape.intersect(new Area(shape4));
    shape.exclusiveOr(new Area(shape5));

Postagem do dono do blog: (10/09/2010 20:17:54)
Preenchendo os valores RGB de uma imagem
// This filter removes all but the red values in an image

    class GetRedFilter extends RGBImageFilter {

        public GetRedFilter() {

            // When this is set to true, the filter will work with images

            // whose pixels are indices into a color table (IndexColorModel).

            // In such a case, the color values in the color table are filtered.

            canFilterIndexColorModel = true;



        // This method is called for every pixel in the image

        public int filterRGB(int x, int y, int rgb) {

            if (x == -1) {

                // The pixel value is from the image's color table rather than the image itself


            // Return only the red component

            return rgb & 0xffff0000;



Here's some code that uses the filter:

    // Get image

    Image image = new ImageIcon("image.gif").getImage();


    // Create the filter

    ImageFilter filter = new GetRedFilter();

    FilteredImageSource filteredSrc = new FilteredImageSource(image.getSource(), filter);


    // Create the filtered image

    image = Toolkit.getDefaultToolkit().createImage(filteredSrc);