DOC PREVIEW
UMD CMSC 132 - Object-Oriented Programming II

This preview shows page 1-2-3-4 out of 13 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CMSC 132: Object-Oriented Programming IICreating GUIsGUI (Graphical User Interface)Java GUI ClassesGUI ClassesHow to Create a GUIJFrame HierarchyExamplesEvent Dispatching Thread (From Wikipedia)Event Dispatching ThreadGUI Elements – LayoutJava Layout ManagersExample1CMSC 132: Object-Oriented Programming IINelson Padua-PerezWilliam PughDepartment of Computer ScienceUniversity of Maryland, College Park2Creating GUIsResourcesAppendix C of textbook Javadoc for the JDKSwing tutorialCourse slides and code handoutsJava Ranch3GUI (Graphical User Interface)You create GUIs by defining objects such asText fieldsLabelsButtonsCheckboxesRadioboxesMenusTablesEtc.4Java GUI ClassesAWT (Abstract Window Toolkit) (java.awt.*)Old GUI framework for Java (Java 1.1)Some reliance on native code counterpartsPlatform independence problemsSwing (javax.swing.*)New GUI framework first introduced in Java 1.2Includes AWT features plus many enhancementsPure Java components (no reliance on native code)Pluggable look and feel architectureSWT (Standard Widget Toolkit; from Eclipse)5GUI ClassesGUI classes can be organized in three groupsContainer classes – Hold other GUI ComponentsJFrame -JPanelJAppletComponent classes – (e.g., JButton, JTextfield, etc.)Helper classes – Describe properties of other GUI ComponetsColorGraphicsDimensionOther6How to Create a GUIDefine a Frame or Applet to hold the components. From now on we will use only frames.Add components to the frameAdd actions to your GUI by adding listeners to GUI components7JFrame HierarchySeveral super classes and well as implemented interfacesMany, member methods including inherited methods that allow for operations such as resizing, setting properties, adding components, etc.ObjectComponentContainerWindowFrameJFrame9ExamplesExamples in gui.jarFor now our examples have no action associated with them.Let’s see example in ex1 packageex2 is basically ex1 but reduced to one class10Event Dispatching Thread (From Wikipedia)Background thread to process events from the AWT graphical interface event queueThese events are mainly update events thatCause components to redraw themselvesRepresent input events Swing uses a single-threaded painting model where only the Event Dispatching thread is the only valid thread that can update user interface componentsUpdating components from other threads is a source of common bugs11Event Dispatching Thread javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndDisplayGUI(); } }); Following code fragment allows the current thread to execute the GUI code in the dispatching thread. createAndDisplayGUI – method that actually defines the GUI12GUI Elements – LayoutDefinitionArrangement of widgets in containerLayout specificationLogical terms (2nd row, 1st column, left)Preferred approachActual coordinates (100 pixels, 5 inches)Can be too rigid, limited to certain window sizes Layout managerEntity translating layout specifications into actual coordinates at runtime, depending on conditions13Java Layout ManagersFlowlayout Lays out components from left to rightGridLayoutLays out components in a grid of user specified sizeBorderLayoutDesignates portions of the container as North, South, East, West, and Center CardLayout Adds components one on top of another GridBagLayout Customizable manager that can use rows and columns of varying lengths14ExampleExample in gui.jarex3 (when manager = LayoutManager.Grid)ex3 (when manager =


View Full Document

UMD CMSC 132 - Object-Oriented Programming II

Documents in this Course
Notes

Notes

8 pages

Recursion

Recursion

12 pages

Sorting

Sorting

31 pages

HTML

HTML

7 pages

Trees

Trees

19 pages

HTML

HTML

18 pages

Trees

Trees

19 pages

Honors

Honors

19 pages

Lecture 1

Lecture 1

11 pages

Quiz #3

Quiz #3

2 pages

Hashing

Hashing

21 pages

Load more
Download Object-Oriented Programming II
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Object-Oriented Programming II and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Object-Oriented Programming II 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?