Lecture # 6 Graphical User Interface(GUI). Introduction A graphical user interface (GUI) presents a user- friendly mechanism for interacting with an application.

Slides:



Advertisements
Similar presentations
Chapter 18 Building the user interface. This chapter discusses n Javas graphical user interface. n Swing: an enhancement of a library called the Abstract.
Advertisements

Introduction to Java 2 Programming
1 Chapter 8 Objects and Classes Lecture 2 Prepared by Muhanad Alkhalisy.
 The Java Foundation Classes (JFC) are a set of packages encompassing the following APIs:  Abstract Window Toolkit (AWT) : native GUI components  Swing.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
1 Chapter 7 Graphics and Event Handling. 2 Overview The java.awt and javax.swing packages and their subpackages support graphics and event handling. Many.
Graphical User Interface (GUI) A GUI allows user to interact with a program visually. GUIs are built from GUI components. A GUI component is an object.
Implementing GUIs in Java ● The Java Foundation Classes (JFC) are a set of packages encompassing the following APIs: – Abstract Window Toolkit (AWT): native.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
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.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Advanced Java Class GUI, part 2. JComponent methods addXXXListener(XXXListener) repaint() – [optional arguments: delay and coordinates of sub-area to.
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.
GUI Basics: Introduction. Creating GUI Objects // Create a button with text OK JButton jbtOK = new JButton("OK"); // Create a label with text "Enter your.
Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy
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.
Java GUI CSCE 190 – Java Instructor: Joel Gompert Mon, July 26, 2004.
Objectives of This Session
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.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
FEN IntroJava2006 AAU1 GUI: Graphical User Interface AWT/SWING: Components Drag and Drop in NetBeans Events Listeners.
1 Graphical User Interfaces AWT and Swing packages Frames and Panels Components Nested Panels Images Reading for this Lecture: L&L, 3.9 – 3.11.
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.
Timer class and inner classes. Processing timer events Timer is part of javax.swing helps manage activity over time Use it to set up a timer to generate.
1 Java Swing - Lecture 2 Components and Containment Boriana Koleva
GUI Basics. What is GUI? A graphical user interface (GUI) is a type of user interface item that allows people to interact with programs in more ways than.
Creating Windows. How can we use Java to create programs that use windows (GUI applications)? How can we use Java to create programs that use windows.
 GUI – Graphic User Interface  Up to now in the programs we have written all output has been sent to the standard output device i.e.: the DOS console.
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.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 – Graphical User Interfaces Java Foundations: Introduction to Programming.
Swing Components. Introduction Swing – A set of GUI classes – Part of the Java's standard library –Much better than the previous library: AWT Abstract.
Csc Basic Graphical User Interface (GUI) Components.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Outline Creating Objects The String Class The Random and Math Classes Formatting Output Enumerated Types Wrapper Classes Components and Containers Images.
Basics of GUI Programming Chapter 11 and Chapter 22.
GUI Components. The Swing package has numerous GUI components that can be added to a window. The Swing package has numerous GUI components that can be.
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.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Computer Science [3] Java Programming II - Laboratory Course Lab 4 -1 : Introduction to Graphical user interface GUI Components Faculty of Engineering.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
1 Lecture 8: User Interface Components with Swing.
Introduction to GUI in 1 Graphical User Interface Nouf Almunyif.
1 A Quick Java Swing Tutorial. 2 Introduction Swing – A set of GUI classes –Part of the Java's standard library –Much better than the previous library:
CPCS 391 Computer Graphics Lab One. Computer Graphics Using Java What is Computer Graphics: Computer graphics are graphics created using computers and,
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
A Quick Java Swing Tutorial
Welcome To java
Abstract Window Toolkit (AWT): native GUI components
A First Look at GUI Applications
Java Swing.
A Quick Java Swing Tutorial
Abstract Window ToolKit (AWT)
Timer class and inner classes
Introduction to Computing Using Java
AWT Components and Containers
Graphics Programming - Frames
A Quick Java Swing Tutorial
Advanced Programming in Java
Graphical User Interface
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

Lecture # 6 Graphical User Interface(GUI)

Introduction A graphical user interface (GUI) presents a user- friendly mechanism for interacting with an application. The user interface is that part of a program that interacts with the user of the program. Gives an application a distinctive “look” and “feel.” Gives user a convenient way to use a software. Gives a lot of controls to user to use the software in best possible way.

Introduction (cont.) Built from GUI components. Sometimes called controls or widgets—short for window gadgets. User interacts via the mouse, the keyboard or another form of input, such as voice recognition. IDEs Provide GUI design tools to specify a component’s exact size and location in a visual manner by using the mouse. Generates the GUI code for you. Greatly simplifies creating GUIs, but each IDE has different capabilities and generates different code.

Introduction (cont.) Example of a GUI title bar at top contains the window’s title. menu bar contains menus ( File and View ). In the top-right region of the window is a set of buttons Typically, users press buttons to perform tasks. In the GUI Components area of the window is a combo box; User can click the down arrow at the right side of the box to select from a list of items.

AWT Package The Java programming language class library provides a user interface toolkit called the Abstract Windowing Toolkit, or the AWT. The AWT is both powerful and flexible. The AWT was designed to provide a common set of tools for graphical user interface design that work on a variety of platforms.

Introduction to GUI Programming What are the stages in building a GUI application? Design the user interface Organising pre-built GUI components to build windows, dialogs E.g buttons, tables, menus, etc Writing the application logic What does the application do? Writing event-handling code to tie the GUI components to the application logic More on event-handling.

Components and containers A graphical user interface is built of graphical elements called components Typical components include such items as buttons, scrollbars, and text fields, etc. In the AWT, all user interface components are instances of class Component or one of its subtypes. Components do not stand alone, but rather are found within containers. Containers contain and control the layout of components. Containers are themselves components, and can thus be placed inside other containers.

Component Tree

Example

Example: A Simple Framed Window import java.awt.*; import javax.swing.*; public class SwingTest { public static void main(String[] args) { JFrame frame = new JFrame("Test Frame"); frame.setSize(new Dimension(300,200)); frame.setLocation(100,100); frame.setVisible(true); }

Some AWT Component Methods void setSize(int width,int height) this property defines what would be the width and height of a component void setLocation(int x, int y) This property sets the location of a control on the screen. void setEnabled(boolean b) Either we give true or false if true then it would be enabled otherwise it would be disabled. void setVisible(boolean b) it Set the visiblity of a control, if true is value the it is visible otherwise nonvisible

Cont.. void setBackground(Color c) It Sets the background colour of a component void setForeground(Color c) It sets the foreground colour of a component, means what color of text would appear on it

Adding Color Color.black Color.blue Color.cyan Color.darkGray Color.gray Color.green Color.lightGray Color.magenta Color.orange Color.pink Color.red Color.white Color.yellow The java.awt.Color class has the following static fields (data members):

Simple GUI-Based Input/Output with JOptionPane Most applications use windows or dialog boxes (also called dialogs) to interact with the user. JOptionPane (package javax.swing ) provides prebuilt dialog boxes for input and output Displayed via static JOptionPane methods. JOptionPane.ShowInputDialogue (container,”message”)

Changing the title through user input public class Main { public static void main(String[] args) { JFrame frame = new JFrame("Test Frame"); frame.setSize(new Dimension(300,200)); frame.setLocation(100,100); frame.setVisible(true); String str= JOptionPane.showInputDialog(frame,"Enter ur Value"); frame.setTitle(str); }

Output Dialogue box Normally the messages that are displayed by the System are said to message boxes or dialogue boxes. Syntax JOptionPane.ShowMessageDialogue(String);

Program to Print a string in message box public class Main { public static void main(String[] args) { JFrame frame = new JFrame("Test Frame"); frame.setSize(new Dimension(300,200)); frame.setLocation(100,100); frame.setVisible(true); String str=“This is my Message”; JOptionPane.ShowMessageDialogue(frame,str); }

Container: Container is an AWT component. It is the second level Container. The AWT component like Button, TextField, ListBox etc are added into the Container Object. Syntax: Container Cont= new Container(); Cont.add(button); Cont.add(text); Cont.add(list);

Button: The widows form button control Allow the user to click it to perform an action. When a button is click it look like it is being pushed. Syntax JButton btn=new JButton(“Click Me”); btn.setSize(30,30); btn.setLocation(40,40);

Labels Labels are the Static text that are used to display for the information of the user. Syntax JLabel lbl=new Jlabel(“User Name”); Lbl.setSize(50,50); lbl.setLocation(50,40);