SlideShare a Scribd company logo
1 of 14
JAVA CARD AND FLOW LAYOUT
SUBMITTED TO:
XYZ
(Assistant Professor)
(Department of Computer Science and Engineering)
SUBMITTED BY:
TABLE OF CONTENT
• What is Java CardLayout
• Methods of CardLayout
• Example of CardLayout
• Java flow Layout
• Constructors of FlowLayout class
JAVA CARD LAYOUT
The CardLayout class manages the components in such a way that only one component is visible
at a time. It treats each component as a card in the container. Only one card is visible at a time,
and the container acts as a stack of cards. The first component added to a CardLayout object is the
visible component when the container is first displayed.
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
Commonly Used Methods of CardLayout Class:
•public void next(Container parent): is used to flip to the next card of the given container.
•public void previous(Container parent): is used to flip to the previous card of the given
container.
•public void first(Container parent): is used to flip to the first card of the given container.
•public void last(Container parent): is used to flip to the last card of the given container.
•public void show(Container parent, String name): is used to flip to the specified card
with the given name.
Example of CardLayout Class Using Default Constructor:
The following program uses the next() method to move to the next card of the container.
1.
2. import java.awt.*;
3. import javax.swing.*;
4. import java.awt.event.*;
5.
6. public class CardLayoutExample1 extends JFrame implements ActionListener
7. {
8.
9. CardLayout crd;
10.
11.JButton btn1, btn2, btn3;
12.Container cPane;
13. CardLayoutExample(){
16.cPane = getContentPane();
17.
18.
19.crd = new CardLayout();
20.
21.cPane.setLayout(crd);
22.
23.
24.btn1 = new JButton("Apple");
25.btn2 = new JButton("Boy");
26.btn3 = new JButton("Cat");
27.
28.
29.btn1.addActionListener(this);
30.btn2.addActionListener(this);
31.btn3.addActionListener(this);
34.cPane.add("a", btn1);
35.cPane.add("b", btn2);
36.cPane.add("c", btn3);
37.}
38.public void actionPerformed(ActionEvent e)
39.{
40.
41.crd.next(cPane);
42.}
43.
44.
45.public static void main(String argvs[])
46.{
47.CardLayoutExample1 crdl = new CardLayoutExample1();
48.
49.
50.crdl.setSize(300, 300);
51.crdl.setVisible(true);
52.crdl.setDefaultCloseOperation(EXIT_ON_CLOSE);
53.}
54.}
1
2
3
4
Java Flow Layout
The Java FlowLayout class is used to arrange the components in a line, one
after another (in a flow). It is the default layout of the applet or panel.
Fields of FlowLayout class:
• public static final int LEFT
• public static final int RIGHT
• public static final int CENTER
• public static final int LEADING
• public static final int TRAILING
Constructors of FlowLayout class:
• FlowLayout(): creates a flow layout with centered alignment and a default 5 unit
horizontal and vertical gap.
• Ex:- FlowLayout fl = new FlowLayout();
• FlowLayout(int align): creates a flow layout with the given alignment and a default
5 unit horizontal and vertical gap.
• Ex:- FlowLayout fl = new FlowLayout(FlowLayout.Left);
• FlowLayout(int align, int hgap, int vgap): creates a flow layout with the given
alignment and the given horizontal and vertical gap.
• Ex:- FlowLayout fl = new FlowLayout(FlowLayout.Left,H30,V20);
1.// import statements
2.import java.awt.*;
3.import javax.swing.*;
4.
5.public class FlowLayoutExample
6.{
7.
8.JFrame frameObj;
9.
10.// constructor
11.FlowLayoutExample()
12.{
13. // creating a frame object
14. frameObj = new JFrame();
15.
16. // creating the buttons
17. JButton b1 = new JButton("1");
18. JButton b2 = new JButton("2");
19. JButton b3 = new JButton("3");
20. JButton b4 = new JButton("4");
21. JButton b5 = new JButton("5");
22. JButton b6 = new JButton("6");
23. JButton b7 = new JButton("7");
24. JButton b8 = new JButton("8");
25. JButton b9 = new JButton("9");
26. JButton b10 = new JButton("10");
27.Public void init (){
28.frameObj.setLayout(new FlowLayout());
29. // adding the buttons to frame
30. frameObj.add(b1); frameObj.add(b2); frameObj.add(b3); frameObj.add(b4);
31. frameObj.add(b5); frameObj.add(b6); frameObj.add(b7); frameObj.add(b8);
32. frameObj.add(b9); frameObj.add(b10);
33. // therefore, alignment is center
34.}
35. // main method
36.public static void main(String argvs[])
37.{
38. new FlowLayoutExample();
39.}
40.}
Java card and flow layout

More Related Content

What's hot

SupportVectorRegression
SupportVectorRegressionSupportVectorRegression
SupportVectorRegression
Daniel K
 
Streaming Python on Hadoop
Streaming Python on HadoopStreaming Python on Hadoop
Streaming Python on Hadoop
Vivian S. Zhang
 
What they don't tell you about JavaScript
What they don't tell you about JavaScriptWhat they don't tell you about JavaScript
What they don't tell you about JavaScript
Raphael Cruzeiro
 
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis GraphRedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
Redis Labs
 

What's hot (20)

Convolution presentation
Convolution presentationConvolution presentation
Convolution presentation
 
WAP to add two given matrices in Java
WAP to add two given matrices in JavaWAP to add two given matrices in Java
WAP to add two given matrices in Java
 
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
 
R programming lab 1 - jupyter notebook
R programming lab   1 - jupyter notebookR programming lab   1 - jupyter notebook
R programming lab 1 - jupyter notebook
 
Oops Paper
Oops PaperOops Paper
Oops Paper
 
SupportVectorRegression
SupportVectorRegressionSupportVectorRegression
SupportVectorRegression
 
Machine Learning on GCP
Machine Learning on GCPMachine Learning on GCP
Machine Learning on GCP
 
Streaming Python on Hadoop
Streaming Python on HadoopStreaming Python on Hadoop
Streaming Python on Hadoop
 
What they don't tell you about JavaScript
What they don't tell you about JavaScriptWhat they don't tell you about JavaScript
What they don't tell you about JavaScript
 
Neuroscience Lab: a tour through the eyes of a pythonista, PyData Barcelona2017
Neuroscience Lab: a tour through the eyes of  a pythonista, PyData Barcelona2017Neuroscience Lab: a tour through the eyes of  a pythonista, PyData Barcelona2017
Neuroscience Lab: a tour through the eyes of a pythonista, PyData Barcelona2017
 
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeksBeginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
 
deep learning library coyoteの開発(CNN編)
deep learning library coyoteの開発(CNN編)deep learning library coyoteの開発(CNN編)
deep learning library coyoteの開発(CNN編)
 
Unity programming 1
Unity programming 1Unity programming 1
Unity programming 1
 
Vector3
Vector3Vector3
Vector3
 
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis GraphRedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
 
Maximizing performance of 3 d user generated assets in unity
Maximizing performance of 3 d user generated assets in unityMaximizing performance of 3 d user generated assets in unity
Maximizing performance of 3 d user generated assets in unity
 
D3.js workshop
D3.js workshopD3.js workshop
D3.js workshop
 
Computer graphics practical(jainam)
Computer graphics practical(jainam)Computer graphics practical(jainam)
Computer graphics practical(jainam)
 
Master defence 2020 - Vadym Korshunov - Region-Selected Image Generation with...
Master defence 2020 - Vadym Korshunov - Region-Selected Image Generation with...Master defence 2020 - Vadym Korshunov - Region-Selected Image Generation with...
Master defence 2020 - Vadym Korshunov - Region-Selected Image Generation with...
 
Luca Passani - Essential Tools for Mobile-Aware Web Professionals | Codemoti...
Luca Passani - Essential Tools for Mobile-Aware Web Professionals |  Codemoti...Luca Passani - Essential Tools for Mobile-Aware Web Professionals |  Codemoti...
Luca Passani - Essential Tools for Mobile-Aware Web Professionals | Codemoti...
 

Similar to Java card and flow layout

Ds lab manual by s.k.rath
Ds lab manual by s.k.rathDs lab manual by s.k.rath
Ds lab manual by s.k.rath
SANTOSH RATH
 
Java3 d 1
Java3 d 1Java3 d 1
Java3 d 1
Por Non
 
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docxIn Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
bradburgess22840
 
Antenna Physical Characetristics
Antenna Physical CharacetristicsAntenna Physical Characetristics
Antenna Physical Characetristics
Assignmentpedia
 

Similar to Java card and flow layout (20)

3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
 
Ccard Layout
Ccard LayoutCcard Layout
Ccard Layout
 
Layout manager
Layout managerLayout manager
Layout manager
 
Ds lab manual by s.k.rath
Ds lab manual by s.k.rathDs lab manual by s.k.rath
Ds lab manual by s.k.rath
 
Lecture 16
Lecture 16Lecture 16
Lecture 16
 
Compact and safely: static DSL on Kotlin
Compact and safely: static DSL on KotlinCompact and safely: static DSL on Kotlin
Compact and safely: static DSL on Kotlin
 
Java3 d 1
Java3 d 1Java3 d 1
Java3 d 1
 
Graphical User Components Part 2
Graphical User Components Part 2Graphical User Components Part 2
Graphical User Components Part 2
 
CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35
 
Deep dive into deeplearn.js
Deep dive into deeplearn.jsDeep dive into deeplearn.js
Deep dive into deeplearn.js
 
Stratosphere Intro (Java and Scala Interface)
Stratosphere Intro (Java and Scala Interface)Stratosphere Intro (Java and Scala Interface)
Stratosphere Intro (Java and Scala Interface)
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
 
Advanced Java programming
Advanced Java programmingAdvanced Java programming
Advanced Java programming
 
CS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingCS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and Culling
 
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docxIn Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
 
Machine-level Composition of Modularized Crosscutting Concerns
Machine-level Composition of Modularized Crosscutting ConcernsMachine-level Composition of Modularized Crosscutting Concerns
Machine-level Composition of Modularized Crosscutting Concerns
 
Computer Science CS Project Matrix CBSE Class 12th XII .pdf
Computer Science CS Project Matrix CBSE Class 12th XII .pdfComputer Science CS Project Matrix CBSE Class 12th XII .pdf
Computer Science CS Project Matrix CBSE Class 12th XII .pdf
 
Chap1 1.4
Chap1 1.4Chap1 1.4
Chap1 1.4
 
Antenna Physical Characetristics
Antenna Physical CharacetristicsAntenna Physical Characetristics
Antenna Physical Characetristics
 
Chap1 1 4
Chap1 1 4Chap1 1 4
Chap1 1 4
 

Recently uploaded

Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdf
Kira Dess
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
rahulmanepalli02
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
Degrees of freedom for the robots 1.pptx
Degrees of freedom for the robots 1.pptxDegrees of freedom for the robots 1.pptx
Degrees of freedom for the robots 1.pptx
Mostafa Mahmoud
 

Recently uploaded (20)

Basics of Relay for Engineering Students
Basics of Relay for Engineering StudentsBasics of Relay for Engineering Students
Basics of Relay for Engineering Students
 
Raashid final report on Embedded Systems
Raashid final report on Embedded SystemsRaashid final report on Embedded Systems
Raashid final report on Embedded Systems
 
Worksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptxWorksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptx
 
Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdf
 
Introduction-to- Metrology and Quality.pptx
Introduction-to- Metrology and Quality.pptxIntroduction-to- Metrology and Quality.pptx
Introduction-to- Metrology and Quality.pptx
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
 
Signal Processing and Linear System Analysis
Signal Processing and Linear System AnalysisSignal Processing and Linear System Analysis
Signal Processing and Linear System Analysis
 
Adsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) pptAdsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) ppt
 
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
 
Fundamentals of Internet of Things (IoT) Part-2
Fundamentals of Internet of Things (IoT) Part-2Fundamentals of Internet of Things (IoT) Part-2
Fundamentals of Internet of Things (IoT) Part-2
 
Path loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata ModelPath loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata Model
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
 
Degrees of freedom for the robots 1.pptx
Degrees of freedom for the robots 1.pptxDegrees of freedom for the robots 1.pptx
Degrees of freedom for the robots 1.pptx
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptx
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)
 
What is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsWhat is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, Functions
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To Curves
 
Working Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdfWorking Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdf
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptx
 

Java card and flow layout

  • 1. JAVA CARD AND FLOW LAYOUT SUBMITTED TO: XYZ (Assistant Professor) (Department of Computer Science and Engineering) SUBMITTED BY:
  • 2. TABLE OF CONTENT • What is Java CardLayout • Methods of CardLayout • Example of CardLayout • Java flow Layout • Constructors of FlowLayout class
  • 3. JAVA CARD LAYOUT The CardLayout class manages the components in such a way that only one component is visible at a time. It treats each component as a card in the container. Only one card is visible at a time, and the container acts as a stack of cards. The first component added to a CardLayout object is the visible component when the container is first displayed. 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
  • 4. Commonly Used Methods of CardLayout Class: •public void next(Container parent): is used to flip to the next card of the given container. •public void previous(Container parent): is used to flip to the previous card of the given container. •public void first(Container parent): is used to flip to the first card of the given container. •public void last(Container parent): is used to flip to the last card of the given container. •public void show(Container parent, String name): is used to flip to the specified card with the given name.
  • 5. Example of CardLayout Class Using Default Constructor: The following program uses the next() method to move to the next card of the container. 1. 2. import java.awt.*; 3. import javax.swing.*; 4. import java.awt.event.*; 5. 6. public class CardLayoutExample1 extends JFrame implements ActionListener 7. { 8. 9. CardLayout crd; 10. 11.JButton btn1, btn2, btn3; 12.Container cPane; 13. CardLayoutExample(){
  • 6. 16.cPane = getContentPane(); 17. 18. 19.crd = new CardLayout(); 20. 21.cPane.setLayout(crd); 22. 23. 24.btn1 = new JButton("Apple"); 25.btn2 = new JButton("Boy"); 26.btn3 = new JButton("Cat"); 27. 28. 29.btn1.addActionListener(this); 30.btn2.addActionListener(this); 31.btn3.addActionListener(this); 34.cPane.add("a", btn1); 35.cPane.add("b", btn2); 36.cPane.add("c", btn3);
  • 7. 37.} 38.public void actionPerformed(ActionEvent e) 39.{ 40. 41.crd.next(cPane); 42.} 43. 44. 45.public static void main(String argvs[]) 46.{ 47.CardLayoutExample1 crdl = new CardLayoutExample1(); 48. 49. 50.crdl.setSize(300, 300); 51.crdl.setVisible(true); 52.crdl.setDefaultCloseOperation(EXIT_ON_CLOSE); 53.} 54.}
  • 8. 1 2
  • 9. 3 4
  • 10. Java Flow Layout The Java FlowLayout class is used to arrange the components in a line, one after another (in a flow). It is the default layout of the applet or panel. Fields of FlowLayout class: • public static final int LEFT • public static final int RIGHT • public static final int CENTER • public static final int LEADING • public static final int TRAILING
  • 11. Constructors of FlowLayout class: • FlowLayout(): creates a flow layout with centered alignment and a default 5 unit horizontal and vertical gap. • Ex:- FlowLayout fl = new FlowLayout(); • FlowLayout(int align): creates a flow layout with the given alignment and a default 5 unit horizontal and vertical gap. • Ex:- FlowLayout fl = new FlowLayout(FlowLayout.Left); • FlowLayout(int align, int hgap, int vgap): creates a flow layout with the given alignment and the given horizontal and vertical gap. • Ex:- FlowLayout fl = new FlowLayout(FlowLayout.Left,H30,V20);
  • 12. 1.// import statements 2.import java.awt.*; 3.import javax.swing.*; 4. 5.public class FlowLayoutExample 6.{ 7. 8.JFrame frameObj; 9. 10.// constructor 11.FlowLayoutExample() 12.{ 13. // creating a frame object 14. frameObj = new JFrame(); 15. 16. // creating the buttons 17. JButton b1 = new JButton("1"); 18. JButton b2 = new JButton("2"); 19. JButton b3 = new JButton("3"); 20. JButton b4 = new JButton("4"); 21. JButton b5 = new JButton("5");
  • 13. 22. JButton b6 = new JButton("6"); 23. JButton b7 = new JButton("7"); 24. JButton b8 = new JButton("8"); 25. JButton b9 = new JButton("9"); 26. JButton b10 = new JButton("10"); 27.Public void init (){ 28.frameObj.setLayout(new FlowLayout()); 29. // adding the buttons to frame 30. frameObj.add(b1); frameObj.add(b2); frameObj.add(b3); frameObj.add(b4); 31. frameObj.add(b5); frameObj.add(b6); frameObj.add(b7); frameObj.add(b8); 32. frameObj.add(b9); frameObj.add(b10); 33. // therefore, alignment is center 34.} 35. // main method 36.public static void main(String argvs[]) 37.{ 38. new FlowLayoutExample(); 39.} 40.}