Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Class notes Java notes

Rating
-
Sold
-
Pages
17
Uploaded on
05-10-2023
Written in
2021/2022

The method in Java or Methods of Java is a collection of statements that perform some specific task and return the result to the caller. A Java method can perform some specific task without returning anything.

Institution
Course

Content preview

Layout Manager in Java: Layout Manages एक विशेष प्रकार के Objects होते हैं जो
ये तय करते हैं कि Application या Applet के Window में विभिन्न प्रकार के Components
किस प्रकार से Organize होंगे। जब हम किसी Applet या Application को Create करते हैं ,
तब जावा Automatically एक Default Layout Manager Create करता है और हमारे
Applet या Application को वह Default Layout Manager Object Assign कर देता है।
सामान्‍यतया ये Default Layout Manager Flow Layout Object होता है।
हमने इसी अध्‍याय में देखा है कि कुल पांच तरह के Containers होते हैं , जिनमें से Panel भी एक
प्रकार का Container है। लेकिन ये एक ऐसा Container है, जो Visually Display नहीं होता
है। इसलिए इस Container का प्रयोग सामान्‍यतया विभिन्न प्रकार के Controls के Group को अन्‍
य Visually Display होने वाले Containers पर Organize (Localize and Sized) करने
के लिए किया जाता है।
जब हम विभिन्न Components को Applet या किसी अन्‍य Container पर Place करते हैं, तब जिस तरीके से ये
विभिन्न Controls Screen पर या Applet पर Organize होते हैं, उनके Organize होने का तरीका बहु त ही
Variable होता है। Applet या Application पर दिखाई देने वाले विभिन्न प्रकार के Components निम्न स्थितियों से
प्रभावित होते हैं:
 Applet Window की Size से
 अन्‍य Components व Containers की Size से
 Use किए जाने वाले Layout Manager से
Flow Layout Manager in Java
जावा में जितने भी Container Controls होते हैं, उन सभी के साथ एक Layout Manager Associated होता है।
Layout Manager Layout Class का एक Object होता है, जिसमें LayoutManager Interface को
Implement किया गया होता है। किसी Layout को Set करने के लिए हमें setLayout() Method को Use करना
होता है। यदि हम किसी Container के साथ किसी Layout को Set नहीं करते हैं, तो उस Container के साथ एक
Default Layout Manager Set हो जाता है, जिसका नाम FlowLayout होता है।
हम जब भी किसी Container Object को Resize करते हैं, Container से Associated LayoutManager उस
Container के सभी Objects को Relatively Resize करके Container में फिर से Set कर देता है। जावा में
Multiplatform पर Use किए जाने वाले GUI Applications या Applets बनाए जाते हैं। जबकि विभिन्न प्रकार के
Platforms पर GUI समान दिखाई नहीं देते हैं।
जावा में Layout Manager s का प्रयोग इसीलिए किया गया है , ताकि हम जावा के Programs को किसी भी
Platform पर Execute करें , वे सभी Platform पर समान दिखाई दें। जब हम किसी Container के लिए किसी
Layout को Manually Set करना चाहते हैं, तो हमें निम्नानुसार Statement Use करना होता है:
इस Statement में layoutObj उस Layout Object का Reference है, जिसे हम Container के लिए Set करना
चाहते हैं। यदि हम किसी Container के लिए किसी Layout को Use करना नहीं चाहते] बल्कि हम Controls को
उनकी Actual Position पर Place करना चाहते हैं, तो हमें layoutObj Argument में null Specify करना होता
है।
लेकिन यदि हम किसी Container के लिए Layout को null कर देते हैं , तो Container में Place होने वाले सभी
Components की Size व Position को हमें ही Specify करना जरूरी हो जाता है , अन्‍यथा हमें Container में कोई

,भी Component दिखाई नहीं देता है। विभिन्न Components की Size तय करने के लिए हमें setBounds()
Method को Use करना पडता है , साथ ही विभिन्न Components को Container के लिए Visible भी बनाना पडता
है।
हम जिस किसी भी Layout Manager को Use करते हैं, वह Layout Manager उस Components के नाम का
Record या Track रखता है और हम जैसे ही किसी Container में किसी Component को Add करते हैं, वह
Layout Manager Notify हो जाता है। जब भी हम उस Container को Resize करते हैं, Layout
Manager minimumLayoutSize() व preferredLayoutSize() Method को Use करके Container
के सभी Components की Size को अनुपात में कम कर देता है। जो भी Component किसी Layout Manager
द्वारा Manage हो रहा होता है यानी जो भी Component किसी Container में Add किया जाता है , उस
Component में getPreferredSize() व getMinimumSize() नाम का Method होता है।
ये दोनों Methods किसी Component द्वारा Display होने वाली Preferred व Minimum Size को Return
करते हैं। जहां तक सम्भव होता है, Layout Manager सभी Objects को अपने नियमों के अनुसार Manage करता है।
जावा में विभिन्न प्रकार के Layout Manager हैं, जिनका प्रयोग करके हम हमारी जरूरत को पूरा कर सकते हैं। साथ ही हम
हमारी जरूरत के अनुसार नया Layout Manager भी Define कर सकते हैं।
Read also: Java GUI Programming

FlowLayout Manager
जावा में कई तरह के Layout Managers हैं, जिनका प्रयोग करके Applet पर Place होने वाले विभिन्न Controls की
Location व Size में Required परिवर्तन किया जा सकता है। FlowLayout Class Applet का Default
Layout Manager होता है, जिसका प्रयोग Automatically अभी तक के सभी Applet Programs के Applets में
हु आ है। FlowLayout में विभिन्न Components उसी तरह से Applet पर Place होते चले जाते हैं , जिस तरह से किसी
Page पर विभिन्न शब्द Print होते चले जाते हैं। जैसे ही Page की Line पूरी होती है, बाकी के शब्द अगली Line में
Print होने लगते हैं।
ठीक इसी तरह से जैसे ही Applet में जगह भर जाती है , विभिन्न Controls अगली Line में Place होने लगते हैं। Applet
के विभिन्न Components को FlowLayout में Setup करने के लिए हमें FlowLayout Class का एक Object
Create करके इसे एक Argument के रूप में setLayout() Method में Pass किया जाता है। यानी इस Layout
को यदि हम Manually Set करना चाहें, तो हमें निम्नानुसार Statement लिखने होते हैं:
FlowLayout myLayout = new FlowLayout();
setLayout(myLayout);
FlowLayout Class किसी Applet के लिए एक Default Layout Manager होता है। Flow Layout
Manager विभिन्न Controls को Applet पर उसी Sequence में एक Horizontal Row में Place करता है, जिस
Sequence में वे init() Method में add() Method का प्रयोग करके Add किए जाते हैं।
जैसे ही ये Manager Applet के Right Border तक पहु ंचता है, ये बाकी के Controls को अगले Horizontal Row
में Place करना शुरू कर देता है। ये Layout अपनी Default स्थिति में विभिन्न Controls को Applet के Center में
Place करता है। FlowLayout Class के तीन Constructors हैं जो कि निम्नानुसार हैं:
Read also: Java Frame

public FlowLayout(); // No-Argument Constructor
public FlowLayout(int align); // 1-Argument Constructor
public FlowLayout(int align, int hgap, int vgap); //3-Argument Constructor

, No-Argument Constructor एक नया FlowLayout Manager Object Create करता है और Applet पर
Place किए जाने वाले सभी Controls को Applet के Center में Place करता है। साथ ही सभी Controls आपस में
By-Default Vertically व Horizontally 5-5 Pixels दूर Place होते हैं।
1-Argument Constructor द्वारा Create होने वाला Layout Manager Object उस दिशा से Controls को
Applet पर Place करना शुरू करता है , जिस दिशा का हम 1-Argumnet Constructor में उल्लेख कर देते हैं। जबकि
इस Constructor का प्रयोग करने पर भी विभिन्न Controls Default रूप से Horizontally व Vertically 5-5
Pixels दूर Place होते हैं।
3-Argument Constructor द्वारा हम ऐसा Layout Object Create कर सकते हैं , जिसे Set करके हम ये तय कर
सकते हैं, कि Controls किस दिशा से Form पर Place] होंगे और विभिन्न Controls के बीच Horizontally व
Vertically कितना Gap रहेगा।
align
Read also: Event Handling in Java

इस Argument के स्थान पर हमें निम्न में से किसी एक Constant को Use करना होता है:
FlowLayout.LEFT – जब Controls को Left से Place करना हो
FlowLayout.RIGHT – जब Controls को Right से Place करना हो
FlowLayout.CENTER – जब Controls को Center में Place करना हो
hgap, vgap
इन Arguments के स्थान पर हम उन Pixels की संख्य
‍ ा को Specify करते हैं, जितने Pixels की दूरी हमें
Horizontally व Vertically दो Controls के बीच रखनी होती है। उदाहरण के लिए यदि हमें Applet पर विभिन्न
Controls को Left से Place करना हो साथ ही सभी Controls के बीच की दूरी को 10 Pixel Horizontally व 5
Pixels Vertically रखना हो, तो निम्न Applet में हम ये काम निम्नानुसार कर सकते हैं :
// File Name: ButtonNTextBoxApplet.java
import java.awt.*;
import java.applet.*;

public class ButtonNTextBoxApplet extends Applet{
TextField txtBox1 = new TextField(10), txtBox2 = new
TextField(10);
Button OKButton = new Button("OK");
FlowLayout organizeControls = new FlowLayout(FlowLayout.LEFT,
10, 5);

public void init(){
setLayout(organizeControls);
add(txtBox1);
add(txtBox2);
add(OKButton);
}
}




Layout Manager in Java Programming Language in Hindi
Read also: GUI Application in Java

Written for

Course

Document information

Uploaded on
October 5, 2023
Number of pages
17
Written in
2021/2022
Type
Class notes
Professor(s)
Anil sir
Contains
All classes

Subjects

$10.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
poonamvihwakarma1993

Get to know the seller

Seller avatar
poonamvihwakarma1993 Barkatullah university
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
2
Last sold
-
Dev's Collection

I have a good collection of assignment and notes.

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions