AWT Components and Containers

Slides:



Advertisements
Similar presentations
Chapter 3 – Web Design Tables & Page Layout
Advertisements

Objectives The objectives of this chapter are: To discuss the classes present in the java.awt package To understand the inheritance hierarchy of the AWT.
AWT Components. 2 Using AWT Components 4 Component –Canvas –Scrollbar –Button –Checkbox –Label –List –Choice –TextComponent –TextArea –TextField 4 Component.
CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
Graphical User Interfaces CS 2110 Spring Ivan Sutherland: “Sketchpad”,
Jan AWT Widgets Yangjun Chen Dept. Business Computing University of Winnipeg.
Standard Components and Their Events GUI interface elements are represented by subclasses of component: –Button class –Label class –TextField class –Checkbox.
1 Simple Phone Applet Lab Mobile Phone Display Area Send, Menu and End Numbers 0-9 * and #
Swinging Into Swing Leo S. Primero III. Understanding what Swing Is Swing is a package that lets you create applications that use a flashy Graphical User.
CS3157 Java UI Recitation. Material Covered: Overview of AWT components, Event Handling, creating applets, and sample UI. Not covered in recitation: Drawing,
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
12-Jul-15 Components. 2 Types of Components Button Canvas Checkbox Choice Label List Scrollbar TextComponent TextArea TextField.
AWT Components (Chapter 9) Java Certification Study Group January 21, 1999 Mark Roth.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Universidad Nacional de Colombia Facultad de Ingeniería Departamento de Sistemas ertificación en AVA.
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
Abstract Window Toolkit (AWT) The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include:  A rich set.
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.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
Visual Basic Programming Introduction VB is one of the High level language VB has evolved from the BASIC language. BASIC stands for Beginners All-purpose.
May 12, 1998CS102-01Lecture 7-3 Building GUIs in Java I CS Lecture 7-3 A picture's worth a thousand words.
Csc Basic Graphical User Interface (GUI) Components.
AWT Package. Java GUI classes are contained in the java.awt package. Java GUI classes are contained in the java.awt package. A graphical Java program.
Basics of GUI Programming Chapter 11 and Chapter 22.
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
CSI 3125, Preliminaries, page 1 AWT Control. CSI 3125, Preliminaries, page 2 AWT Control The AWT supports the following types of controls: ■ Labels ■
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.
Java Programming, Second Edition Chapter Thirteen Understanding Swing Components.
Copyright © Curt Hill More Widgets In Abstract Window Toolbox.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Lecture # 6 Graphical User Interface(GUI). Introduction A graphical user interface (GUI) presents a user- friendly mechanism for interacting with an application.
20-753: Fundamentals of Web Programming 1 Lecture 6: Advanced HTML Fundamentals of Web Programming Lecture 6: Advanced HTML.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
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.
Chapter 3: Widgets for a GUI General Component methods Useful widgets classes –Text classes Label TextField TextArea –Active widgets Button Checkbox Choice.
AWT AWT stands for Abstract Windowing Toolkit. It contains all classes to write the program that interface between the user and different windowing toolkits.
ANDROID LAYOUTS AND WIDGETS. Slide 2 Introduction Parts of the Android screen Sizing widgets and fonts Layouts and their characteristics Buttons, checkboxes.
Java Programming (By Rama Bhadra Rao M) You can Trace me in Day 5
GUI building with the AWT
Christopher Budo, Davis Nygren, spencer franks, Luke miller
Aum Amriteshwaryai Namah
Advanced GUIs II CS Lecture
Java Swing.
Graphical User Interface (pronounced "gooey")
Abstract Window ToolKit (AWT)
Chap 7. Building Java Graphical User Interfaces
Chapter 13: Advanced GUIs and Graphics
Graphical User Interfaces -- Introduction
AWT.
Tutorial 6 Creating Dynamic Pages
Graphics Programming - Frames
Topics Graphical User Interfaces Using the tkinter Module
Practice Activity – Part 1
Introduction to Graphical Interfaces in Java: AWT and Swing
Menu Bars and Menus.
AWT Components Java AWT components are platform-dependent i.e. components are displayed according to the view of operating system. AWT is heavyweight i.e.
Objectives The objectives of this chapter are:
Advanced GUIs II CS Lecture
A picture's worth a thousand words
Advanced GUIs and Graphics
Graphical User Interface
TA: Nouf Al-Harbi NoufNaief.net :::
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

