Objectives of This Session

Slides:



Advertisements
Similar presentations
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Advertisements

Corresponds with Chapter 12
Unit 091 Introduction to GUI Programming Introduction to User Interfaces Introduction to GUI Programming GUI Design Issues GUI Programming Issues Java.
1 Chapter 7 Graphics and Event Handling. 2 Overview The java.awt and javax.swing packages and their subpackages support graphics and event handling. Many.
CS3157 Java UI Recitation. Material Covered: Overview of AWT components, Event Handling, creating applets, and sample UI. Not covered in recitation: Drawing,
JFC and the Swing Package Feb 10, Java Foundation Class (JFC) zAWT (Abstract Window Toolkit) has been used since jdk1.0 Archaic and very poorly.
1 lecture 12Lecture 13 Event Handling (cont.) Overview  Handling Window Events.  Event Adapters Revisited.  Introduction to Components and Containers.
Java GUI building with the AWT. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
GUI Basics: Introduction. Creating GUI Objects // Create a button with text OK JButton jbtOK = new JButton("OK"); // Create a label with text "Enter your.
GUI Programming in Java
Draw Shapes Introduction to simple graphics. What is a Component? A class that resides in the java.awt package Examples include: –Button, java.awt.Button.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Introduction to GUI in Java 1. Graphical User Interface Java is equipped with many powerful,easy to use GUI component such as input and output dialog.
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Java GUI building with Swing. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Java Programming 1 Java Programming II Events, AWT, and Swing.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Abstract Window Toolkit (AWT) The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include:  A rich set.
GUI Chapter 10 Graphics context and objects Creating a window based application JFrame, JTextField, JButton Containers and Controls Graphics commands Layout.
10/24/20151 Java GUI Programming. 10/24/20152 What is a GUI? Java has standard packages for creating custom Graphical User Interfaces Some of the fundamental.
Session 27 Swing vs. AWT. AWT (Abstract Window ToolKit) It is a portable GUI library for stand-alone applications and/or applets. The Abstract Window.
CSTP FS99CS423 (cotter)1 Java Graphics java.awt.*;
1 Block1 – unit 2 (The Case study in Budd 5-6).  create a small application that uses the Abstract Windowing Toolkit (AWT)  Swing packages to simulate.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
– Advanced Programming P ROGRAMMING IN Lecture 21 Introduction to Swing.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
1 Unit 5 GUI Aum Amriteshwaryai Namah. 2 Overview Shall learn how to reuse the graphics classes provided by Java for constructing Graphical User Interface.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Applets Yong Choi School of Business CSU, Bakersfield.
GUI Basics. What is GUI? A graphical user interface (GUI) is a type of user interface item that allows people to interact with programs in more ways than.
 GUI – Graphic User Interface  Up to now in the programs we have written all output has been sent to the standard output device i.e.: the DOS console.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
9.1 Java Packages A collection of classes Allows classes to be grouped arbitrarily Hierarchical structure independent of inheritance Classes can.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Week 6: Basic GUI Programming Concepts in Java Example: JFrameDemo.java container : a screen window/applet window/panel that groups and arranges components.
Ch13 Creating windows and applets. Short overview AWT (Abstract Windowing Toolkit) Early Java development used graphic classesEarly Java development used.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
Swing. Introduction to Swing What is Swing? “ Swing is a diverse collection of lightweight components that can be used to build sophisticated user interfaces.”
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
CSI 3125, Preliminaries, page 1 AWT. CSI 3125, Preliminaries, page 2 AWT Java AWT (Abstract Windowing Toolkit) is an API to develop GUI or window-based.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Computer Science [3] Java Programming II - Laboratory Course Lab 4 -1 : Introduction to Graphical user interface GUI Components Faculty of Engineering.
SE-1020 Dr. Mark L. Hornick 1 Graphical User Interfaces.
Lecture # 6 Graphical User Interface(GUI). Introduction A graphical user interface (GUI) presents a user- friendly mechanism for interacting with an application.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
1 Lecture 8: User Interface Components with Swing.
AWT Java AWT (Abstract Windowing Toolkit) is an API to develop GUI or window-based application in java. Java AWT components are platform-dependent i.e.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
CPCS 391 Computer Graphics Lab One. Computer Graphics Using Java What is Computer Graphics: Computer graphics are graphics created using computers and,
AWT Vs SWING. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses.
Lecture 6 Object Oriented Programming Using Java By Rashid Ahmad Department of Computer Science University of Peshawar.
A Quick Java Swing Tutorial
CSC 205 Programming II Lecture 5 AWT - I.
GUI building with the AWT
Welcome To java
Lecture 8 Object Oriented Programming Using Java
Abstract Window ToolKit (AWT)
Ellen Walker Hiram College
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Graphics Programming - Frames
Week 8 Swing NetBeans GUI Builder
Advanced Programming in Java
GUI building with the AWT
Chapter 12 GUI Basics.
Presentation transcript:

Objectives of This Session Identify the need for AWT State the hierarchy of classes in AWT Demonstrate the first AWT class (using Graphics class). Identify the Component & Container classes Demonstrate an AWT class with components. Explain the functioning of AWT with Peer Classes Explain callback mechanism

