Pratical:-1
1. Write a program to demonstrate the use of AWT components .
import [Link].*;
public class BasicAWT extends Frame{
public static void main(String args[])
{
Frame f=new Frame();
[Link](400,400);
[Link](true);
[Link](new FlowLayout());
[Link]([Link]);
Label l1=new Label();
[Link]("Enter your name");
//[Link](20,50,30,30);
TextField tf= new TextField("Shreya");
//[Link](20,50,20,50);
Label l2=new Label ("Address");
TextArea ta = new TextArea ("",3,40);
Button b = new Button ("Submit");
Label l4 = new Label("Select subject");
//[Link](100,100,100,110);
Checkbox cb1 = new Checkbox("english");
Checkbox cb2 = new Checkbox("marathi");
Checkbox cb3 = new Checkbox("hindi");
Checkbox cb4 = new Checkbox("history");
Label l5= new Label ("Select gender");
CheckboxGroup cg = new CheckboxGroup ();
Checkbox c1 = new Checkbox("Male",cg,true);
Checkbox c2 = new Checkbox("Female",cg,true);
[Link](l1);
[Link](tf);
[Link](l4);
[Link](cb1);
[Link](cb2);
[Link](cb3);
[Link](cb4);
[Link](l5);
[Link](c1);
[Link](c2);
[Link](l2);
[Link](ta);
[Link](b);
}
}
Pratical:-2
1. Write a program to design a form using the component list and choice.
import [Link].*;
public class ChoiceDemo
{
public static void main(String args[])
{
Frame f = new Frame();
[Link](400,400);
[Link](true);
[Link](new FlowLayout());
Choice c = new Choice();
[Link]("Maths");
[Link]("Physics");
[Link]("Chemistry");
Label la=new Label("LIST Component");
List l = new List();
//[Link](true);
[Link]("The Times of India");
[Link]("Lokmat");
[Link]("Divya Marathi");
[Link]("Navbharat Times");
[Link](la);
[Link](l);
[Link](c);
}
}
Pratical:-3
1. Write a program to design simple calculator with the use of Grid layout.
import [Link].*;
import [Link].*;
public class MyGridLayout{
JFrame f;
MyGridLayout(){
f=new JFrame();
JButton b1=new JButton("1");
JButton b2=new JButton("2");
JButton b3=new JButton("3");
JButton b4=new JButton("4");
JButton b5=new JButton("5");
JButton b6=new JButton("6");
JButton b7=new JButton("7");
JButton b8=new JButton("8");
JButton b9=new JButton("9");
// adding buttons to the frame
[Link](b1); [Link](b2); [Link](b3);
[Link](b4); [Link](b5); [Link](b6);
[Link](b7); [Link](b8); [Link](b9);
// setting grid layout of 3 rows and 3 columns
[Link](new GridLayout(3,3));
[Link](300,300);
[Link](true);
}
public static void main(String[] args) {
new MyGridLayout();
}
}
Pratical:-4
Using of CardLayout to write a program to create a two-level card deck that
allows the user to select an operating system.
import [Link].*;
import [Link].*;
import [Link];
import [Link].*;
public class CardLayoutDemo extends JFrame implements ActionListener {
CardLayout card;
JButton b1, b2, b3;
Container c;
CardLayoutDemo()
{
c = getContentPane();
card = new CardLayout(40, 30);
[Link](card);
b1 = new JButton("First Level");
b2 = new JButton("Second Level");
[Link](this);
[Link](this);
[Link]("a", b1);
[Link]("b", b2);
}
public void actionPerformed(ActionEvent e)
{
[Link](c);
}
public static void main(String[] args)
{
CardLayoutDemo cl = new CardLayoutDemo();
[Link](400, 400);
[Link](true);
[Link](EXIT_ON_CLOSE);
}
}
Pratical:-5
1. Write a program using AWT to create a menu bar where menu bar
contains menu items .
import [Link].*;
class MenuExample
{
MenuExample(){
Frame f= new Frame("Menu and MenuItem Example");
MenuBar mb=new MenuBar();
Menu menu=new Menu("Menu");
Menu submenu=new Menu("Sub Menu");
MenuItem i1=new MenuItem("Item 1");
MenuItem i2=new MenuItem("Item 2");
MenuItem i3=new MenuItem("Item 3");
MenuItem i4=new MenuItem("Item 4");
MenuItem i5=new MenuItem("Item 5");
[Link](i1);
[Link](i2);
[Link](i3);
[Link](i4);
[Link](i5);
[Link](submenu);
[Link](menu);
[Link](mb);
[Link](400,400);
[Link](null);
[Link](true);
}
public static void main(String args[])
{
new MenuExample();
}
}
}
Pratical:-6
1. Write a program using swig to display a Scrollpane and jcomboBox in an
japple.
import [Link].*;
import [Link].*;
import [Link];
import [Link];
public class JComboBoxDemo extends JApplet implements ItemListener
{
JLabel JLabelObj ;
public void init()
{
setLayout(new FlowLayout());
setSize(400, 400);
setVisible(true);
JComboBox JComboBoxObj = new JComboBox();
[Link]("Solapur");
[Link]("Pune");
[Link]("Banglore");
[Link]("Mumbai");
[Link](this);
JLabelObj = new JLabel();
add(JComboBoxObj);
add(JLabelObj);
}
public void itemStateChanged(ItemEvent ie)
{
String stateName = (String) [Link]();
[Link]("You are in "+stateName);
}
}
/* <applet code="JComboBoxDemo" height="400" width="400"> </applet> */
Pratical:7
1. Write a program to create a JTree.
import [Link].*;
import [Link].*;
import [Link].*;
public class JTreeDemo
{
public static void main(String[] args) {
JFrame JFrameMain = new JFrame();
[Link](true);
[Link](400,400);
DefaultMutableTreeNode rootNode = new
DefaultMutableTreeNode("India");
DefaultMutableTreeNode maharashtraNode = new
DefaultMutableTreeNode("Maharashtra");
DefaultMutableTreeNode gujrathNode = new
DefaultMutableTreeNode("Gujrath");
[Link](maharashtraNode);
[Link](gujrathNode);
DefaultMutableTreeNode mumbaiSubNode = new
DefaultMutableTreeNode("Mumbai");
DefaultMutableTreeNode puneSubNode = new
DefaultMutableTreeNode("Pune");
DefaultMutableTreeNode nashikSubNode = new
DefaultMutableTreeNode("Nashik");
DefaultMutableTreeNode nagpurSubNode = new
DefaultMutableTreeNode("Nagpur");
[Link](mumbaiSubNode);
[Link](puneSubNode);
[Link](nashikSubNode);
[Link](nagpurSubNode);
JTree tree = new JTree(rootNode);
[Link](tree);
}
}
Pratical:-8
1. Write a program to create a JTable.
import [Link].*;
import [Link].*;
import [Link].*;
public class JTableDemo
{
public static void main(String[] args)
{
JFrame JFrameMain = new JFrame();
[Link](true);
[Link](400,400);
String colHeads[] = {"ID","Name","Salary"};
Object data[][] = {
{101,"Amit",670000},
{102,"Jai",780000},
{101,"Sachin",700000}
};
JTable JTableObj = new JTable(data,colHeads);
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(JTableObj,v,h);
[Link](jsp,[Link]);
//[Link](JTableObj);
}
}
Pratical:-9
1. Write a program to launch a JProgressBar
import [Link].*;
import [Link].*;
public class JProgresBarDemo
{
JProgressBar JProgressBarObj;
int i=0,num=0;
JProgresBarDemo()
{
JFrame JFrameMain = new JFrame();
[Link](true);
[Link](400,400);
[Link](new FlowLayout());
JProgressBarObj = new JProgressBar(0,2000);
[Link](0);
[Link](true);
[Link](JProgressBarObj);
}
public static void main(String[] args)
{
JProgresBarDemo jpd = new JProgresBarDemo();
[Link]();
}
public void iterate()
{
while(i<=2000){
[Link](i);
i =i+20;
try
{
[Link](150);
}
catch(Exception e)
{
}
}
}
}