dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java
Expertise: Advanced
Mar 17, 2008

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Create a Color Using "<<" and "|" Operators

This tip shows you how to create the RED color using the "<<" and "|" operators. After that, the color is used to fill a rectangle:

import java.awt.*;

class draw_red_rect extends Frame{

Color col=null;

public draw_red_rect()
     {
     super();
     }

public void init()
     {
     setLayout(null);
     setSize(100,100);

     int A=255<<24; 
     int R=255<<16;
     int G=0<<8;
     int B=0<<0; //int B=0;

     System.out.println("A="+A+",R="+R+",G="+G+",B="+B);

     int RED=A | R | G | B;

     col=new Color(RED);
     System.out.println("RED="+RED+" // getRGB="+col.getRGB());
     System.out.println("RED_BINAR= 
              "+Integer.toBinaryString(col.getRGB()));

     setVisible(true);  //show();
     }

public void paint(Graphics g)
     {       
     g.setColor(col);
     g.fillRect(30,30,50,50);
     }
}

public class red{
     public static void main(String[] args){
         draw_red_rect t=new draw_red_rect();
         t.init();
    }
}
Leonard Anghel
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date