0% found this document useful (0 votes)
50 views36 pages

AJP Practical Program 7

The document describes an applet program that uses checkboxes and radio buttons. It imports the necessary packages and defines a Demo class that extends Applet. In the init() method, it sets the layout to null and creates a CheckboxGroup. It then creates several Checkbox objects with different labels and adds them to the applet. It similarly creates Checkbox objects without a group and adds them. Finally, it sets the bounds of each component and adds them to the applet. The output includes the applet tag to run the program.

Uploaded by

umeshsabale.2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views36 pages

AJP Practical Program 7

The document describes an applet program that uses checkboxes and radio buttons. It imports the necessary packages and defines a Demo class that extends Applet. In the init() method, it sets the layout to null and creates a CheckboxGroup. It then creates several Checkbox objects with different labels and adds them to the applet. It similarly creates Checkbox objects without a group and adds them. Finally, it sets the bounds of each component and adds them to the applet. The output includes the applet tag to run the program.

Uploaded by

umeshsabale.2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

*/=============================

radio button & checkbox


x] Q1.ans

=============================*/
import java.awt.*;
import java.applet.*;
public class Demo extends Applet
{
public void init()
{
setLayout(null); CheckboxGroup cbg=new
CheckboxGroup();

Checkbox c1= new


Checkbox("Male",true,cbg);
Checkbox c2=new
Checkbox("female",false,cbg);
Checkbox c3=new
Checkbox("Other",false,cbg);
Checkbox b1=new Checkbox("India",true);
Checkbox b2=new Checkbox("America");
Checkbox b3=new Checkbox("Awasari");
c1.setBounds(100,100,150,40);
c2.setBounds(100,130,170,30);
c3.setBounds(100,160,150,40);
b1.setBounds(100,190,150,40);
b2.setBounds(100,220,150,40);
b3.setBounds(100,250,40,40);
add(b1); add(b2); add(b3);
add(c1); add(c2); add(c3);
}
}

/* <applet code=”Demo.class” width=”500”


height”500”> </applet>*/
__________________________________
OUTPUT:
/*=============================
Devlop applet form using Label,
x] Q2.ans

Button,TextField and Textarea


=============================*/
import java.awt.*;
import java.applet.*;
public class Demo extends Applet
{
public void init()
{
setLayout(null);
Label L1=new Label("enter your name");
TextField t1=new TextField(10);
Label L2=new Label("enter feedback");
TextArea ta1=new TextArea(15,15);
Button b1=new Button(“submit”);
l1.setBounds(100,100,150,40);
t1.setBounds(250,100,150,40);
l2.setBounds(100,250,150,40);
ta1.setBounds(250,250,150,40);
b1.setBounds(300,400,150,40);
add(L1);add(L2);add(t1);add(ta1);
add(b1);
}
}

/* <applet code=”Demo.class”
width=”500” height”500”> </applet>*/
__________________________________
OUTPUT:
*/==============================
devlop program using label to display
1.1]

“welcome to java message”


==============================*/
import java.awt.*;
class LabelDemo extends Frame
{
LabelDemo() {
FlowLayout f1=new FlowLayout();
setLayout(f1);
Label L1=new Label("welcome to java");
L1.setBackground(Color.cyan);
add(L1);}
public static void main(String args[]) {
LabelDemo id=new LabelDemo();
id.setVisible(true);
id.setTitle("label");
id.setSize(500,500);
}}
OUTPUT:
/*============================
1.2] Devlop a program to select multiple
language( e.g marathi,hindi,english,
sanskrit)
============================*/
import java.awt.*;
class ChoiceDemo extends Frame
{
ChoiceDemo()
{
setBackground(Color.cyan);
setForeground(Color.black);
FlowLayout f1=new FlowLayout();
setLayout(f1);
Choice c1=new Choice();
c1.add("marathi");
c1.add("hindi");
c1.add("english");
c1.add("sanskrit");
add(c1);
}
public static void main(String args[])
{
ChoiceDemo cd=new ChoiceDemo();
cd.setVisible(true);
cd.setTitle("Choice Contrl");
cd.setSize(500,500);
}
}
__________________________________

OUTPUT:
/*===============================
1.3] create a three button ok cancle rest
===============================*/
import java.awt.*;
class buttonDemo extends Frame
{
buttonDemo()
{ FlowLayout f1=new FlowLayout();
setLayout(f1);
setBackground(Color.cyan);
Button b1=new Button("Ok");
Button b2=new Button("REST");
Button b3=new Button("CANCLE");
add(b1); add(b2); add(b3);
}
public static void main(String args[])
{
buttonDemo fd=new buttonDemo();
fd.setVisible(true); fd.setTitle("Buttons");
fd.setSize(500,500);
}
}
________________________________
OUTPUT :

__________________________________
/*===========================*/
X] -->
import java.awt.*;
import java.applet.*;
public class listDemo extends Applet
{
public void init() {
List L2=new List(3,true);
L2.add("Summer");
L2.add("Winter");
L2.add("Rainy");
add(L2);
}}
/* <applet code=”listDemo.class”
width=”500” height”500”> </applet>*/
_________________________________
OUTPUT:
/*=============================
2.1] Devlop a applet application using list

component to add name of 10 differnt city


=============================*/
import java.awt.*;
import java.applet.*;
public class listDemo extends Applet
{
public void init()
{
List L2=new List(3,true);
L2.add("Pune");
L2.add("Awasari");
L2.add("Mumbai");
L2.add("Nagar");
L2.add("Solapur");
L2.add("Tuljapur");
L2.add(“nashik”);
L2.add(“mumabi ”);
L2.add(“tamilnadu”);
L2.add(“utter pradesh”);
add(L2);
}
}
/* <applet code=”listDemo.class”
width=”500” height”500”> </applet>*/
__________________________________

OUTPUT :

