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

Practical 6

Advance java

Uploaded by

noumangolandaj
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)
29 views6 pages

Practical 6

Advance java

Uploaded by

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

Practical 6

import javax.swing.*;

import java.awt.event.*;

public class p61 extends JFrame {

JFrame f;

p61(){

f=new JFrame();

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.setSize(300, 200);

String[] cities = {"Solapur", "Mumbai", "Pune", "Bangalore"};

JComboBox<String> cityComboBox = new JComboBox<>(cities);

JLabel cityLabel = new JLabel("Select a city");

cityComboBox.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

String selectedCity = (String) cityComboBox.getSelectedItem();

cityLabel.setText("You are in " + selectedCity);

});

f.setLayout(new java.awt.FlowLayout());

f.add(cityComboBox);

f.add(cityLabel);

// Make the frame visible

f.setVisible(true);

public static void main(String[] args) {

new p61();
}

OUTPUT:

import java.awt.event.*;

import javax.swing.*;
public class p62 extends JFrame {

JFrame f;

p62(){

f=new JFrame();

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.setSize(300, 200);

String[] states = {"Maharashtra", "Karnataka", "Gujarat", "Madhya


Pradesh","Rajasthan","Kerala","Telangana"};

JComboBox<String> cityComboBox = new JComboBox<>(states);

JLabel cityLabel = new JLabel("Select a State");

cityComboBox.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

String selectedCity = (String) cityComboBox.getSelectedItem();

cityLabel.setText("You are in " + selectedCity);

});

f.setLayout(new java.awt.FlowLayout());

f.add(cityComboBox);

f.add(cityLabel);

// Make the frame visible

f.setVisible(true);

public static void main(String[] args) {

new p62();

}
OUTPUT:

import javax.swing.*;

public class p63 {

public static void main(String[] args) {


// Create a new JFrame

JFrame frame = new JFrame("JScrollPane Example");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setSize(400, 300);

// Create a JPanel with a vertical BoxLayout

JPanel panel = new JPanel();

panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

// Add multiple labels to the panel

for (int i = 1; i <= 50; i++) {

panel.add(new JLabel("Label " + i));

// Create a JScrollPane and add the panel to it

JScrollPane scrollPane = new JScrollPane(panel);

// Add the JScrollPane to the frame

frame.add(scrollPane);

// Make the frame visible

frame.setVisible(true);

OUTPUT:

You might also like