Sunday 25 January 2015

Filled Under:

How to use colour in applet

Java supports color in a portable,device independent fashion.The AWT color system allows to specify any color we want.It then find best match og color.
COLOR defines several  constant such as Color.red as we use in this tutorial and we  can also create
color by color constructors.The most common constructor are:


  1. Color(int red,int green,int blue) in this tutorial we use this constructor.
  2. Color(int rgbValue).
  3. Color(float red,float green,float blue).

HTML CODE OF APPLET:


<html>
<body>
<applet code="colorapp" width="300" height="300">
</applet>
</body>
</html>

JAVA CODING:

import java.applet.*;
import java.awt.*;
public class colorapp extends Applet{

public void paint(Graphics g){
Color c2 = new Color(100,255,100);
Color c3 = new Color(100,100,255);
g.setColor(c2);
g.fillRoundRect(70,90,140,100,30,40);
g.setColor(c3);
g.fillOval(70,90,140,100);
g.setColor(Color.red);
g.drawString("Pro java tricks",90,130);
setBackground(Color.red);
}

}

OUTPUT:







0 comments:

Post a Comment