Identify the Need for AWT To visually enhance applets & applications. i.e. Java programmer should be able to write programs that move & size windows, put components, display text & colors, fonts etc Till now we saw only how to write applications that may take user I/p’s , display results on the System console. But modern programs & web pages do not work like this. By providing different applications with a consistent set of intuitive user interface components, GUI’s allow user to spend less time in trying to remember which key stroke sequences do what & spend more time using the program in a productive manner. Need for Java prg to have more GUI.java had to find a way to write applications that would be GUI & platform independent. While trying to provide a common solution, developers had to consider so many drawbacks: Eg : Mac can have only one button mouse. It does not have picture buttons like windows95.

The AWT Library AWT is a general-purpose, multi-platform windowing library. It’s a standard part of Java environment. Provides all the basic functionality that may be needed for use in developing GUI application. Provides classes that encapsulate many useful GUI components.

AWT Class import java.awt.*; class MyFrame extends Frame { public void paint(Graphics g) g.drawString(“Hello world”,50,50); } public static void main(String args[]) Frame f = new MyFrame(); f.setSize(100,100); f.show(); The Frame class: The Window class is derived from Container class. Although it is not an abstract class, you rarely create Window objects. But it is the root class for 2 very useful classes: Frame & Dialog. Window & its derived classes allow you to create windows that can float over & even outside the browser window. Frame is derived from Container class, Thus, it can contain other controls, Images & text. When a frame is created, it is by default invisible. & its size is 1X1 pixels. The paint() method: Seldom called directly by the programmer because drawing graphics is an event-driven process. It is called automatically when window has to be repainted. It works like WM_Paint of windowing software. The OS sends a message to the windowing system, whenever a event like above occurs.

The Color Class Defines methods & constants for manipulating colors in a Java program. Every color is created from a red, green & blue component. To change color, you must create a Color object or use one of the predefined Color constants.

The Font Class Allows to create a font object that will display text in a particular font. The number of fonts varies greatly across systems. Java uses standardized font names & maps these into system-specific font names for portability. JDK guarantees that fonts Serif, Monospaced, Sans serif, Dialog & Dialog Input will be available. Specifying a font that is not available on a system is a logic error. Java will substitute that system’s default font.

The Color & Font Class public void paint(Graphics g) { g.setColor(Color.blue); Font f = new Font(“TimesRoman”,Font.BOLD,20); g.setFont(f); g.drawString(“Hello World”, 50,50); }

Graphics Class Graphics is an abstract class. A graphics context enables drawing on screen in Java. A Graphics object encapsulates state info needed for the basic rendering options that java supports. It remembers a collection of settings for drawing images &text. All drawing in Java must go through a Graphics object.

Graphics Class Why is Graphics class an abstract class ? Reason is : Java’s Portability Graphics capabilities that enable a PC running windows are different from ones that enable a UNIX workstation to draw a rectangle. When Java is implemented on each platform, a derived class of Graphics is created that actually implements the drawing capabilities. E.g. WGraphics class for Windows

AWT(Components) Button Checkbox Choice Menu TextField Scrollbar Canvas CheckboxGroup List Label TextArea ScrollPane

Component Hierarchy in AWT Object Component Scrollbar Canvas Checkbox Choice Label Text Component Text Area List Text Field Container

AWT (Container) FileDialog Frame Dialog Panel Window Container Component

AWT(Geometry) Several classes in AWT package provide handy encapsulation of int values related to screen geometry. Dimension Insets Point Polygon Rectangle

Java Class Using Components import java.awt.*; class MyFrame extends Frame { TextField t1; Button b1; MyFrame() t1 = new TextField(20); b1 = new Button(“Click”); setLayout(new FlowLayout( )); add(t1); add(b1); }

Java Class Using Components public static void main(String args[]) { Frame f = new MyFrame(); f.setSize(100,100); f.show(); }

AWT(Toolkit) Toolkit class: encapsulates details of the underlying OS & h/w that a JVM is running on. This object is created when the JVM starts, before any of the application classes are loaded. Toolkit defines the methods that create OS peers for AWT components These methods are called automatically as the components are created & thus shouldn't be called by the programmer. You can get a Toolkit object with the getDefaultToolkit() method of Toolkit class.

The Callback Mechanism Callback is an important concept for Event driven programming. Callback means that the programmer should give the implementation of a method. The programmer does not call the method but there is an arrangement such that some callback program invokes the method when required.

Peers How does the basic AWT library deal with user interface elements? By delegating their creation & behavior to the native GUI toolkit on each target platform. The resulting program will then run on any platform with the “look & feel” of the target platform.

Swing Components Hierarchy java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent Swing Components

Swing The AWT library took help of underlying OS to generate peers for each UI component. Swing components are purely written in Java. Therefore lightweight, since no peers are created. Also they need not take on the “look & feel” of the target platform ; thus helps in maintaining a consistent “look & feel” over all platforms.

Swing Program public class SwingFrame extends JFrame { JButton b1, b2; JTextField tf; public SwingFrame() tf=new JTextField(); b1=new JButton(“Click”); b2=new JButton (“Cancel”);

Swing Program Container cp=getContentPane(); cp.add(b1); cp.add(b2); cp.add(tf); } public static void main(String str[]) { JFrame f=new SwingFrame(); f.setSize(800,800); f.setVisible(true);