Thursday, July 29, 2010

CORE JAVA PROJECT

import  java.applet.*;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

/*<applet  code="fontadjust"  width=800 height=500>

</applet>*/

public class  fontadjust  extends Applet implements ActionListener,ComponentListener,AdjustmentListener,KeyListener

{

TextField t;

Button r1,r2,r3;

Button move,size,hide,show,submit,col;

Scrollbar redbar,greenbar,bluebar;

Label red,green,blue;

int x,y,w,h,s;

Font f;

Label l,l1;

public void init()

{

setLayout(null);

l1=new Label("PROGRAM BY KRISHNAPRASAD AND VINAYKUMAR");

l1.setBounds(350,450,290,10);

add(l1);

t=new TextField();

red=new Label("red:0");

green=new Label("green:0");

blue=new Label("blue:0");

redbar=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,256);

greenbar=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,256);

bluebar=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,256);

add(red);

red.setBounds(10,370,70,30);

add(green);

green.setBounds(90,370,70,30);

add(blue);

blue.setBounds(190,370,70,30);

add(redbar);

redbar.setBounds(10,400,70,30);

add(greenbar);

greenbar.setBounds(90,400,70,30);

add(bluebar);

bluebar.setBounds(190,400,70,30);

redbar.addAdjustmentListener(this);

greenbar.addAdjustmentListener(this);

bluebar.addAdjustmentListener(this);

submit=new Button("submit");

add(t);

add(submit);

t.setBounds(20,10,250,30);

submit.setBounds(50,60,70,30);

submit.addActionListener(this);

move=new Button("move");

size=new Button("size");

hide=new Button("hide");

show=new Button("show");

x=10;

y=10;

w=100;

h=30;

add(move);

move.setBounds(10,450,70,30);

add(size);

size.setBounds(90,450,70,30);

add(hide);

hide.setBounds(190,450,70,30);

add(show);

show.setBounds(270,450,70,30);

col=new Button("colors");

col.setBounds(450,30,70,30);

add(col);

col.addActionListener(this);

move.addActionListener(this);

size.addActionListener(this);

hide.addActionListener(this);

show.addActionListener(this);

submit.addKeyListener(this);

t.addKeyListener(this);

t.requestFocus();



}

public void keyPressed(KeyEvent ke)

{

if(ke.getSource()==submit)

if (ke.getKeyCode()==KeyEvent.VK_ENTER)

{

l=new Label(t.getText());

add(l);

l.setBounds(20,10,100,30);

f=new Font("Times New Roman",Font.ITALIC,10);

s=10;

l.setFont(f);

l.addComponentListener(this);

remove(submit);

remove(t);

}

}

public void keyReleased(KeyEvent ke)

{

if(ke.getSource()==t)

{

if(ke.getKeyCode()==KeyEvent.VK_F1)

{

Color c=getBackground();

if(c!=Color.red)

setBackground(Color.red);

else

setBackground(Color.white);

}

if(ke.getKeyCode()==KeyEvent.VK_F2)

{

Color c=getBackground();

if(c!=Color.green)

setBackground(Color.green);

else

setBackground(Color.white);

}

if(ke.getKeyCode()==KeyEvent.VK_F3)

{

Color c=getBackground();

if(c!=Color.blue)

setBackground(Color.blue);

else

setBackground(Color.white);

}

}

}

public void keyTyped(KeyEvent ke){}

public  void componentResized(ComponentEvent ce)

{

s=s+1;

f=new Font("Times New Roman",Font.ITALIC,s);

l.setFont(f);

}

public  void componentMoved(ComponentEvent ce)

{

}

public  void componentHidden(ComponentEvent ce)

{

}

public  void componentShown(ComponentEvent ce)

{

}

public void actionPerformed(ActionEvent ae)

{

if(ae.getSource()==submit)

{

showStatus("copyrights reserved");

l=new Label(t.getText());

add(l);

l.setBounds(20,10,100,30);

f=new Font("Times New Roman",Font.ITALIC,10);

s=10;

l.setFont(f);

l.addComponentListener(this);

remove(submit);

remove(t);

}

else if(ae.getSource()==move)

{

x=x+30;

if(x>=400)

{

y=y+10;

x=10;

}

l.setLocation(x,y);

}

else if(ae.getSource()==size)

{

w=w+10;

h=h+5;

l.setSize(w,h);

}

else if(ae.getSource()==hide)

l.setVisible(false);

else if(ae.getSource()==col)

{



r1=new Button("red");

r1.setBackground(Color.red);

r1.setBounds(450,30,70,30);

add(r1);

r2=new Button("green");

r2.setBackground(Color.green);

r2.setBounds(450,70,70,30);

add(r2);

r3=new Button("blue");

r3.setBackground(Color.blue);

r3.setBounds(450,110,70,30);

add(r3);

r1.addActionListener(this);

r2.addActionListener(this);

r3.addActionListener(this);

remove(col);

}

else if(ae.getSource()==r1)

{

Color c=getBackground();

if(c!=Color.red)

{

setBackground(Color.red);

l.setBackground(Color.red);

}

else

{

setBackground(Color.white);

l.setBackground(Color.white);

}

}

else if(ae.getSource()==r2)

{

Color c=getBackground();

if(c!=Color.green)

{

setBackground(Color.green);

l.setBackground(Color.green);

}

else

{

setBackground(Color.white);

l.setBackground(Color.white);

}

}

else if(ae.getSource()==r3)

{

Color c=getBackground();

if(c!=Color.blue)

{

setBackground(Color.blue);

l.setBackground(Color.blue);

}

else

{

setBackground(Color.white);

l.setBackground(Color.white);

}

}

else

l.setVisible(true);

}

public void adjustmentValueChanged(AdjustmentEvent ae)

{

red.setText("red:"+redbar.getValue());

green.setText("green:"+greenbar.getValue());

blue.setText("blue:"+bluebar.getValue());

Color c=new Color(redbar.getValue(),greenbar.getValue(),bluebar.getValue());

l.setForeground(c);

}

}





No comments:

Post a Comment

FOLLOWERS