Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Understanding AWT Components and Layout Managers in Java GUI Development, Slides of Java Programming

An overview of the abstract windowing toolkit (awt) components and layout managers used in developing java graphical user interfaces (guis). It covers the initial set of awt components, including buttons, text fields, labels, text areas, check boxes, menus, radio buttons, canvases, lists, and scroll panes. The document also explains how to use layout managers, such as flowlayout and gridlayout, to organize and position components in a container.

Typology: Slides

2011/2012

Uploaded on 07/03/2012

aapti
aapti 🇮🇳

4.6

(28)

82 documents

1 / 55

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ava-programming
An
Introduction
Java Short Course
Day-10
J
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37

Partial preview of the text

Download Understanding AWT Components and Layout Managers in Java GUI Development and more Slides Java Programming in PDF only on Docsity!

ava - programming

An Introduction

Java Short Course

Day-

J

Outline

  • Applets Once again
  • GUI-Components
  • Components hierarchy
  • Packages
  • The Java AWT Package
  • Exploring Component Classes
  • Creating and Using Components
  • Exploring Components Properties
  • Using JBuilder7 design tool

Container-Non-Container Components

JPanel

JPanel

JButton JButton

JTextArea

JFrame

Combination

JPanel

JButton

JLabel

JButton JButton

JTextArea

AWT Components

Swing

Components

Packages

  • Packages  java.awt  javax.swings
  • java.awt pacakge

 Abstract Windowing Kit  GUI-Components are drawn according to the underlying windowing system  Initial set of Components developed  AWT Components  Buttons  Text Fields  Labels  Text Areas  Check Boxes  Menus  Radio Buttons  Canvases  Lists  Scroll Panes  Choices

First Button

  • Two simple steps

 Create a Button

 Add button to the applet

 Don’t Forget to import the awt package.

  • Step-

public Button firstButton = new Button(“ Click It ”);

  • Step-

add(firstButton);

Button applet output

  • Button Applet

Adding few more buttons

import java.awt.*;

import java.applet.*;

public class ButtonApplet extends Applet{

//creating the button component

public Button firstButton = new Button(“One”);

public Button secondButton = new Button(“Two”);

public Button thirdButton = new Button(“Threet”);

public void init( ){

//adding to the applet

add(firstButton); add(secondButton); add(thirdButton); }

}

Why Buttons are in one row?

How to control them?

Layout Managers

  • How your components should be organized

 Layout Managers draw place your components at relative positions

 Absolute position can cause problems

 Necessary for application intended for different platforms

 Layout Managers are classes

 AWT Layout Managers

 Flow Layout  GridLayout  Border Layout  CardLayout  GridBagLayout  Null layout

 So how did the previous applet worked

 The default layout manager

Flow Layout

  • Adds components in a row
  • Starts from left
  • Treats container as set of rows
  • Height of row is defined by the height of components
  • Default alignment is left
  • Can also start from right or center
  • The constructor

 pulic FlowLayout()

 Public FlowLayout(int alignment) //FlowLayout.LEFT

 Public FlowLayout(int alignement,int hgap,vgap)

  • Setting layout
  • Step-

Public FlowLayout myFlowLayout=new FlowLayout();

  • Step-

setLayout(myFlowLayout)

Flow Layout…cont..

  • Example-

 Using Flow Layout constructor 1

import java.awt.; import java.applet.;

public class flowLayoutTest extends Applet{

public FlowLayout myFlowLayout=new FlowLayout(); Button B=new Button(“Click It”);

public void init(){ setLayout(myFlowLayout); add(B); } }