AWT Components and Containers Ch 19. AWT Components and Containers

1 getLocation() - This method is used to get position of the component, as a Point. The usage of the method is shown below. Point p = someComponent.getLocation();  int x = someComponent.getX();  int y = someComponent.getY();  getSize() - This method is used to get the current size of component. Dimension d = someComponent.getSize();  int height = d.height;  int width = d.width;  int height = someComponent.getHeight();  int width = someComponent.getWidth(); 

setBackground(Color)/setForeground(Color) - This method is used to change the background/foreground colors of the component. setFont(Font) - This method is used to change the font of text within a component. setVisible(boolean) - This method is used for the visibility state of the component. The component appears on the screen if setVisible() is set to true and if its set to false then the component will not appear on the screen. setEnabled(boolean) - This method is used to toggle the state of the component.

java.awt package contains many classes and methods that allow us to create and manage GUI based components . It is used in applets to create web applications but can also be used to create stand-alone applications . Component Management Event Handling Layout Management Graphics Rendering

UI elements of AWT : UI Components Layout Managers Containers Events

Label (String Text, int Alignment) Labels :generally used to show the text or string in your application and label never perform any type of action. Syntax ::  Label () Creates a blank Label instance. Label (String Text) Creates a Label instance with the specified text. Label L1 = new Label ("This is the label text."); Label (String Text, int Alignment) Creates a Label instance with the specified text and horizontal alignment. Label l1 = new Label ("This is the label text.", Label.CENTER); Justification of label can be left, right or centered.  

The key thing to remember about adding components to the applet is the three steps: Declare the component Initialize the component Add the component to the layout.

void setBackground (Color BgdColor) void setAlignment (int Alignment) Sets the color of the background for the label. void setAlignment (int Alignment) Sets the alignment of the label's contents along the X axis. void setFont (Font TextFont) Sets the font for this component.Arguments void setForeground (Color TextColor) Sets the color of the text for the label. void setText (String Text) Sets the text for the label.

