GUI and Event Driven Programming-GUI Programming-Lecture Slides, Slides of Computer Engineering and Programming

This lecture was delivered by Aniruddh Parmar at B. R. Ambedkar Bihar University for Data Transfer Programming course. It includes: GUI, Event, Driven, Programming, Portability, Library, Classes, Platform, Hierarchy, Container, Helper, Swing, Components

Typology: Slides

2011/2012

Uploaded on 07/11/2012

dhananad
dhananad 🇮🇳

4

(4)

39 documents

1 / 23

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
GUI and Event Driven
Programming
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17

Partial preview of the text

Download GUI and Event Driven Programming-GUI Programming-Lecture Slides and more Slides Computer Engineering and Programming in PDF only on Docsity!

GUI and Event Driven

Programming

Portability

 The java.awt library contains heavyweight

classes

 Implemented via the Java Virtual Machine

 Dependent on target platform

 The javax.swing library contains lightweight

classes

 Implemented in Java

 Independent of target platform

Container Classes

Dimension
Font
FontMetrics
Component
Graphics
Object Color
Container
Panel Applet
Frame
Dialog
Window
JComponent
JApplet
JFrame
JDialog

Swing Components in the javax.swing package Lightweight Heavyweight Classes in the java.awt package 1 LayoutManager

JPanel

GUI Helper Classes

Dimension
Font
FontMetrics
Component
Graphics
Object Color
Container
Panel Applet
Frame
Dialog
Window
JComponent
JApplet
JFrame
JDialog

Swing Components in the javax.swing package Lightweight Heavyweight Classes in the java.awt package 1 LayoutManager

JPanel

Core Swing Components

JMenuItem JCheckBoxMenuItem

AbstractButton
JComponent

JMenu JRadioButtonMenuItem JToggleButton (^) JCheckBox JRadioButton JComboBox JInternalFrame JLayeredPane JList JMenuBar JOptionPane JPopupMenu JProgressBar JFileChooser JScrollBar JSplitPane JSeparator JScrollPane JSlider JTabbedPane JTable JTableHeader JTextComponent JTextField JTextArea JToolBar (^) JToolTip JTree JRootPane JPanel JPasswordField JColorChooser JLabel JEditorPane JSpinner JButton

AWT Classes

AWTEvent
Font
FontMetrics
Component
Graphics
Object Color
Canvas
Button

TextComponent

Label
List
CheckBoxGroup
CheckBox
Choice
Container Panel Applet
Frame
Dialog FileDialog
Window
TextField
TextArea
MenuComponent MenuItem
MenuBar
Menu
Scrollbar

LayoutManager

Content Frame Delegation

 In Java 1.4, required to add GUI elements to

content panes:

frame.getContentPane().add(new JButton(“OK”));

 In Java 1.5, frame delegates automatically to the

content pane:

frame.add(new JButton(“OK”));

Frames as Containers

 All JFrame objects act as container objects

 GUI objects are added (much like an ArrayList), then

displayed when requested

 A layout manager describes how GUI objects are to be

displayed

 FlowLayout  GridLayout  BorderLayout  GridBagLayout The order in which objects are added matters to FlowLayout and GridLayout layout managers

Color (ii)

 Most GUI components are colorable :

setBackground(Color c) setForeground(Color c)

Fonts (i)

 Use the java.awt.Font class to work with fonts:

Font font = new Font(name, style, pointSize);

 Examples:

Font f1 = new Font(“Serif”, Font.PLAIN, 12); Font f2 = new Font(“SansSerif”, Font.BOLD, 16); Font f3 = new Font(“Monospaced”, Font.BOLD + Font.ITALIC, 16); Font f4 = new Font(“Times New Roman”, Font.PLAIN, 16);

Event-Driven Programming (i)

 In event-driven programming , code is executed

upon activation of events

 Events include mouse movements, mouse clicks, mouse

drags, keystrokes, timer expirations, operating system

events, etc.

EventObject AWTEvent AdjustmentEvent ComponentEvent TextEvent ItemEvent ActionEvent InputEvent WindowEvent MouseEvent KeyEvent ContainerEvent FocusEvent PaintEvent ListSelectionEvent

Event-Driven Programming (ii)

Source Event Type User Action Object Generated Click a button JButton ActionEvent Click a check box JCheckBox ItemEvent, ActionEvent Click a radio button JRadioButton ItemEvent, ActionEvent Press return on a text field JTextField ActionEvent Select a new item JComboBox ItemEvent, ActionEvent Window opened, closed, etc. Window WindowEvent Mouse pressed, released, etc. Component MouseEvent Key released, pressed, etc. Component KeyEvent

Event-Driven Programming (iii)

 Listener classes respond to actions

 e.g. override the java.awt.event.actionPerformed()

method

 Listener classes must be registered with the GUI

objects they are listening for:

 e.g. via the okButton.addActionListener() method

Mouse Events (i)

java.awt.event.MouseEvent +getButton(): int +getClickCount(): int +getPoint(): java.awt.Point +getX(): int +getY(): int Indicates which mouse button has been clicked. Returns the number of mouse clicks associated with this event. Returns a Point object containing the x and y coordinates. Returns the x-coordinate of the mouse point. Returns the y-coordinate of the mouse point. java.awt.event.InputEvent +getWhen(): long +isAltDown(): boolean +isControlDown(): boolean +isMetaDown(): boolean +isShiftDown(): boolean Returns the timestamp when this event occurred. Returns whether or not the Alt modifier is down on this event. Returns whether or not the Control modifier is down on this event. Returns whether or not the Meta modifier is down on this event Returns whether or not the Shift modifier is down on this event.