{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

16Graphical User Interface

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

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

View Full Document Right Arrow Icon
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.
Image of page 1

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

View Full Document Right Arrow Icon
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.
Image of page 2
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
Image of page 3

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

View Full Document Right Arrow Icon
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 ) .
Image of page 4
A Window is a Container that is not contained in any other Container . It defines a method setVisible( boolean ) , addWindowListener( WindowListener l ) , etc.
Image of page 5

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

View Full Document Right Arrow Icon
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.
Image of page 6
Image of page 7

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

View Full Document Right Arrow Icon
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 ); You’ll see that a Frame of object is not visible unless you make it visible.
Image of page 8
DrJava
Image of page 9

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

View Full Document Right Arrow Icon
Hello World -2- Let’s 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" ); } }
Image of page 10
Image of page 11

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

View Full Document Right Arrow Icon
MyFrame is a specialized Frame , which is a specialized Container , therefore, it has the ability to contain other components.
Image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern