Name: Manish Kumhar Class: Tyco-A Roll No: 43 Subject: Ajp (Experiment: 4)
Name: Manish Kumhar Class: Tyco-A Roll No: 43 Subject: Ajp (Experiment: 4)
CLASS: TYCO-A
ROLL NO: 43
SUBJECT: AJP (EXPERIMENT: 4)
Practical No. 4: Use of CardLayout to write a program to create a two-level
card deck that allows the user to select an operating system.
I. Practical Significance:
The CardLayout class manages the components in such a manner that only one component is visible
at a time. It treats each component as a card hence known as CardLayout.
Nil
Sr. Name of
Broad Specification Quantity Remarks (If any)
No. Resource
1
X. Program Code: Teacher must assign a separate program statement to group of 3-4 students.
Execute the following Program and write the output.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
Figure 5
Program:-
import java.awt.*;
public class GridBagLayoutExample extends Frame
{
GridBagLayoutExample(String str)
{
super(str);
GridBagLayout grid = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
setLayout(grid);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridx = 0;
gbc.gridy = 0;
add(new Button("Button One"), gbc);
gbc.gridx = 1;
gbc.gridy = 0;
add(new Button("Button two"), gbc);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.ipady = 20;
gbc.gridx = 0;
gbc.gridy = 1;
add(new Button("Button Three"), gbc);
gbc.gridx = 1;
gbc.gridy = 1;
add(new Button("Button Four"), gbc);
gbc.gridx = 0;
gbc.gridy = 2;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridwidth = 2;
add(new Button("Button Five"), gbc);
setSize(300, 300);
setVisible(true);
}
public static void main(String[] args)
{
GridBagLayoutExample a = new GridBagLayoutExample("Manish Kumhar 43");
}
}
Output:-
2. Write Java Program to display following output.
Figure 6
Program:-
import java.awt.*;
class Exp4 extends Frame
{
Exp4(String str)
{
super(str);
Label abcName = new Label("Name");
TextField nameTxt = new TextField(10);
Label lblcomments = new Label("Comments");
TextArea TAcomments = new TextArea(6,15);
Button SubmitBtn = new Button("Submit");
setLayout(new GridBagLayout());
GridBagConstraints gbc =new GridBagConstraints();
add(abcName,gbc,0,0,1,1,0,0);
add(nameTxt,gbc,1,0,1,1,0,20);
add(lblcomments,gbc,0,1,1,1,0,0);
add(TAcomments,gbc,1,1,1,1,0,60);
add(SubmitBtn,gbc,0,2,2,1,0,20);
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature of
Marks Obtained
Teacher
Process Product
Total(50)
Related(35) Related(15)