Package java'awt - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Package java'awt

Description:

Can use child when parent is expected. // add to and remove from ... public void run() throws IOException. line = stdin.readline(); while ( line != null ) ... – PowerPoint PPT presentation

Number of Views:60
Avg rating:3.0/5.0
Slides: 16
Provided by: qya
Category:

less

Transcript and Presenter's Notes

Title: Package java'awt


1
Package java.awt
2
Abstract Windowing Toolkit (AWT)
  • Graphical User Interfaces (GUIs)
  • Component (control)
  • Event
  • Font
  • Graphics
  • . . .

3
Small Piece of Java AWT Class Hierarchy
  • class java.lang.Object
  • class java.awt.Component
  • class java.awt.Button
  • class java.awt.Checkbox
  • class java.awt.Container
  • class java.awt.Panel

  • java.applet.Applet
  • class java.awt.Window
  • class java.awt.Dialog
  • class java.awt.Frame
  • class java.awt.Label
  • class java.awt.List
  • class java.awt.TextComponent
  • class java.awt.TextArea
  • class java.awt.TextField
  • class java.awt.Event
  • class java.awt.Graphics
  • class java.awt.Font

4
Component
  • Abstract superclass of the non-menu-related AWT
    components
  • Interacts with the user
  • Has graphical representation, displayed on the
    screen
  • Examples buttons, checkboxes, text fields
  • Methods
  • setSize
  • setLocation
  • paint
  • repaint

5
TextField
  • Single line of text
  • Subclass of AWT Component
  • import java.awt.
  • Methods
  • getString
  • setString

6
List
  • List of Strings
  • Subclass of AWT Component
  • import java.awt.
  • Methods
  • add
  • remove
  • getSelectedIndex

7
Container
  • Can contain other AWT components
  • Subclass of Component
  • import java.awt.
  • It has some subclasses
  • Panel
  • Window
  • Dialog
  • Frame

8
Graphics
  • Allow an application to draw onto components
  • Abstract base class for all graphics contexts
  • import java.awt.
  • Encapsulates state information
  • color, font, object on which to draw,
    etc.
  • Methods
  • public void drawLine(int x1, int y1, int x2,
    int y2)
  • void drawString(String str, int x, int y)
  • void drawOval(int x, int y, int width,
    int height) // x,y upper-left
  • void setColor(Color c)
    // set current drawing color
  • void setFont(Font font)

9
Timer
  • Fires action events after a specified delay
  • Not AWT
  • import javax.swing.Timer
  • Methods
  • start
  • stop
  • Change timeout time

10
Event
  • GUI Programs
  • Event Driven
  • Event Examples
  • Clicking on a button
  • Selecting Yes or No
  • Moving the mouse
  • Pressing a key
  • Resizing a window
  • Closing a window

11
Events Handling
  • Exceptions Handling
  • defining exception class
  • throw / throws
  • try-catch
  • statements to handle exceptions
  • Defining an event
  • Raising an event
  • Receiving an event
  • Responding to an event

12
Events Handling
  • Defining an event
  • Class ActionEvent
  • import java.awt.event.
  • Raising an event
  • inside a class
  • Receiving an event
  • Interface ActionListener
  • import java.awt.event.
  • Responding to an event
  • actionPerformed
  • method of ActionListener

13
Events Handling
  • NetBeans generates all necessary code for us
  • Responding to an event
  • In NetBeans
  • InsertCode
  • Implement Method
  • actionPerformed
  • Double click
  • NetBeans does almost all the work for us!

14
Java Applet
  • Subclass of Panel (which was a subclass of
    Container)
  • Embedded in another application (not run on its
    own)
  • Calling an Applet from an HTML file
  • ltapplet codebase"classes code"MyApplet.class"
    width800 height600gt lt/appletgt
  • NetBeans does almost all the work for us!

15
Prog5
Lab 5
Quiz4
Write a Comment
User Comments (0)
About PowerShow.com