__________________________________
/*=============================
2.2] Devlop a applet application using list

component to select multiple name of


news paper
=============================*/
import java.awt.*;
import java.applet.*;
public class news extends Applet
{
public void init()
{
List L2=new List(3,true);
L2.add("lokmat");
L2.add("pudhari");
L2.add(“kesri");
L2.add("india");
L2.add("sport news");
L2.add("the sun");
L2.add(“daily mail”);
add(L2);
}
}
/* <applet code=”news.class”
width=”500” height”500”> </applet>*/
__________________________________

OUTPUT :

__________________________________
/*=============================
write a java program to Demostret Grid 5*5
=============================*/
import java.awt.*;
class GridLayoutDemo extends Frame
{
GridLayoutDemo()
{
GridLayout g1=new GridLayout(5,5);
setLayout(g1);
for(int i=1;i<25;i++)
{
add(new Button(""+i));
}}
public static void main(String args[]) {
GridLayoutDemo gd=new
GridLayoutDemo();
gd.setVisible(true);
gd.setTitle("FlowLayout Manager");
gd.setSize(500,500);
}
}
OUTPUT :-

__________________________________
/*=============================
display the numer on button form 0 to 9
=============================*/
import java.awt.*;
class GridLayoutDemo extends Frame
{
GridLayoutDemo()
{
GridLayout g1=new GridLayout(4,3);
setLayout(g1);
for(int i=0;i<=9;i++)
{
add(new Button(""+i));
}
}
public static void main(String args[])
{
GridLayoutDemo gd=new
GridLayoutDemo();
gd.setVisible(true);
gd.setTitle("FlowLayout Manager");
gd.setSize(500,500);
}
}
__________________________________

OUTPUT :-

__________________________________
/*===========================
3.1] GridLayout
=============================*/
import java.awt.*;
class GridLayoutDemo extends Frame
{
GridLayoutDemo()
{
GridLayout g1=new
GridLayout(4,3,10,10);
setLayout(g1);
for(int i=1;i<=5;i++)
{
add(new Button("Button"+i));
}
}
public static void main(String args[])
{
GridLayoutDemo gd=new
GridLayoutDemo();
gd.setVisible(true);
gd.setTitle("FlowLayout Manager");
gd.setSize(800,800);
}
}
__________________________________
OUTPUT:-

__________________________________
/*=============================
3.2] Border Layout
=============================*/
import java.awt.*;
class BorderLayoutDemo extends Frame
{
BorderLayoutDemo()
{
BorderLayout bl=new BorderLayout();
setLayout(bl);

Button b1=new Button("EAST REGION");


Button b2=new Button("WEST REGION");
Button b3=new Button("SOUTH
REGION");
Button b4=new Button("NORTH
REGION");
Button b5=new Button(" CENTER");
add(b1,BorderLayout.EAST);
add(b2,BorderLayout.WEST);
add(b3,BorderLayout.SOUTH);
add(b4,BorderLayout.NORTH);
add(b5,BorderLayout.CENTER);
}
public static void main(String args[])
{
BorderLayoutDemo bld=new
BorderLayoutDemo();
bld.setVisible(true);
bld.setTitle("BorderLayout Demo");
bld.setSize(500,500);
}}
__________________________________
OUTPUT :-

__________________________________
/*=============================
5] create menu of color and disable menu

item for black color


=============================*/
import java.awt.*;
class notepad1 extends Frame{
notepad1()
{
FlowLayout f1=new FlowLayout();
setLayout(f1);

Menu m1=new Menu("Color");

MenuItem m11=new
MenuItem("REd");
MenuItem m12=new
MenuItem("Orange");
MenuItem m13=new
MenuItem("black");
m13.setEnabled(false);
MenuItem m14=new
MenuItem("orange");
m1.add(m11);
m1.add(m12);
m1.add(m13);
m1.add(m14);
MenuBar mbr=new MenuBar();
mbr.add(m1);
setMenuBar(mbr); }
public static void main(String args[])
{
notepad1 n=new notepad1();
n.setVisible(true);
n.setTitle("notepad");
n.setSize(600,600);
}}
__________________________________
OUTPUT:-
6 x ->
__________________________________
import java.awt.*;
import javax.swing.*;
class JComboBoxDemo extends JFrame
{
JComboBoxDemo()
{
Container c=getContentPane();
FlowLayout f1=new FlowLayout();
c.setLayout(f1);
c.setBackground(Color.orange);
JComboBox jcb=new JComboBox();
Label l1=new Label(“you are in mumbai”);
jcb.addItem("Mumbai");
jcb.addItem("solapur");
jcb.addItem("banglore");
jcb.addItem("mumbai");
c.add(jcb);
add(l1);
}
public static void main(String args[])
{
JComboBoxDemo j1=new
JComboBoxDemo();
j1.setVisible(true);
j1.setTitle("JComboBox Demo");
j1.setSize(800,800);
j1.setDefaultCloseOperation(JFrame.EXI
T_ON_CLOSE);
}}
__________________________________
OUTPUT:-
/*=============================
6.1 Q. write a program frame to select

differnt state of india using jcombobox


=============================*/
import java.awt.*;
import javax.swing.*;
class JComboBoxDemo extends JFrame
{
JComboBoxDemo()
{
Container c=getContentPane();
FlowLayout f1=new FlowLayout();
c.setLayout(f1);
c.setBackground(Color.orange);
JComboBox jcb=new JComboBox();
jcb.addItem("bihar");
jcb.addItem("Maharashtra");
jcb.addItem("Rajstan");
jcb.addItem("tamil nadu");
c.add(jcb);
}
public static void main(String args[])
{
JComboBoxDemo j1=new
JComboBoxDemo();
j1.setVisible(true);
j1.setTitle("JComboBox Demo");
j1.setSize(800,800);
j1.setDefaultCloseOperation(JFrame.EXI
T_ON_CLOSE);
}}
__________________________________
OUTPUT:-
/*=============================
6.2 Q. devlop a program demostrate the use

of scroll pane
=============================*/
import java.awt.*;
import javax.swing.*;
class JScrollPaneDemo extends JFrame
{
JScrollPaneDemo(){
Container c=getContentPane();
c.setBackground(Color.red);
JTextArea ta1=new JTextArea("Good
Morning Friends Have A Nice
Day");

int
v=ScrollPaneConstants.VERTICAL_SCROL
LBAR_AS_NEEDED;
int
h=ScrollPaneConstants.HORIZONTAL_SCR
OLLBAR_AS_NEEDED;
JScrollPane jsp=new JScrollPane(ta1,v,h);

c.add(jsp);}
public static void main(String args[]){
JScrollPaneDemo j1=new
JScrollPaneDemo();
j1.setVisible(true);
j1.setTitle("JScrollPane Demo");
j1.setSize(600,600);
j1.setDefaultCloseOperation(EXIT_ON_CLO
SE);
}}
__________________________________
OUTPUT:-
/*=============================
7 .x] Q1. develop program the use of tree

component in swing
=============================*/
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
class JTreeNodeDemo extends JFrame{
JTreeNodeDemo()
{
Container c=getContentPane();
BorderLayout b1=new BorderLayout();
c.setLayout(b1);
DefaultMutableTreeNode root=new
DefaultMutableTreeNode("Language");
DefaultMutableTreeNode r1=new
DefaultMutableTreeNode("POP Lang");
DefaultMutableTreeNode r2=new
DefaultMutableTreeNode("OOP Lang");
root.add(r1);
root.add(r2);
DefaultMutableTreeNode r11=new
DefaultMutableTreeNode("C Lang");
DefaultMutableTreeNode r12=new
DefaultMutableTreeNode("PACAL Lang");
DefaultMutableTreeNode r13=new
DefaultMutableTreeNode("FORTRAN
Lang");
r1.add(r11);
r1.add(r12);
r1.add(r13);
JTree jt=new JTree(root);
int
v=ScrollPaneConstants.VERTICAL_SCROL
LBAR_AS_NEEDED;
int
h=ScrollPaneConstants.HORIZONTAL_SCR
OLLBAR_AS_NEEDED;
JScrollPane jsp=new JScrollPane(jt,v,h);
c.add(jsp,BorderLayout.WEST);
}
public static void main(String args[]){
JTreeNodeDemo j1=new JTreeNodeDemo();
j1.setVisible(true);
j1.setTitle("JTree Demo");
j1.setSize(600,600);

j1.setDefaultCloseOperation(JFrame.EXIT_O
N_CLOSE);
}}
__________________________________
OUTPUT:-
/*=============================
7 .x] Q2. Ans

=============================*/
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
class JTreeNodeDemo extends JFrame
{
JTreeNodeDemo()
{
Container c=getContentPane();
BorderLayout b1=new BorderLayout();
c.setLayout(b1);
DefaultMutableTreeNode root=new
DefaultMutableTreeNode("India");
DefaultMutableTreeNode r1=new
DefaultMutableTreeNode("Maharashtra");
DefaultMutableTreeNode r2=new
DefaultMutableTreeNode("Gujrat");
root.add(r1);
root.add(r2);
DefaultMutableTreeNode r11=new
DefaultMutableTreeNode("Mumbai");
DefaultMutableTreeNode r12=new
DefaultMutableTreeNode("Pune");
DefaultMutableTreeNode r13=new
DefaultMutableTreeNode("Nashik");
DefaultMutableTreeNode r14=new
DefaultMutableTreeNode("Nagpur");
r1.add(r11);
r1.add(r12);
r1.add(r13);
r1.add(r14);
JTree jt=new JTree(root);
int
v=ScrollPaneConstants.VERTICAL_SCROL
LBAR_AS_NEEDED;
int
h=ScrollPaneConstants.HORIZONTAL_SCR
OLLBAR_AS_NEEDED;
JScrollPane jsp=new JScrollPane(jt,v,h);
c.add(jsp,BorderLayout.WEST);
}
public static void main(String args[])
{
JTreeNodeDemo j1=new JTreeNodeDemo();
j1.setVisible(true);
j1.setTitle("JTree Demo");
j1.setSize(600,600);

j1.setDefaultCloseOperation(JFrame.EXIT_O
N_CLOSE);
}}
__________________________________
OUTPUT:-

You might also like