0% found this document useful (0 votes)
15 views6 pages

Ajp Prac 6

Uploaded by

saeedarwatkar
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)
15 views6 pages

Ajp Prac 6

Uploaded by

saeedarwatkar
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/ 6

Practical No.

6
 Program code: Write a program code to generate the following output.
importjava.awt.*;

import javax.swing.*;

/*<applet code="combo1" width=500 height=500></applet>*/

public class combo1 extends JApplet

public void init()

Container c=getContentPane();

JLabel l=new JLabel("You are in Mumbai");

c.setLayout(new FlowLayout());

JComboBoxcb=new JComboBox();

cb.addItem("Solapur");

cb.addItem("Pune");

cb.addItem("Bangalore");

cb.addItem("Mumbai");

c.add(l);

c.add(cb);

}
Output
 Exercise:

1) Write a program to develop a frame to select the different states of india using
JComboBox.

import javax.swing.*;

import java.awt.*;

public class saee_combo1

public static void main(String[] args)

JFrame f = new JFrame("saee_combo1");

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.setSize(300, 150);

JComboBox jcb = new JComboBox();

jcb.addItem("Maharashtra");

jcb.addItem("Gujarat");

jcb.addItem("Rajasthan");

jcb.addItem("Kerala");

jcb.addItem("Tamil Nadu");

jcb.addItem("West Bengal");

f.add(jcb);

f.setLayout(new FlowLayout());

f.setVisible(true);

}
Output:
2) Develop a program to demonstrate the use of JScrollPane.

import java.awt.*;

import javax.swing.*;

import javax.swing.tree.*;

/*<applet code="saee_jtree1" width=500 height=500></applet>*/

public class saee_jtree1 extends JApplet

public void init()

Container c=getContentPane();

DefaultMutableTreeNode r=new DefaultMutableTreeNode("India");

DefaultMutableTreeNode a=new DefaultMutableTreeNode("Maharashtra");

DefaultMutableTreeNode a1=new DefaultMutableTreeNode("Mumbai");

DefaultMutableTreeNode a2=new DefaultMutableTreeNode("Pune");

DefaultMutableTreeNode a3=new DefaultMutableTreeNode("Nashik");

DefaultMutableTreeNode a4=new DefaultMutableTreeNode("Nagpur");

DefaultMutableTreeNode b=new DefaultMutableTreeNode("Gujrat");

a.add(a1);

a.add(a2);

a.add(a3);

a.add(a4);

r.add(a);

r.add(b);

JTree jt=new JTree(r);


int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;

int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;

JScrollPane jsp=new JScrollPane(jt,v,h);

c.add(jsp);

Output:

You might also like