0% found this document useful (0 votes)
8 views

Java Practical6

Uploaded by

Priyanka Thadke
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)
8 views

Java Practical6

Uploaded by

Priyanka Thadke
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/ 5

Name:- Priyanka Khandu Thadke

Class:-A(CO5I) Roll no:- 60


Practical no:-06 Write a java Program using swing to display a ScrollPane and JCombobox in
an JApplet with the items-English , Marathi , Hindi , Sanskrit.

Program Code:-
Q.1) Write a program code to generate following output.
Program:-
import java.awt.*; import

javax.swing.*; import

java.awt.event.ItemEvent; import

java.awt.event.ItemListener;

public class ComboBoxE1 extends JFrame implements ItemListener{

JLabel l1;

public ComboBoxE1()

JComboBox cb = new JComboBox();

cb.addItem("Solapur");

cb.addItem("Pune");

cb.addItem("Banglore");

cb.addItem("Mumbai");

cb.addItemListener(this);

l1 = new JLabel();

add(cb);

add(l1);

setSize(300,200);

setVisible(true);
setLayout(new FlowLayout());

public void itemStateChanged(ItemEvent ie)

String stateName = (String) ie.getItem();

l1.setText("You are in" +stateName);

public static void main(String[] args)

{ new ComboBoxE1();

Output:-
Exercise:-
Q.1) Write a program to develop a frame to select the different states of India using
JComboBox.
Program:-
import java.awt.*;

import javax.swing.JComboBox;

import javax.swing.JFrame;

public class ComboBoxE2 extends JFrame{ public ComboBoxE2()

String s[]= {"Maharashtra","Rajastan","Gujrat","Punjab","Goa","Tamilnadu"};

JComboBox cb = new JComboBox<>(s);

cb.addItem("Maharashtra");

cb.addItem("Punjab");

cb.addItem("Rajastan");

cb.addItem("Goa");

cb.addItem("Gujrat");

add(cb);

setSize(300,200);

setLayout(new FlowLayout());

setVisible(true);

public static void main(String[] args) { new ComboBoxE2();

}
Output:-

Q.2) Develop a program to demonstrate the use of ScrollPane in Swings.


Program:-
import java.awt.*;

import javax.swing.*;

import javax.swing.JFrame;

import javax.swing.JTextArea;

import javax.swing.JTextArea;

public class ScrollPaneE3 extends JFrame{ public ScrollPaneE3()

setSize(400,300);

setVisible(true);

setDefaultCloseOperation(EXIT_ON_CLOSE);

getContentPane().setLayout(new FlowLayout());

JTextArea ta = new JTextArea(20,20);


JScrollPane s1 = new JScrollPane(ta);

s1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

s1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

getContentPane().add(s1);

public static void main(String[] args) {

new ScrollPaneE3();

Output:-

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy