SlideShare a Scribd company logo
Rakesh Ravaso Patil
Dept. of Computer Engg.
T.E. „B‟ 12276
Overview…
 Introduction to AWT
    Swing vs. AWT
 Building GUI
 Component Hierarchy
 AWT Control Fundamentals
 Adding Components
 Arranging Components
 Overview of Event Handling
 Working with Graphics
 Conclusion
AWT (Abstract Window Toolkit)
 Present in all Java implementations

 Adequate for many applications

 Uses the controls defined by your OS

 Difficult to build an attractive GUI

 import java.awt.*;
 import java.awt.event.*;
Swing
 Same concepts as AWT
 Doesn‟t work in ancient Java implementations (Java
  1.1 and earlier)
 Many more controls, and they are more flexible
   Some controls, but not all, are a lot more complicated
 Gives a choice of “look and feel” packages
 Much easier to build an attractive GUI
 import javax.swing.*;
Swing vs. AWT
 Swing is bigger, slower, and more complicated
    But not as slow as it used to be
 Swing is more flexible and better looking
 Swing and AWT are incompatible--you can use
 either, but you can‟t mix them
   Actually, you can, but it‟s tricky and not worth doing
 Learning the AWT is a good start on learning Swing
 Many of the most common controls are just renamed
    AWT: Button b = new Button ("OK");
    Swing: JButton b = new JButton("OK");
To build a GUI...
 Create some Components, such as buttons, text
  areas, panels, etc.
 Add your Components to your display area
 Arrange, or lay out, your Components
 Attach Listeners to your Components
   Interacting with a Component causes an Event to occur
   A Listener gets a message when an interesting event
    occurs, and executes some code to deal with it
An Applet is Panel is Container
java.lang.Object
  |
  +----java.awt.Component
       |
       +----java.awt.Container
           |
           +----java.awt.Panel
                |
                +----java.applet.Applet
  …so you can display things in an Applet
Example: A "Life" applet
               Container (Applet)

               Containers (Panels)


                Component (Canvas)


                Components (Buttons)


                Components (TextFields)

                Components (Labels)
Some types of components
   Label           Button             Checkbox




  Choice                                          Scrollbar


TextField   List                                  TextArea


 Button




                       Checkbox   CheckboxGroup
Creating components
 Label lab = new Label ("Hi, Dave!");
 Button but = new Button ("Click me!");
 Checkbox toggle = new Checkbox ("toggle");
 TextField txt =
    new TextField ("Initial text.", 20);
 Scrollbar scrolly = new Scrollbar
   (Scrollbar.HORIZONTAL, initialValue,
    bubbleSize, minValue, maxValue);
