Professional Documents
Culture Documents
AJP Practical Program 7
AJP Practical Program 7
=============================*/
import java.awt.*;
import java.applet.*;
public class Demo extends Applet
{
public void init()
{
setLayout(null); CheckboxGroup cbg=new
CheckboxGroup();
/* <applet code=”Demo.class”
width=”500” height”500”> </applet>*/
__________________________________
OUTPUT:
*/==============================
devlop program using label to display
1.1]
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
OUTPUT :
__________________________________
/*=============================
2.2] Devlop a applet application using list
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);
__________________________________
/*=============================
5] create menu of color and disable menu
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
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:-