16Graphical User Interface

16Graphical User Interface - ITI 1121. Introduction to...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ITI 1121. Introduction to Computing II * Marcel Turcotte School of Information Technology and Engineering Version of February 14, 2011 Abstract Graphical components Event-driven programming Inner classes Model-View-Controller * These lecture notes are meant to be looked at on a computer screen. Do not print them unless it is necessary. AWT The Abstract Window Toolkit (AWT) is the oldest set of classes used to build Graphical User Interfaces (GUIs) in Java. It has been part of all the Java releases. A more recent and improved toolkit is called Swing. For this introduction, we will focus on AWT. Components/Containers A graphical element is called a component . Accordingly, there is a class called Component that defines the characteristics that are common to of all components. Components include: windows, buttons, check boxes, menus, text fields, scroll bars, etc. The components that contain other components are called containers . Accordingly, there is a class called Container that defines the characteristics that are common to all the containers. Component Container Component TextArea TextField Window Panel Dialog Frame FileDialog Label TextComponent Canvas List Container Button AWT is a rich source of examples of inheritance. A Component defines a collection of methods that are common to all the graphical objects, such as setBackground( Color c ) and getX() . A Container contains other graphical components, and therefore declares a method add( Component c ) and setLayout( LayoutManager m ) . A Window is a Container that is not contained in any other Container . It defines a method setVisible( boolean ) , addWindowListener( WindowListener l ) , etc. Hello World -1- A Frame is a top-level window with a title and a border. import java.awt.*; public class Run { public static void main( String args ) { Frame f; f = new Frame( "Hello World!" ); f.setSize( 200,300 ); f.setVisible( true ); } } A top-level component is one that is not contained within any other component. DrJava Alternatively, use DrJava to create and experiment with graphical objects. Use the interactions window and type each of the following statements one by one. > import java.awt.*; > Frame f = new Frame( "Hello World!" ); > f.setSize( 100, 200 ); > f.setVisible( true ); > f.setVisible( false ); > f.setVisible( true ); > f.setVisible( false ); Youll see that a Frame of object is not visible unless you make it visible. DrJava Hello World -2- Lets create a specialized Frame that has the required characteristics for this application. import java.awt.*; public class MyFrame extends Frame { public MyFrame( String title ) { super( title ); setSize( 200, 300 ); setVisible( true ); } } Which would be used as follows: public class Run { public static void main( String args ) { Frame f = new MyFrame( "Hello World" ); } } MyFrame is a specialized Frame , which is a specialized Container , therefore, it has the ability to contain other components....
View Full Document

This note was uploaded on 03/02/2012 for the course ITI 1121 taught by Professor Samaan during the Winter '10 term at University of Ottawa.

Page1 / 100

16Graphical User Interface - ITI 1121. Introduction to...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online