Adding components to the Applet
  class MyApplet extends Applet {
     public void init () {
      add (lab); // same as this.add(lab)
      add (but);
      add (toggle);
      add (txt);
      add (scrolly);
      ...
Arranging components
 Every Container has a layout manager
 The default layout for a Panel is FlowLayout
 An Applet is a Panel
 Therefore, the default layout for a Applet is
  FlowLayout
 You could set it explicitly with
    setLayout (new FlowLayout( ));
 You could change it to some other layout manager
Flow Layout
 Use add(component); to add to a
    component when using a
    FlowLayout
   Components are added left-to-right
   If no room, a new row is started
   Exact layout depends on size of
    Applet
   Components are made as small as
    possible
   FlowLayout is convenient but often
    ugly
BorderLayout
 At most five components
  can be added
 If you want more
  components, add a
 Panel, then add
 components to it.
•setLayout (new BorderLayout());
GridLayout
 The GridLayout
  manager divides the
  container up into a
  given number of rows
  and columns:
 new GridLayout(rows,
  columns)

•All sections of the grid are equally sized and as
large as possible
Making components active
 Most components already appear to do something--
  buttons click, text appears
 To associate an action with a component, attach a
  listener to it
 Components send events, listeners listen for events
 Different components may send different events, and
  require different listeners
Listeners
 Listeners are interfaces, not classes
    class MyButtonListener implements
          ActionListener {
 An interface is a group of methods that must be
  supplied
 When you say implements, you are promising to
  supply those methods
Writing a Listener
 For a Button, you need an ActionListener

    b1.addActionListener
       (new MyButtonListener ( ));

 An ActionListener must have an
 actionPerformed(ActionEvent) method

    public void actionPerformed(ActionEvent e) {
      …
    }
Listeners for TextFields
 An ActionListener listens for someone hitting the
  Enter key
 An ActionListener requires this method:
    public void actionPerformed (ActionEvent e)
 You can use getText( ) to get the text

 A TextListener listens for any and all keys
 A TextListener requires this method:
    public void textValueChanged(TextEvent e)
Working With Graphics
                Circle               Triangle
   Rounded
   Rectangle   Arc

                                        Ellipse




                         Rectangle
 Lines
Working with Graphics
 void drawLine(int x1, int y1, int x2, int y2)
 void drawRect(int top, int left, int width, int height)
 void drawRoundRect(int top, int left,int width, int
            height, int xDiam, int yDiam)
 void drawOvel(int top, int left, int width, int height)
 void drawArc(int top, int left, int width,int height, int
            startAngle, int sweepAngle)
 void drawPoly(int x[], int y[], int numPoints)

 void fill….
Format Shape
 Working with colors
   HSB
   RGB
   static int HSBtoRGB(float hue, float saturation, float
                                         brightness)
   Static float[] RGBtoHSB(int red, int green, int blue,
                                         float value[])
 Working with Fonts
   Font(String fontName, int fontStyle, int pointSize)
Summary : Building a GUI
 Create a container, such as Frame or Applet
 Choose a layout manager
 Create more complex layouts by adding Panels; each
  Panel can have its own layout manager
 Create other components and add them to whichever
  Panels you like
 For each active component, look up what kind of
  Listeners it can have
 Create (implement) the Listeners
   often there is one Listener for each active component
Summary: Building a GUI
 For each Listener you implement, supply the
  methods that it requires
 For Applets, write the necessary HTML
 Graphics
   Drawing Lines
   Drawing Rectangles
   Drawing Ellipse and Circles
   Drawing Polygons
 Color schemes and Fonts
Awt

More Related Content

PPTX
Java awt (abstract window toolkit)
PPTX
Java swing
PPT
Java awt
PDF
Java I/o streams
PPT
Javascript arrays
PDF
Arrays in Java
PPT
JDBC – Java Database Connectivity
Java awt (abstract window toolkit)
Java swing
Java awt
Java I/o streams
Javascript arrays
Arrays in Java
JDBC – Java Database Connectivity

What's hot (20)

PDF
Collections In Java
PPT
Java And Multithreading
PPTX
Event In JavaScript
PPT
Class 5 - PHP Strings
PPTX
PPTX
Servlets
PPTX
Java Decision Control
PDF
07 java collection
PPTX
Strings in Java
PPTX
Packages in java
PPTX
Php.ppt
PPTX
Decision making and branching
PPT
PDF
C++ Files and Streams
PPT
Java layoutmanager
PPTX
Operators php
PDF
JavaScript - Chapter 4 - Types and Statements
ODP
Introduction of Html/css/js
PPSX
Data Types & Variables in JAVA
Collections In Java
Java And Multithreading
Event In JavaScript
Class 5 - PHP Strings
Servlets
Java Decision Control
07 java collection
Strings in Java
Packages in java
Php.ppt
Decision making and branching
C++ Files and Streams
Java layoutmanager
Operators php
JavaScript - Chapter 4 - Types and Statements
Introduction of Html/css/js
Data Types & Variables in JAVA
Ad

Viewers also liked (15)

PPTX
Bluetooth - Overview
DOCX
Bluetooth wi fi wi max 2, 3
PPT
Bluetooth
PPTX
software project management Waterfall model
PPTX
Bluetooth technology
PPTX
Visibility control in java
PPT
Classical problem of synchronization
PPTX
Event Handling in java
PDF
Access modifiers in java
PPT
Wi-Fi vs Bluetooth
PPT
PPT
Java access modifiers
PPTX
Waterfall model ppt final
PPTX
Waterfall model
PPTX
Wi-Fi Technology
Bluetooth - Overview
Bluetooth wi fi wi max 2, 3
Bluetooth
software project management Waterfall model
Bluetooth technology
Visibility control in java
Classical problem of synchronization
Event Handling in java
Access modifiers in java
Wi-Fi vs Bluetooth
Java access modifiers
Waterfall model ppt final
Waterfall model
Wi-Fi Technology
Ad

Similar to Awt (20)

PPT
28 awt
PPT
25 awt
PPTX
Awt - Swings-- Applets In java
PDF
PraveenKumar A T AWS
PDF
PPTX
AWT stands for Abstract Window Toolkit. AWT is collection of classes and int...
PPT
Swing and AWT in java
PDF
Swingpre 150616004959-lva1-app6892
PPT
14a-gui.ppt
PPTX
GUI components in Java
PPT
Windows Programming with AWT
PPT
Unit 1- awt(Abstract Window Toolkit) .ppt
PPT
awt.ppt java windows programming lecture
PPT
awdrdtfffyfyfyfyfyfyfyfyfyfyfyfyyfyt.ppt
PPT
fdtrdrtttxxxtrtrctctrttrdredrerrrrrrawt.ppt
PPT
1.Abstract windowing toolkit.ppt of AJP sub
PPT
appletcomponentsjbjxbsjkcsjkcjmsc jc.ppt
PPT
Java AWT Controls and methods, Listener classes
PPT
introduction to JAVA awt programmin .ppt
PPT
Basic of Abstract Window Toolkit(AWT) in Java
28 awt
25 awt
Awt - Swings-- Applets In java
PraveenKumar A T AWS
AWT stands for Abstract Window Toolkit. AWT is collection of classes and int...
Swing and AWT in java
Swingpre 150616004959-lva1-app6892
14a-gui.ppt
GUI components in Java
Windows Programming with AWT
Unit 1- awt(Abstract Window Toolkit) .ppt
awt.ppt java windows programming lecture
awdrdtfffyfyfyfyfyfyfyfyfyfyfyfyyfyt.ppt
fdtrdrtttxxxtrtrctctrttrdredrerrrrrrawt.ppt
1.Abstract windowing toolkit.ppt of AJP sub
appletcomponentsjbjxbsjkcsjkcjmsc jc.ppt
Java AWT Controls and methods, Listener classes
introduction to JAVA awt programmin .ppt
Basic of Abstract Window Toolkit(AWT) in Java

Recently uploaded (20)

PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Classroom Observation Tools for Teachers
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Basic Mud Logging Guide for educational purpose
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Module 4: Burden of Disease Tutorial Slides S2 2025
O5-L3 Freight Transport Ops (International) V1.pdf
RMMM.pdf make it easy to upload and study
O7-L3 Supply Chain Operations - ICLT Program
Classroom Observation Tools for Teachers
STATICS OF THE RIGID BODIES Hibbelers.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Basic Mud Logging Guide for educational purpose
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Renaissance Architecture: A Journey from Faith to Humanism
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
TR - Agricultural Crops Production NC III.pdf
PPH.pptx obstetrics and gynecology in nursing

Awt

  • 1. Rakesh Ravaso Patil Dept. of Computer Engg. T.E. „B‟ 12276
  • 2. Overview…  Introduction to AWT  Swing vs. AWT  Building GUI  Component Hierarchy  AWT Control Fundamentals  Adding Components  Arranging Components  Overview of Event Handling  Working with Graphics  Conclusion
  • 3. AWT (Abstract Window Toolkit)  Present in all Java implementations  Adequate for many applications  Uses the controls defined by your OS  Difficult to build an attractive GUI  import java.awt.*;  import java.awt.event.*;
  • 4. Swing  Same concepts as AWT  Doesn‟t work in ancient Java implementations (Java 1.1 and earlier)  Many more controls, and they are more flexible  Some controls, but not all, are a lot more complicated  Gives a choice of “look and feel” packages  Much easier to build an attractive GUI  import javax.swing.*;
  • 5. Swing vs. AWT  Swing is bigger, slower, and more complicated  But not as slow as it used to be  Swing is more flexible and better looking  Swing and AWT are incompatible--you can use either, but you can‟t mix them  Actually, you can, but it‟s tricky and not worth doing  Learning the AWT is a good start on learning Swing  Many of the most common controls are just renamed  AWT: Button b = new Button ("OK");  Swing: JButton b = new JButton("OK");
  • 6. To build a GUI...  Create some Components, such as buttons, text areas, panels, etc.  Add your Components to your display area  Arrange, or lay out, your Components  Attach Listeners to your Components  Interacting with a Component causes an Event to occur  A Listener gets a message when an interesting event occurs, and executes some code to deal with it
  • 7. An Applet is Panel is Container java.lang.Object | +----java.awt.Component | +----java.awt.Container | +----java.awt.Panel | +----java.applet.Applet …so you can display things in an Applet
  • 8. Example: A "Life" applet Container (Applet) Containers (Panels) Component (Canvas) Components (Buttons) Components (TextFields) Components (Labels)
  • 9. Some types of components Label Button Checkbox Choice Scrollbar TextField List TextArea Button Checkbox CheckboxGroup
  • 10. Creating components  Label lab = new Label ("Hi, Dave!");  Button but = new Button ("Click me!");  Checkbox toggle = new Checkbox ("toggle");  TextField txt = new TextField ("Initial text.", 20);  Scrollbar scrolly = new Scrollbar (Scrollbar.HORIZONTAL, initialValue, bubbleSize, minValue, maxValue);
  • 11. Adding components to the Applet class MyApplet extends Applet { public void init () { add (lab); // same as this.add(lab) add (but); add (toggle); add (txt); add (scrolly); ...
  • 12. Arranging components  Every Container has a layout manager  The default layout for a Panel is FlowLayout  An Applet is a Panel  Therefore, the default layout for a Applet is FlowLayout  You could set it explicitly with setLayout (new FlowLayout( ));  You could change it to some other layout manager
  • 13. Flow Layout  Use add(component); to add to a component when using a FlowLayout  Components are added left-to-right  If no room, a new row is started  Exact layout depends on size of Applet  Components are made as small as possible  FlowLayout is convenient but often ugly
  • 14. BorderLayout  At most five components can be added  If you want more components, add a Panel, then add components to it. •setLayout (new BorderLayout());
  • 15. GridLayout  The GridLayout manager divides the container up into a given number of rows and columns:  new GridLayout(rows, columns) •All sections of the grid are equally sized and as large as possible
  • 16. Making components active  Most components already appear to do something-- buttons click, text appears  To associate an action with a component, attach a listener to it  Components send events, listeners listen for events  Different components may send different events, and require different listeners
  • 17. Listeners  Listeners are interfaces, not classes  class MyButtonListener implements ActionListener {  An interface is a group of methods that must be supplied  When you say implements, you are promising to supply those methods
  • 18. Writing a Listener  For a Button, you need an ActionListener b1.addActionListener (new MyButtonListener ( ));  An ActionListener must have an actionPerformed(ActionEvent) method public void actionPerformed(ActionEvent e) { … }
  • 19. Listeners for TextFields  An ActionListener listens for someone hitting the Enter key  An ActionListener requires this method: public void actionPerformed (ActionEvent e)  You can use getText( ) to get the text  A TextListener listens for any and all keys  A TextListener requires this method: public void textValueChanged(TextEvent e)
  • 20. Working With Graphics Circle Triangle Rounded Rectangle Arc Ellipse Rectangle Lines
  • 21. Working with Graphics  void drawLine(int x1, int y1, int x2, int y2)  void drawRect(int top, int left, int width, int height)  void drawRoundRect(int top, int left,int width, int height, int xDiam, int yDiam)  void drawOvel(int top, int left, int width, int height)  void drawArc(int top, int left, int width,int height, int startAngle, int sweepAngle)  void drawPoly(int x[], int y[], int numPoints)  void fill….
  • 22. Format Shape  Working with colors  HSB  RGB  static int HSBtoRGB(float hue, float saturation, float brightness)  Static float[] RGBtoHSB(int red, int green, int blue, float value[])  Working with Fonts  Font(String fontName, int fontStyle, int pointSize)
  • 23. Summary : Building a GUI  Create a container, such as Frame or Applet  Choose a layout manager  Create more complex layouts by adding Panels; each Panel can have its own layout manager  Create other components and add them to whichever Panels you like  For each active component, look up what kind of Listeners it can have  Create (implement) the Listeners  often there is one Listener for each active component
  • 24. Summary: Building a GUI  For each Listener you implement, supply the methods that it requires  For Applets, write the necessary HTML  Graphics  Drawing Lines  Drawing Rectangles  Drawing Ellipse and Circles  Drawing Polygons  Color schemes and Fonts