STUDENTS 3K

  • Home
  • Students+
    • Engineering Students
    • Education Loan
    • Study Abroad Guide
    • Projects Download
  • Freshers
    • Aptitude Q & A
    • Placement Papers
    • Verbal Ability
    • Interview Questions
    • IT Company Details
    • Job Updates
  • Study Resources
    • Career Guidance
    • LAB Programs
      • C Programs
      • CPP Programs [C++]
      • Java Programs
    • Question Papers
    • Learn English
    • Notice Board
  • More –>>
    • Love calculator
You are here: Home / Important Programs / FlowLayout in Java AWT with Example program

FlowLayout in Java AWT with Example program

FlowLayout in Java AWT with Example code: This simple program is a type of various Java Layouts. The type of java layouts are,

  • Grid Layout,
  • Border Layout,
  • Card Layout,
  • & Flow Layout.

We have already discussed about GridLayout and CardLayouts here. If you want to know the various java layouts with program means just visit a link.

  • Simple Quiz project using java AWT code

FLOW LAYOUT IN JAVA

This java program is used to arrange the objects in a direction of flow method and it is just like the texts are available in a paragraph. It uses a button to arrange the view by left or right and button will only available in horizontal position. It will not be the sequential and uses align property to align the lines and buttons.

[Useful: C Programming Guide] & [IT Companies Details]

FlowLayout Example Tutorial:

Q: Write a Java program to design a FlowLayout using AWT.

//Import statements
import java.awt.*;
import java.awt.event.*;
//Class definition
public class Fl extends Frame implements ActionListener
{
	Variable declaration
	Button bu1,bu2,bu3;
	String mg="Demonstrating the layouts";
	public Fl(String title)
	{
		super(title);
		setLayout(new FlowLayout());//Object creation
		bu1=new Button("Left Aligned");
		bu2=new Button("Right Aligned");
		bu3=new Button("Center Aligned");
		bu1.addActionListener(this);
		bu2.addActionListener(this);
		bu3.addActionListener(this);
		add(bu1);
		add(bu2);
		add(bu3);
	}
	public void actionPerformed(ActionEvent e)
	{
		int val;
		if(e.getSource()==bu1)//Decision making statement
		{
			val=FlowLayout.LEFT;
			mg="Layout - Left aligned";
		}
		else if(e.getSource()==b2)
		{
			val=FlowLayout.RIGHT;
			mg="Layout - Right aligned";
		}
		else
		{
			val=FlowLayout.CENTER;
			mg="Layout - Center aligned";
		}
		setLayout(new FlowLayout(val));
		validate(); //screen is updated
		repaint();
	}
	public void paint(Graphics g)
	{
		g.drawString(mg,100,150); //Graphics method
	}
	public static void main(String args[])
	{
		Fl f=new Fl("FlowLayout");
		f.setSize(300,300);
		f.show();
	}
}

SEE: All Examination Results & News

Filed Under: Important Programs Tagged With: AWT, Java, LAB, Programs





Random Materials :

  • Data Mining and Data Warehousing
  • Difference Between Class and Primitive Types
  • Database Roles in SQL
  • CASE Expression in SQL
  • Concurrent Update Problem

Follow Us on Facebook

Advertisement

Company Profile

  • About Students3k
  • Contact Us
  • Earn Money Online
  • Website Archive Page
  • Privacy Policy
  • Disclaimer

Categories

  • Important Programs
  • Study Abroad
  • IT Companies
  • Career Guidance for Students
  • Teachers
  • Verbal Analogies

We Are Social

  • Facebook Fans
  • Twitter Follow
  • Google Plus
  • Pinterest Page

© Copyright 2012 - 2016 Students3k.com · All Rights Reserved · Designed By Benefits

Show