Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Gradient in an applet (See related posts)

   1  
   2  import java.awt.*;
   3  import java.applet.*;
   4  import javax.swing.*;
   5  
   6  public class JavaAppDe extends JApplet {
   7  	
   8      public void init() {
   9      }
  10  	
  11      public void paint (Graphics g) {
  12          super.paint(g);
  13  	int base = 0;
  14  	while(base<255) {
  15  		g.setColor(new Color(base,base,base));
  16  		g.drawLine(0,base,255,base);
  17  		base++;
  18  	}
  19      }
  20  }

Comments on this post

krafi posts on Oct 30, 2007 at 12:05
Hello Kedare,

I think there is a better and easier solution :

   1  
   2  	@Override
   3  	public void paint(Graphics g) {
   4  		
   5  		super.paint(g);
   6  		
   7  		Graphics2D g2d = (Graphics2D) g;  
   8  		GradientPaint gradient = new GradientPaint(0, 0, Color.BLUE, this.getWidth(),   this.getHeight(),Color.CYAN);
   9  		g2d.setPaint(gradient);
  10  		g2d.fillRect(0, 0, this.getWidth(), this.getHeight());
  11  	}


Have Fun,

Krafi

You need to create an account or log in to post comments to this site.


Click here to browse all 5556 code snippets

Related Posts