100% found this document useful (1 vote)
2K views9 pages

1.write Java Program To Show Following Output

This document contains code examples demonstrating the use of various Java GUI components like List, Choice, GridLayout, FlowLayout, and BorderLayout. The examples show how to add items to lists and choices, lay out buttons in grids and flows, and position components in border layout areas. Output is generated displaying the selected or displayed items.

Uploaded by

Soham Parab
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
100% found this document useful (1 vote)
2K views9 pages

1.write Java Program To Show Following Output

This document contains code examples demonstrating the use of various Java GUI components like List, Choice, GridLayout, FlowLayout, and BorderLayout. The examples show how to add items to lists and choices, lay out buttons in grids and flows, and position components in border layout areas. Output is generated displaying the selected or displayed items.

Uploaded by

Soham Parab
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/ 9

X.

Program Code:
1.Write Java Program to show following output.
CODE:
package Experiment2;

import java.applet.Applet;
import java.awt.*;

public class ProgramCode1 extends Applet {


@Override
public void init() {
List c = new List(4);
c.add("Summer");
c.add("Winter");
c.add("Rainy");
add(c);
}
}
OUTPUT:
XIII. Exercise
1.Develop an applet/application using List components to add names
of 10 different cities.
CODE:
package Experiment2;

import java.applet.Applet;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

public class Exercise1 extends Applet {


Choice c = new Choice();
Label l1 = new Label();

@Override
public void init() {
c.add("Ulhasnagar");
c.add("Vashi");
c.add("Thane");
c.add("Shahad");
c.add("Kalyan");
c.add("Chembur");
c.add("Kurla");
c.add("Mulund");
c.add("Bhivandi");
c.add("Ambernarth");
add(c);
add(l1);
add(new Label("By Soham Parab"));
c.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
String msg = "Selected City: "+c.getSelectedItem();
l1.setText(msg);
}
});
}

@Override
public void paint(Graphics g) {
l1.setBounds(100,40,1000,20);
}
}
OUTPUT
2.Develop applet/application to select multiple names of news -
papers.
CODE:
package Experiment2;

import java.applet.Applet;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.sql.Array;
import java.util.Arrays;

public class Exercise2 extends Applet {


List list = new List(10,true);
Label l1 = new Label();

@Override
public void init() {
list.add("Times Of India");
list.add("Mumbai Mirror");
list.add("DNA");
list.add("Hinudstan Times");
list.add("The Indian Express");
add(list);
add(l1);
add(new Label("By Soham Parab"));
list.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
String[] msg = list.getSelectedItems();
l1.setText("Selected Newspapers:"+Arrays.toString(msg));
}
});
}

@Override
public void paint(Graphics g) {
l1.setBounds(40,200,1000,20);
}
}
OUTPUT
X. Program Code
1. Write a Program to Demonstrate Grid of 5*5.
CODE
package Experiment3;

import java.applet.Applet;
import java.awt.*;

public class ProgramCode1 extends Applet {


@Override
public void init() {
setLayout(new GridLayout(5,5,5,5));
for(int i=1;i<=25;i++){
add(new Button(Integer.toString(i)));
}
}}
OUTPUT:
2. Write a program to display The Number on Button from 0 to 9.
CODE:
package Experiment3;

import java.applet.Applet;
import java.awt.*;

public class ProgramCode2 extends Applet {


@Override
public void init() {
setLayout(new FlowLayout(FlowLayout.CENTER));
for(int i=0;i<10;i++){
add(new Button(Integer.toString(i)));
}
add(new Label("Designed By 19-Soham Parab"));
}
}
OUTPUT
XIII. Exercise.
1. Write a program to generate following Output.
CODE:
package Experiment3;

import java.applet.Applet;
import java.awt.*;

public class Exercise1 extends Applet {


@Override
public void init() {
setLayout(new GridLayout(3,2,10,10));
for(int i=1;i<=5;i++){
add(new Button("Button "+i));
}
add(new Label("Designed By 19-Soham"));
}}
OUTPUT
2. Write a program to generate following output using Border
Layout.
CODE:
package Experiment3;

import java.applet.Applet;
import java.awt.*;

public class Exercise2 extends Applet {


@Override
public void init() {
setLayout(new BorderLayout());
add(new Button("North"),BorderLayout.NORTH);
add(new Button("South"),BorderLayout.SOUTH);
add(new Button("West"),BorderLayout.WEST);
add(new Button("East"),BorderLayout.EAST);
add(new Button("Center"),BorderLayout.CENTER);
}}
OUTPUT:

You might also like