0% found this document useful (0 votes)
54 views4 pages

Ajp PR6

Uploaded by

Vighnesh Pote
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)
54 views4 pages

Ajp PR6

Uploaded by

Vighnesh Pote
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/ 4

Practical No.

6
Name: Pote Vighnesh Sandip Class: CO5I
Roll No: Batch: C

Title: Write program using swing to display a ScrollPane and JComboBox in an JApplet with
the items. – English, Marathi, Hindi, Sanskrit.

1. Write a program code to generate the following output.

Program:
package Practical6;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class PR6_1


{
public static void main(String[] args)
{
JFrame f=new JFrame("ComboBox Exaxmple");
f.setVisible(true);
f.setSize(400,400);
f.setLayout(new FlowLayout());
String city[]= {"Solapur","Pune","Banglore","Mumbai"};
JComboBox jc=new JComboBox(city);
f.add(jc);
JLabel L1=new JLabel();
String selectedIten=(String) jc.getSelectedItem();
L1.setText("You are in "+selectedIten);

jc.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String selectedIten = (String) jc.getSelectedItem();
L1.setText("You are in " + selectedIten);
}
});
f.add(L1);
}
}
Output:
2. Program to develop a frame to select Different states of India using JComboBox.

Program:

package Practical6;

import java.awt.*;
import javax.swing.*;

public class PR6_2


{
public static void main(String[] args)
{
Frame f = new Frame("Different States of India");
f.setSize(400,400);
f.setVisible(true);
f.setLayout(new FlowLayout());
String city[] =
{"Maharastra","Gujarat","Punjab","Tamilnadu","Bihar","Keral","UttarPradesh"};
JComboBox cb = new JComboBox(city);
f.add(cb);
}
}

Output:
3. Develop a program to demonstrate the use of ScrollPane in Swings.

Program:
package Practical6;

import java.awt.*;
import javax.swing.*;

public class PR6_3


{
public static void main(String[] args)
{
Frame f = new Frame("Use of ScrollPane Method");
f.setSize(400,400);
f.setVisible(true);
f.setLayout(new FlowLayout());
JTextArea t = new JTextArea("ScrollPane Example\n".repeat(10),10,15);
JScrollPane s1 = new JScrollPane(t);

s1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
s1.setVerticalScrollBarPolicy(JScrollPane. VERTICAL_SCROLLBAR_ALWAYS);
f.add(s1);
}
}

Output:

You might also like