Buttons : It is used to trigger actions and other events required for your application. Syntax: Button button_name = new Button (“Label."); Button.setLabel(String) and Button.getLabel() method. Buttons are added to the it's container using the add (button_name) method.   

TextField (String Text) Text Field:. This component contains single line and limited text information. TextField () Creates a blank TextField instance. TextField (String Text) Creates a TextField instance with the specified text. TextField (int Columns) Creates a blank TextField instance with the specified number of columns. TextField (String Text, int Columns) Creates a TextField instance with the specified text and the specified number of columns.

void setBackground (Color BackgroundColor) String getText () Returns the text in the field. void setBackground (Color BackgroundColor) Sets the background color of the TextField. void setEditable (boolean Editable) Sets the field as being editable or fixed. void setFont (Font TextFont) Sets the font for this component. void setText (String Text) Sets the text for the field.

Check Boxes : creates check boxes in your applications. CheckBox () Creates a blank CheckBox instance. CheckBox (String Text) Creates a CheckBox instance with the specified text. CheckBox (String Text, boolean Selected) Creates a CheckBox instance with the specified text and the designated selection state.

void setBackground (Color BackgroundColor) boolean isSelected () Returns the state (checked or not checked) of the checkbox. void setBackground (Color BackgroundColor) Sets the background color of the checkbox. void setState (boolean State) Sets the state (checked or not checked) of the checkbox. void setFont (Font TextFont) Sets the font for this component. void setForeground (Color TextColor) Sets the color of the text for the checkbox. void setLabel (String Text) Sets the text for the checkbox.

Radio Button : This is used as a group of checkboxes which group name is same. Only one CheckboxGroup chkgp = new CheckboxGroup(); add (new Checkbox ("One", chkgp, false); add (new Checkbox ("Two", chkgp, false);

Text Area: The TextArea class is a GUI component which can be used to provide multiple line text input or output. TextArea () Creates a blank TextArea instance. TextArea (String Text) Creates a instance with the specified text. TextArea (int Rows, int Columns) Creates a blank instance with the specified number of rows and columns. TextArea (String Text, int Rows, int Columns) Creates a TextArea instance with the specified text ,number of rows and columns.

Conatants for SCrollBars; SCROLL_BARS_BOTH SCROLL_BARS_VETICAL_ONLY SCROLL_BARS_HORIZONTAL_ONLY SCROLL_BARS_NONE String getText () Returns the text in the field. void setBackground (Color BackgroundColor) Sets the background color of the TextArea. void setEditable (boolean Editable) Sets the field as being editable or fixed. void setFont (Font TextFont) Sets the font for this component. void setText (String Text) Sets the text for the field.

Choice () Creates an empty Choice instance. void insert (String Item, int Index) Inserts the item into this choice at the specified position. int getSelectedIndex () Returns the index of the selected item. void setBackground (Color BackgroundColor) Sets the background color of the choice box. void setFont (Font TextFont) Sets the font for this component. void setForeground (Color TextColor) Sets the color of the text for the choice box. void Select (int Selection) Sets the index of the selected item.

List (int Rows, boolean MultiSelect) Creates an empty List instance with the default 4 rows visible. List (int Rows) Creates an empty List instance with the specified number of visible rows. List (int Rows, boolean MultiSelect) Creates an empty List instance with the specified number of visible rows and the specified MultiSelect switch.

void add (String Item, int Index) Inserts the item into this choice at the next position. void add (String Item, int Index) Inserts the item into this choice at the specified position. int getSelectedIndex () Returns the index of the selected item. String getSelectesItem(); In case of Multiselect : String[]getSelectesItem(); Int getSelectedIndexes();

Scrollbar() Scrollbar(int orientation) Scrollbar(int orientation, int value, int visible, int min, int max) Orientation Scrollbar.HORIZONTAL or Scrollbar.VERTICAL. visible represents the size of the visible portion of the scrollable area in pixels. The Scrollbar uses this when moving up or down a page.

Canvas is a region where you can draw things such as circles, triangles, ovals or any other shape. It is a graphical component that represents a region. It has got a default method which is paint() method.

Other Container Classes Panels:To make Applet or Frame layout easier, we break a frame up into regions and compose each of them separately. Each region is called a Panel. Each can have its own different LayoutManager. Panels don’t have any visible borderlines,title or menu. We can delimit them with differing background colours.

A Window is a top-level window with no borders and no menubar. Window(Frame) Constructs a new Window initialized to an invisible state. pack() Packs the components of the WIndow. show() Shows the Window. dispose() Disposes of the Window.

A Frame is a top-level window ,a subclass of Window. It has title bar,menubar,borders and resize corners. It is normally used as the main window of a standalone application. Frame () Creates a blank instance. Frame (String Text) Creates a Frame instance with the specified text in the title bar.

setSize (int Width, int Height) Resizes this window so that it has the specified Width and Height. setTitle (String Text) Sets the text for the title bar. show () Makes the window visible.

Hierarchy Sample Frame Panel Panel Panel Panel Label Label Label Text Field Text Field Text Field Scrollbar Scrollbar Scrollbar Panel Button Button Button

Dialog A Dialog is a top-level window with a title and a border that is typically used to take some form of input from the user. Dialogs are useful specifically to take input because they can be made to block input to other Window objects until the user finishes with the Dialog Restrictions : Cannot have menu. Cannot be resized. Must be opened by parent window .

The FileDialog class displays a dialog window from which the user can select a file . getFile() method returns the current file selection from the FileDialog . getDirectory() returns the current directory for the FileDialog .

Menu Component –an abstract class ,is super class of all menu related classes. To create an instance of MenuBar Class: MenuBar mb=new MenuBar(); setMenuBar(mb); Attatch it to frame . To create popup Menu m=new Menu(“File”); MenuItems m.add(new MenuItem(open”);