0% found this document useful (0 votes)
77 views2 pages

Practical - 6.1 // Write A Prgram To Devlope A Frame To Selecte The Different Satest of Indian Using Jcombobox

This document contains code for two Java programs. The first program develops a frame to select different states of India using a JComboBox. It creates a JComboBox with state names, adds it to a JFrame along with a label, and updates the label text when a new item is selected from the dropdown. The second program demonstrates the use of a JScrollPane in Swing. It adds multiple JTextFields to a JPanel in a grid layout, places the panel inside a JScrollPane, and adds scrollbars that always display.

Uploaded by

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

Practical - 6.1 // Write A Prgram To Devlope A Frame To Selecte The Different Satest of Indian Using Jcombobox

This document contains code for two Java programs. The first program develops a frame to select different states of India using a JComboBox. It creates a JComboBox with state names, adds it to a JFrame along with a label, and updates the label text when a new item is selected from the dropdown. The second program demonstrates the use of a JScrollPane in Swing. It adds multiple JTextFields to a JPanel in a grid layout, places the panel inside a JScrollPane, and adds scrollbars that always display.

Uploaded by

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

Practical -6.

// write a prgram to devlope a frame to selecte the different satest of indian


using JCombobox

import java.swing*;.

import java.awt.event.*;
public class ComboBoxExample implements ItemListener
{
JFrame f;
JLabel l;
ComboBoxExample()
{
l=new JLabel("This");
f=new JFrame("ComboBox Example");
String c[]={"Solapur","Pune","Banglore","Mumbai"};
JComboBox cb=new JComboBox(c); cb.setBounds(50,
50,90,20);
cb.addItem("Nashik");
cb.addItem("Nagar");
cb.addItemListener(this);
f.add(l);
l.setBounds(10, 10, 500,500);
f.add(cb);
f.setLayout(null);
f.setSize(400,500);
f.setVisible(true);
}
public void itemStateChanged(ItemEvent e)
{
String a=(String) e.getItem();
l.setText("your choice is " + a );
}
public static void main(String[] args) {
new ComboBoxExample();
}
}

practical 6.2
//Develpoe a program to demonstrate the use of scrollpane in swing
import java.awt.*;
import javax.swing.*;
public class JScrollDemo extends JApplet
{
public void init()
{
Container c=getContentPane(); JPanel
j=new JPanel(); j.setLayout(new
GridLayout(20,20)); for(int outer=0;
outer<=15;outer++)
{
for(int inner=0;inner<=15;inner++)
{
j.add(new JTextField("TextField" +outer+ "," +inner));
}
}
JScrollPane jsp=new JScrollPane(j);
jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ ALWAYS);
jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
c.add(jsp);
}
}
/*<appletcode=”JScrollDemo”
width=400 height=400>
</applet> */

You might also like