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

Name: Manish Kumhar Class: Tyco-A Roll No: 43 Subject: Ajp (Experiment: 4)

This document contains details about a practical assignment on using CardLayout in Java to create a two-level card deck that allows the user to select an operating system. It provides information on the practical significance, relevant program outcomes, competencies, course outcomes, practical outcomes, theoretical background, sample code and output, related questions, and an exercise. The assignment aims to develop skills in applying different layouts and demonstrating different layout managers.

Uploaded by

Manish Kumhar
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)
302 views

Name: Manish Kumhar Class: Tyco-A Roll No: 43 Subject: Ajp (Experiment: 4)

This document contains details about a practical assignment on using CardLayout in Java to create a two-level card deck that allows the user to select an operating system. It provides information on the practical significance, relevant program outcomes, competencies, course outcomes, practical outcomes, theoretical background, sample code and output, related questions, and an exercise. The assignment aims to develop skills in applying different layouts and demonstrating different layout managers.

Uploaded by

Manish Kumhar
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/ 10

NAME: MANISH KUMHAR

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.

II. Relevant Program Outcomes (POs)


 Basic knowledge: Apply knowledge of basic mathematics, sciences and basic engineering to
solve the computer group related problems.
 Discipline knowledge: Apply Computer Programming knowledge to solve the computer group
related problems.
 Experiments and practice: Plan to perform experiments and practices to use the results to solve
the computer group related problems.
 Engineering tools: Apply relevant Computer programming / technologies and tools with an
understanding of the limitations.
 Individual and Team work: Function effectively as a leader and team member in
diverse/multidisciplinary teams.
 Communication: Communicate effectively in oral and written form.

III. Competency and Practical skills


To develop standalone applications
The practical is expected to develop the following skills:
1. Able to apply different layouts to Applet, Frame and Panel
2. Able to demonstrate the use of different types of Layout Manager

IV. Relevant Course Outcome(s)


Develop programs using GUI Framework (AWT and Swing).

V. Practical Outcome (PrOs)


Write a program to demonstrate the use of Border layout showing four buttons at four sides of an
applet with captions “left”, “right”, “top” and “bottom”

VI. Relevant Affective domain related Outcome(s)


1. Follow precautionary measures.
2. Follow naming conventions.
3. Follow ethical practices.

VII. Minimum Theoretical Background


Constructors of CardLayout class
1. CardLayout(): creates a card layout with zero horizontal and vertical gap.
2. CardLayout(int hgap, int vgap): creates a card layout with the given horizontal and vertical
gap.
Commonly used methods of CardLayout class
1. public void next (Container parent): is used to flip to the next card of the given container.
2. public void previous (Container parent): is used to flip to the previous card of the given
container.
3. public void first (Container parent): is used to flip to the first card of the given container.
4. public void last (Container parent): is used to flip to the last card of the given container.
5. public void show (Container parent, String name): is used to flip to the specified card with
the given name.
VIII. Resources required (Additional)–

Nil

IX. Resources used (Additional)

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.*;

public class CardLayoutExample extends JFrame implements ActionListener


{
CardLayout card; JButton b1, b2,
b3; Container c;
CardLayoutExample()
{
c=getContentPane(); card=new
CardLayout(40,30);
//create CardLayout object with 40 hor space and 30 ver space c.setLayout(card);
b1=new JButton("Apple"); b2=new
JButton("Boy"); b3=new JButton("Cat");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
c.add("a",b1);c.add("b",b2);c.add("c",b3);
}
public void actionPerformed(ActionEvent e)
{
card.next(c);
}
public static void main(String[] args)
{
CardLayoutExample cl=new CardLayoutExample();
cl.setSize(400,400);
cl.setVisible(true); cl.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
XI. Result (Output of Code):
XII. Practical Related Questions
Note: Below given are few sample questions for reference. Teacher must design more such
questions so as to ensure the achievement of identified CO.
1. State difference between GridLayout and GridBagLayout.
2. Explain constructor of GridbagLayout.

(Space for answer)


XIII. Exercise
1. Write Java program to display following output.

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);

setTitle("GridBagLayout in Java Example");


setSize(350,200);
setVisible(true);
addWindowListener(new java.awt.event.WindowAdapter()
{
public void windowClosing(java.awt.event.WindowEvent e)
{
System.exit(0);
}
});
}
void add(Component comp,GridBagConstraints gbc,int x,int y,int w,int h,int wx,int wy)
{
gbc.gridx = x;
gbc.gridy = y;
gbc.gridwidth = w;
gbc.gridheight= h;
gbc.weightx = wx;
gbc.weighty = wy;
add(comp,gbc);
}
}
class Manish3
{
public static void main(String args[])
{
Exp4 frame = new Exp4("Manish Kumhar 43");
}
}
Output:-
XIV. References/ Suggestions for Further Reading
1. https://www.javatpoint.com
2. https://www.tutorialspoint.com/java
3. The complete reference Java 2 by Herbert Schildt

XV. Assessment Scheme

Performance Indicators Weightage


Process related (35 Marks) 70%
1. Logic formation 30%
2. Debugging ability 30%
3. Follow ethical practices 10%
Product related (15 Marks) 30%
4. Expected output 10%
5. Timely Submission 10%
6. Answer to sample questions 10%
Total (50 Marks) 100%

List of Students /Team Members

1. …………………………………..
2. …………………………………..
3. …………………………………..

Dated signature of
Marks Obtained
Teacher

Process Product
Total(50)
Related(35) Related(15)

You might also like