Best Projects

Bug Trackingsystem,Books online shopping,college management system,HR management system,Internet banking,Online chat room ,Online exam,Telephone billing system,Banking application,ATM database,airways reservation system,virtual network computing ,calculator,SMTP(simple mail transfer protocol)

Back&Fore ground color changer

Description: This code helpful in How to use Layouts,
Scroll Bar, Label, Panel etc



//ColorChange
import java.awt.*;
import java.awt.event.*;

class ColorChange
{
public static void main(String s[])
{
FrameDemo f = new FrameDemo("Color Changer");
f.setSize(800,550);
f.setVisible(true);
}

}

class C extends Canvas
{
int r,g,b;

public void rgb(int x,int y,int z)
{
r=x;
g=y;
b=z;
}

public void paint(Graphics g1)
{
setBackground(new Color(r,g,b));
g1.setColor(new Color(b,r,g));
g1.setFont(new Font("TimesRoman",1,50));
g1.drawString("Computer World",100,100);
}
}
class FrameDemo extends Frame implements AdjustmentListener
{
Scrollbar sb ,sb1,sb2;
C c;
Label l3 , l4 , l5;
FrameDemo()
{

this("");
}
FrameDemo(String s1)
{
super(s1);
setLayout(new BorderLayout());

sb = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,255);
sb1 = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,255);
sb2 = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,255);

Label l = new Label("Red Color");
Label l1 = new Label("Green Color");
Label l2 = new Label("Blue Color");
l3 = new Label();
l4 = new Label();
l5 = new Label();

c =new C();

Panel p = new Panel();
Panel p1 = new Panel();
p.setLayout(new GridLayout(6,1));
p.add(l);
p.add(sb);
p.add(l1);
p.add(sb1);
p.add(l2);
p.add(sb2);
add(c,"Center");
add(p,"North");
p1.setLayout(new GridLayout(1,3));
p1.add(l3);
p1.add(l4);
p1.add(l5);
add(p1,"South");
c.setSize(100,100);

sb.addAdjustmentListener(this);
sb1.addAdjustmentListener(this);
sb2.addAdjustmentListener(this);

l3.setText("Red :: "+sb.getValue());
l4.setText("Green ::"+sb1.getValue());
l5.setText("Blue ::"+sb2.getValue());
}
public void adjustmentValueChanged(AdjustmentEvent e)
{
c.rgb(sb.getValue(),sb1.getValue(),sb2.getValue());
c.repaint();

l3.setText("Red :: "+sb.getValue());
l4.setText("Green ::"+sb1.getValue());
l5.setText("Blue ::"+sb2.getValue());
}
}

No comments: