ফ্লো-লেয়াঊট

FlowLayout Default for javax.swing.JPanel. Places components sequentially (left
to right) in the order they were added. It’s also possible to specify the
order of the components by using the Container method add,which
takes a Component and an integer index position as arguments.

ফ্লোলেয়াঊট javax.swing.JPanel এর জন্য ডিফল্ট থাকে। আমরা যেমন MS word এ লেখার সময় right ,left ,বা , center alignment এ লেখা ফরমেট করে থাকি সে রকম কাজ করে থাকে । অর্থাত অ্যালাইনমেন্ট কে Flow করে থাকে। যে কোন ভাবে পজিশান চেঞ্জ করা যায়।
এরকম একটি প্রোগ্রাম এখন দেখা যাক——-
eclipse এ নিম্নোক্ত প্রোগ্রামটি রান করালে বিষয়টি বুঝতে পারা যাবে

প্রথমে হেডার ফাইল ইম্পোর্ট করে নিতে হবে । অবশ্য যখন যে হেডার দরকার সেটি ইমপোর্ট করে নিলেই হবে , বরং এটাই ভালো প্রসেস।
import java.awt.FlowLayout;
import java.awt.Container;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JButton;
public class FlowLayoutFrame extends JFrame
{

তিনটি বাটন নেম ভেরিয়েবল নিয়ে নিলাম–
private JButton  leftJButton; // button to set alignment left
private JButton  centerJButton; // button to set alignment center
private JButton  rightJButton; // button to set alignment right

******এখানে ফ্লোলেয়াউট ডিক্লেয়ার করলাম******
private  FlowLayout  layout; // layout object

****লেয়াঊটি একটি কন্টেনারে রাখতে হবে তাই কন্টেনার ভেরিয়েবল ডিক্লেয়ার করলাম***
private  Containe r container; // container to set layout
———-FlowLayoutFrame() নামে একটি ক্লাস নিলাম —–
public  FlowLayoutFrame()
{
*******নাম দিলাম******সুপার এর মাধ্যমে যে নাম দিলাম তা ফ্রেমের header হিসেবে কাজ করবে***
super( “FlowLayout Demo” );

container = getContentPane(); // get container to layout
// set up leftJButton and register listener
leftJButton = new JButton( “Left” ); // create Left button

leftJButton.addActionListener(

new ActionListener() // anonymous inner class
{
// process leftJButton event
public void actionPerformed( ActionEvent event )
{

// realign attached components

} // end method actionPerformed
} // end anonymous inner class
); // end call to addActionListener

// set up centerJButton and register listener
layout = new FlowLayout(); // create FlowLayout
setLayout( layout ); // set frame layout
add( leftJButton ); // add Left button to frame
layout.setAlignment( FlowLayout.LEFT );
layout.layoutContainer( container );
centerJButton = new JButton( “Center” ); // create Center button
add( centerJButton ); // add Center button to frame
centerJButton.addActionListener(

new ActionListener() // anonymous inner class
{
// process centerJButton event
public void actionPerformed( ActionEvent event )
{

// realign attached components

} // end method actionPerformed
} // end anonymous inner class
); // end call to addActionListener

// set up rightJButton and register listener
rightJButton = new JButton( “Right” ); // create Right button

rightJButton.addActionListener(

new ActionListener() // anonymous inner class
{
// process rightJButton event
public void actionPerformed( ActionEvent event )
{

// realign attached components

} // end method actionPerformed
} // end anonymous inner class
); // end call to addActionListener
} // end FlowLayoutFrame constructor } // end class FlowLayoutFrame
layout.setAlignment( FlowLayout.CENTER );
layout.layoutContainer( container );
add( rightJButton ); // add Right button to frame
layout.setAlignment( FlowLayout.RIGHT );
layout.layoutContainer( container );

// Fig. 14.40: FlowLayoutDemo.java
// Testing FlowLayoutFrame.
import javax.swing.JFrame;
public class FlowLayoutDemo
{
public static void main( String[] args )
{
FlowLayoutFrame flowLayoutFrame = new FlowLayoutFrame();
flowLayoutFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
flowLayoutFrame.setSize( 300, 75 ); // set frame size
flowLayoutFrame.setVisible( true ); // display frame
} // end main
} // end class FlowLayoutDemo
import java.awt.FlowLayout;
import java.awt.Container;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JButton;
public class FlowLayoutFrame extends JFrame
{

private JButton  leftJButton; // button to set alignment left
private JButton  centerJButton; // button to set alignment center
private JButton  rightJButton; // button to set alignment right
public  FlowLayoutFrame()
private  Containe r container; // container to set layout
private  FlowLayout  layout; // layout object

super( “FlowLayout Demo” );
container = getContentPane(); // get container to layout
// set up leftJButton and register listener
leftJButton = new JButton( “Left” ); // create Left button

leftJButton.addActionListener(

new ActionListener() // anonymous inner class
{
// process leftJButton event
public void actionPerformed( ActionEvent event )
{

// realign attached components

} // end method actionPerformed
} // end anonymous inner class
); // end call to addActionListener

// set up centerJButton and register listener
layout = new FlowLayout(); // create FlowLayout
setLayout( layout ); // set frame layout
add( leftJButton ); // add Left button to frame
layout.setAlignment( FlowLayout.LEFT );
layout.layoutContainer( container );
centerJButton = new JButton( “Center” ); // create Center button
add( centerJButton ); // add Center button to frame
centerJButton.addActionListener(

new ActionListener() // anonymous inner class
{
// process centerJButton event
public void actionPerformed( ActionEvent event )
{

// realign attached components

} // end method actionPerformed
} // end anonymous inner class
); // end call to addActionListener

// set up rightJButton and register listener
rightJButton = new JButton( “Right” ); // create Right button

rightJButton.addActionListener(

new ActionListener() // anonymous inner class
{
// process rightJButton event
public void actionPerformed( ActionEvent event )
{

// realign attached components

} // end method actionPerformed
} // end anonymous inner class
); // end call to addActionListener
} // end FlowLayoutFrame constructor } // end class FlowLayoutFrame
layout.setAlignment( FlowLayout.CENTER );
layout.layoutContainer( container );
add( rightJButton ); // add Right button to frame
layout.setAlignment( FlowLayout.RIGHT );
layout.layoutContainer( container );

// Fig. 14.40: FlowLayoutDemo.java
// Testing FlowLayoutFrame.
import javax.swing.JFrame;
public class FlowLayoutDemo
{
public static void main( String[] args )
{
FlowLayoutFrame flowLayoutFrame = new FlowLayoutFrame();
flowLayoutFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
flowLayoutFrame.setSize( 300, 75 ); // set frame size
flowLayoutFrame.setVisible( true ); // display frame
} // end main
} // end class FlowLayoutDemo

import java.awt.FlowLayout;
import java.awt.Container;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JButton;

public class FlowLayoutFrame extends JFrame
{
private JButton leftJButton; // button to set alignment left
private JButton centerJButton; // button to set alignment center
private JButton rightJButton; // button to set alignment right
private FlowLayout layout; // layout object
private Container container; // container to set layout

// set up GUI and register button listeners
public FlowLayoutFrame()
{
super( “FlowLayout Demo” );

layout = new FlowLayout(); // create FlowLayout
container = getContentPane(); // get container to layout
setLayout( layout ); // set frame layout

// set up leftJButton and register listener
leftJButton = new JButton( “Left” ); // create Left button
add( leftJButton ); // add Left button to frame
leftJButton.addActionListener(

new ActionListener() // anonymous inner class
{
// process leftJButton event
public void actionPerformed( ActionEvent event )
{
layout.setAlignment( FlowLayout.LEFT );

// realign attached components
layout.layoutContainer( container );
} // end method actionPerformed
} // end anonymous inner class
); // end call to addActionListener

// set up centerJButton and register listener
centerJButton = new JButton( “Center” ); // create Center button
add( centerJButton ); // add Center button to frame
centerJButton.addActionListener(

new ActionListener() // anonymous inner class
{
// process centerJButton event
public void actionPerformed( ActionEvent event )
{
layout.setAlignment( FlowLayout.CENTER );

// realign attached components
layout.layoutContainer( container );
} // end method actionPerformed
} // end anonymous inner class
); // end call to addActionListener

// set up rightJButton and register listener
rightJButton = new JButton( “Right” ); // create Right button
add( rightJButton ); // add Right button to frame
rightJButton.addActionListener(

new ActionListener() // anonymous inner class
{
// process rightJButton event
public void actionPerformed( ActionEvent event )
{
layout.setAlignment( FlowLayout.RIGHT );

// realign attached components
layout.layoutContainer( container );
} // end method actionPerformed
} // end anonymous inner class
); // end call to addActionListener
} // end FlowLayoutFrame constructor
} // end class FlowLayoutFram

—–**********
import javax.swing.JFrame;

public class FlowLayoutDemo
{
public static void main( String[] args )
{
FlowLayoutFrame flowLayoutFrame = new FlowLayoutFrame();
flowLayoutFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
flowLayoutFrame.setSize( 300, 75 ); // set frame size
flowLayoutFrame.setVisible( true ); // display frame
} // end main
} // end class FlowLayoutDemo

flowLayout

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s