Computer Science [3] Java Programming II - Laboratory Course Lab 4 -1 : Introduction to Graphical user interface GUI Components Faculty of Engineering.

Slides:



Advertisements
Similar presentations
Chapter 11 Creating User Interfaces F What is JavaBean? F JComponent F JButton  ImageIcon  JLabel  JTextField  JTextArea  JComboBox  JList  JCheckBox.
Advertisements

Graphical User Interfaces (Part IV)
Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
1 Chapter 13 Creating User Interfaces. 2 Objectives F To create graphical user interfaces with various user-interface components: JButton, JCheckBox,
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 16 Creating User Interfaces.
Lecture 15 Graphical User Interfaces (GUI’s). Objectives Provide a general set of concepts for GUI’s Layout manager GUI components GUI Design Guidelines.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 15 Creating User.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L03 (Chapter 15) Creating.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L04 (Chapter 15) Creating.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Creating User Interfaces. 2 Motivations A graphical user interface (GUI) makes a system user-friendly and easy to use. Creating a GUI requires creativity.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Scott Grissom, copyright 2006Ch 11: GUI Slide 1 Graphical User Interfaces (Ch 11) Careful design of a graphical user interface is key to a viable software.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
Graphic User Interfaces Part 1. Typical GUI Screen from Microsoft Word What GUI “components” can you see? –Menus? Buttons? Labels? What else? –Anything.
PROGRAMMING REVIEW Lab 2 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
Java Programming Chapter 10 Graphical User Interfaces.
Chapter 9: Applets Jim Burns Fall Outline Learn about applets Learn about applets Write an HTML doc to host an applet Write an HTML doc to host.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
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.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 13 Creating User.
Creating User Interfaces F JComponent F JButton F JLabel F JTextField F JTextArea F JComboBox F JList F JCheckBox F JRadioButton F Dialogs.
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.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Creating GUIs in Java Using.
Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea.
Chapter 13 Creating User Interfaces F What is JavaBeans?  Component and JComponent F JButton  ImageIcon  JLabel  JTextField  JTextArea  JComboBox.
Dale Roberts GUI Programming using Java - Introduction Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
Java Swing. Swing is a set of classes that provides more powerful and flexible components than are possible with the AWT. In addition to the familiar.
1 Outline 1 Introduction 2 Overview of Swing Components 3 JLabel 4 Event Handling 5 TextFields 6 How Event Handling Works 7 JButton 8 JCheckBox and JRadioButton.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent Jbutton Jbutton ImageIcon ImageIcon JLabel JLabel JTextField.
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
Java Programming: Advanced Topics 1 Components and Facilities for Rich Graphical User Interfaces Chapter 7.
Graphical User Interfaces (Part 2) 1. View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
Computer Science [3] Java Programming II - Laboratory Course Lab 4: Common GUI Event Types and Listener Interfaces Layout Mangers Faculty of Engineering.
Lec.10 (Chapter 8 & 9) GUI Jiang (Jen) ZHENG June 27 th, 2005.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 15 Creating User.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 – Graphical User Interfaces Java Foundations: Introduction to Programming.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
GUI Basics. Agenda What GUI How to make in java Creating frames Frequently used GUI components Layout Managers.
5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise.
Creating User Interfaces Event-Driven Programming.
Basics of GUI Programming Chapter 11 and Chapter 22.
Chapter 11 Creating User Interfaces
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Software Construction LAB 08 Java Programming with SWING GUI Builder.
Java Programming, Second Edition Chapter Thirteen Understanding Swing Components.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 15 : Swing III King Fahd University of Petroleum & Minerals College of Computer.
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.
1 Lecture 8: User Interface Components with Swing.
View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user interface element (the user interface.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
GUIs & Event-Driven Programming Chapter 11 Review.
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit 6 Graphical user interfaces 1.
Christopher Budo, Davis Nygren, spencer franks, Luke miller
Advanced User Interfaces
Chap 7. Building Java Graphical User Interfaces
Chapter 13: Advanced GUIs and Graphics
Graphical User Interfaces -- Introduction
Chapter 7 Creating User Interfaces
Chapter 13 Creating User Interfaces
Advanced GUIs and Graphics
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

Computer Science [3] Java Programming II - Laboratory Course Lab 4 -1 : Introduction to Graphical user interface GUI Components Faculty of Engineering & IT Software Engineering Department Eng.Omar Al-Nahal Eng.Omar Al-Nahal

Introduction to Graphical user interface (GUI) Review Introduction to Graphical user interface (GUI) Review Simple GUI-Based Input/Output with JOptionPane - Review

Output JOptionPane Message Dialog Constants

4 GUI Elements b The key elements of a Java graphical user interface are: GUI componentsGUI components layout managerslayout managers event processingevent processing b GUI components, such as text fields and buttons, are the screen elements that a user manipulates with the mouse and keyboard b Layout managers govern how the components appear on the screen. b Events signal important user actions.

5 Containers b A container is a special category of GUI components that group other components. b All containers are components, but not all components are containers. b An applet is a container. b Therefore,buttons, text fields, and other Component can be added to an applet to be displayed. b Each container has an associated layout manager to control the way components in it are displayed.

6 Containers b Some containers must be attached to another graphical surface: PanelPanel AppletApplet b Other containers can be moved independently: WindowWindow FrameFrame DialogDialog

7 Containers Component Container Window Panel Dialog Frame Applet

Some basic GUI components. Swing Overview Classes from package javax.swing defines various GUI components objects with which the user interacts via the mouse, the keyboard or another form of input.

Component Object Container Window Frame JFrameJComponent JPanel JLabelJMenuBar AbstractButton JButton JMenu JMenuItem JTextFieldJTextArea JTextComponent Hierarchy of Swing Classes AWT Swing Class Abstract Class Layout manager classes are in the AWT.

Swing Overview b Common superclasses of many of the Swing components  Component class Operations common to most GUI components are found in Component class.Operations common to most GUI components are found in Component class.  Container class Two important methods originates in this classTwo important methods originates in this class –add — adds components to a container. –setLayout — enables a program to specify the layout manager that helps a Container position and size its components. java.lang.Object java.awt.Container Javax.swing,JComponent java.awt.Component

JLabel A label is a display area for a short text, an image.

JLabel Constructors The constructors for labels are as follows: JLabel() JLabel(String text, int horizontalAlignment) JLabel(String text) JLabel(Icon icon) JLabel(Icon icon, int horizontalAlignment) JLabel(String text, Icon icon, int horizontalAlignment ) See Label.java

Text Areas JTextFields, JPasswordFields & Text Areas. A text field is an input area where the user can type in characters. Text fields are useful in that they enable the user to enter in variable data. A text field is an input area where the user can type in characters. Text fields are useful in that they enable the user to enter in variable data. A text area is similar, but displays multiple lines of text They are defined by the TextField and TextArea classes A text area automatically has scrollbars on its bottom.

JTextField Constructors b b JTextField(int columns) Creates an empty text field with the specified number of columns. b b JTextField(String text) Creates a text field initialized with the specified text. b b JTextField(String text, int columns) Creates a text field initialized with the specified text and the column size.

JTextField Methods getText() Returns the string from the text field. setText(String text) Puts the given string in the text field. setEditable(boolean editable) Enables or disables the text field to be edited. By default, editable is true. setColumns(int) Sets the number of columns in this text field. See Area.java See JTextField.javaSee TestJText.java See TestArea.java

Buttons JButton inherits AbstractButton and provides several constructors to create buttons. JButton Constructors The following are JButton constructors: JButton() JButton(String text) JButton(String text, Icon icon) JButton(Icon icon) See JButton.java

JCheckBox JCheckBox inherits all the properties such as text, icon, mnemonic, verticalAlignment, horizontalAlignment, horizontalTextPosition, verticalTextPosition, and selected from AbstractButton, and provides several constructors to create check boxes. See CheckBox.java

JRadioButton Radio buttons are variations of check boxes. They are often used in the group, where only one button is checked at a time. See JRadio.java

JComboBox A combo box is a simple list of items from which the user can choose. It performs basically the same function as a list, but can get only one value. JComboBox Methods To add an item to a JComboBox jcbo, use jcbo.addItem(Object item) To get an item from JComboBox jcbo, use jcbo.getItem() See ComBobox.java

Menus   Java provides several classes— JMenuBar, JMenu, JMenuItem, JCheckBoxMenuItem, and JRadioButtonMenuItem —to implement menus in a frame. b b A JFrame or JApplet can hold a menu bar to which the pull-down menus are attached. b b Menus consist of menu items that the user can select (or toggle on or off). Menu bars can be viewed as a structure to support menus.

Menu Demo The JMenuBar Class A menu bar holds menus; the menu bar can only be added to a frame. Following is the code to create and add a JMenuBar to a frame: The Menu Class You attach menus onto a JMenuBar. The following code creates two menus, Operation and Help, and adds them to the JMenuBar See Menu.java

The JMenuItem Class You add menu items on a menu. JMenuBar menubar; JMenu menu1, menu2, submenu; JMenuItem task1, task2, task3, task4, task5,task6,task7; The The Sub menus You can add submenus into menu items submenu.add(task1= new JMenuItem("Addition")); submenu.add(task2= new JMenuItem("subtraction")); submenu.add(task6= new JMenuItem("Multiplication")); submenu.add(task7= new JMenuItem("Qutation"));