Thursday, 7 May 2015

GRID LAYOUT PROGRAM IN JAVA

import java.awt.*;
import java.applet.*;

/**
<appletcode=grid.class width=500 height=500>
</applet>
*/

public class grid extends Applet
{
Button b1,b2,b3,b4;
String result;

public void init()
{
b1=new Button(“one”);
b2=new Button(“two”);
b3=new Button(“three”);
b4=new Button(“four”);
setlayout(new gridLayout(2,2,10,10));

add(b1);
add(b2);
add(b3);
add(b4);
}

}



CARD LAYOUT PROGRAM IN JAVA

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

/**
<APPLET CODE=cardlayout.class  WIDTH=200  HEIGHT=200>
</APPLET>
*/

public class cardlayout extends Applet implements ActionListener
{
Checkbox win98,winnt,solaris,mac;
Panel oscards.winpan,otherpan;
CardLayout card;
Button win,other;

public void init()
{
win=new Button(“windows”);
other=new Button(“others”);

add(win);
add(other);

card=newCardLayot(10,10);
oscards=new Panel();
oscards.SetLayout(card);

win98=new Checkbox(“windows 98”);
winnt=new Checkbox(“windowsnt”);
solaris=new Checkbox(“solaris”);
mac=new Checkbox(“macos”);

winpan=new Panel();
winpan.add(win98);
winpan.add(winnt);

otherpan=new Panel();
otherpan=add(solaris);
otherpan.add(mac);
oscards.add(winpan,”windows”);
oscards.add(otherpan,”other”);
add(oscards);
win.addActionListener(this);
other.addActionListener(this);
}

public void actionPerformed(ActionEvent e)
{
if(e.getSource()==win)
{
card.show(oscards,”windows”);
}
else
{
card.show(oscards,”other”);
}
}

}


BORDER LAYOUT PROGRAM IN JAVA

import java.awt.*;
import java.applet.*;

/**
<applet code=borderlayout.class  width=500  height=500>
</applet>
*/

public class borderlayout extends Applet
{
Button b1,b2,b3.b4;
String result;

public void init()
{
b1=new Button(“one”);
b2=new Button(“two);
b3=new Button(“three”);
b4=new Button(“four”);
setLayout(new BorderLayout(10,10));

add(“North”,b1);
add(“East”,b2);
add(“West”,b3);
add(“South”,b4);
add(“Center”,newTextArea());
}

}


FLOW LAYOUT PROGRAM IN JAVA

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

/**
<appletcode=flowlayout.class width=500 height=500>
</applet>
*/

public class flowlayout extends Applet implements ActionListener
{
Button b1,b2,b3,b4;
String result;

public void init()
{
b1=new Button(“one”);
b2=new Button(“two”);
b3=new Button(“three”);
b4=new Button(“four”);
setLayout(new FlowLayout(FlowLayput.LEFT,10,10));

b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);

add(b1);
add(b2);
add(b3);
add(b4);
}

public void actionPerformed(ActionEvent e)
{
String str=e.getActionCommand();
if(str.equals(“one”))
{
result=”YOU CLICKED BUTTON ONE”;
repaint();
}
else if(str.equals(“two”))
{
result=”YOU CLICKED BUTTON TWO”;
repaint();
}
else if(str.equals(“three”))
{
result=”YOU CLICKED BUTTON THREE”;
repaint();
}
else
{
result=”YOU CLICKED BUTTON FOUR”;
repaint();
}
}

public void paint()
{
g.drawString(result,50,350);
}
}




LABEL,BUTTON,TEXT FIELD AND TEXT AREA PROGRAM IN JAVA

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

/**
<applet code=”LabelButtonDemo.class” width=500 height=500>
</applet>
*/
public class LabelButtonDemo extends Applet implements ActionListener
{
Label l;
Button b1;
String str;
FlowLayout f;
TextField t;
TextArea ta;

public void init()
{
f=new FlowLayout(FlowLayout.CENTER,240,18);
setLayout(f);
l=new Label(“Label”);
l.setBackground(color.gray);
l.setForeground(color.white);
t=new TextField(“Text”,20);
ta=new TextArea(“Welcome\nTo\nTextArea”,10,50,TextArea.SCROLLBARS_BOTH);
b1=new Button(“click”);
b1.addActionListener(this);
add(l);
add(b1);
add(t);
add(ta);
}
public void actionPerformed(ActionEvent e)
{
str=e.getActionCommand();
if(str==”click”)
{
l.setText(“I am Label”);
ta.append(“\nButton Clcked”);
t.setText(“Button Clicked”);

}}}



Monday, 4 May 2015

SCROLLBAR PROGRAM IN JAVA



import java.awt.*;
import java.awt.event.*;
import java.applet.*;

/**
<applet code=”ScrollDemo.class” width=500 height=500>
</applet>
*/

public class ScrollDemo extends Applet implements AdjustmentListener
{
Scrollbar red,green,blue;
Color c;
Object o;

public void init();
{
red=new Scroll(Scrollbar.HORIZONTAL,1,0,1,255);
green=new Scroll(Scrollbar.HORIZONTAL,1,0,1,255);
blue=new Scroll(Scrollbar.HORIZONTAL,1,0,1,255);

red.addAdjustmentListener(this);
green.addAdjustmentListener(this);
blue.addAdjustmentListener(this);

add(red);
add(green);
add(blue);
}

public void adjustmentValueChanged(AdjustmentEvent e)
{
c=new Color(red.getValue(),blue.getValue(),green.getValue());
setBackground(c);
}
}


CHECK BOX AND CHECKBOXGROUP PROGRAM IN JAVA



import java.applet.*;
import java.awt.*;
import java.awt.event.*;

/**<applet code=”CheckboxDemo.class” width=500 height=500>
</applet>
*/

public class CheckboxDemo extends Applet implements ItemListener
{
Color color;
Font f;

Checkbox fc1;
Checkbox fc2;
Checkbox fc3;

Checkbox fs1;
Checkbox fs2;
Checkbox fs3;

Checkbox fst1;
Checkbox fst2;
Checkbox fst3;

Checkbox cb1;
Checkbox cb2;
Checkbox cb3;

CheckboxGroup c1;
CheckboxGroup c2;
CheckboxGroup c3;

Object o;
public void init()
{
c1=new CheckboxGroup();
c2=new CheckboxGroup();
c3=new CheckboxGroup();

cb1=new Checkbox(“c1”,null,false);
cb2=new Checkbox(“c2”,null,false);
cb3=new Checkbox(“c3”,null,true);

fc1=new Checkbox(“RED”,c1,false);
fc2=new Checkbox(“GREEN”,c1,false);
fc3=new Checkbox(“BLUE”,c1,false);

fs1=new Checkbox(“15”,c2,false);
fs2=new Checkbox(“25”,c2,false);
fs3=new Checkbox(“35”,c2,false);

fst1=new Checkbox(“BOLD”,c3,false);
fst2=new Checkbox(“ITALIC”,c3,false);
fst3=new Checkbox(“PLAIN”,c3,false);

fc1.addItemListener(this);
fc2.addItemListener(this);
fc3.addItemListener(this);

fst1.addItemListener(this);
fst2.addItemListener(this);
fst3.addItemListener(this);

fs1.addItemListener(this);
fs2.addItemListener(this);
fs3.addItemListener(this);

cb1.addItemListener(this);
cb2.addItemListener(this);
cb3.addItemListener(this);

add(fc1);
add(fc2);
add(fc3);

add(fs1);
add(fs2);
add(fs3);

add(fst1);
add(fst2);
add(fst3);

add(cb1);
add(cb2);
add(cb3);
}

public void itemStateChanged(ItemEvent e)
{
o=e.getItemSelectable();
if(o==fc1)
{
color=Color.red;
repaint();
}
if(o==fc2)
{
color=Color.green;
repaint();
}
if(o==fc3)
{
color=Color.blue;
repaint();
}

if(o==fs1)
{
f=new Font(“TimesNewRoman”,Font.BOLD,15);
repaint();
}
if(o==fs2)
{
f=new Font(“TimesNewRoman”,Font.BOLD,25);
repaint();
}
if(o==fs3)
{
f=new Font(“TimesNewRoman”,Font.BOLD,35);
repaint();
}

if(o==fst1)
{
f=new Font(“TimesNewRoman”,Font.BOLD,15);
repaint();
}
if(o==fst2)
{
f=new Font(“TimesNewRoman”,Font.ITALIC,25);
repaint();
}
if(o==fst3)
{
f=new Font(“TimesNewRoman”,Font.PLAIN,35);
repaint();
}

if(o==cb1)
{
repaint();
}
if(o==cb2)
{
repaint();
}
if(o==cb3)
{
repaint();
}
}

public void paint(Graphics g)
{
g.setFont(f);
g.setColor(color);
g.drawString(“WELCOME TO APPLET”,0,200);
g.drawString(“Chechbox1 state”+cb1.getState(),0,300);
g.drawString(“Chechbox2 state”+cb2.getState(),0,380);
g.drawString(“Chechbox3 state”+cb3.getState(),0,450);
}
}