CiS 260: App Dev I Chapter 6: GUI and OOD.

Slides:



Advertisements
Similar presentations
Basic Java – Interface design. Understand: How to use TextPad for Java How to define classes and objects How to create a GUI interface How event-driven.
Advertisements

Drawing in a frame – Java GUI
Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 20, 2005.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Java GUI Libraries Swing Programming. Swing Components Swing is a collection of libraries that contains primitive widgets or controls used for designing.
© L.Lúcio, An example GUI in Java n Two graphic libraries in Java u AWT u Swing n Swing is more recent than AWT: u Built on top of AWT classes;
Graphical User Interface (GUI) and Object-Oriented Design (OOD)
COMP 14 Introduction to Programming Miguel A. Otaduy June 7, 2004.
Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
1 Class 8. 2 Chapter Objectives Use Swing components to build the GUI for a Swing program Implement an ActionListener to handle events Add interface components.
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
Lesson 35: Review of the Java GUI. The JFrame, Container and JButton.
Java Programming Chapter 10 Graphical User Interfaces.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
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.
MIT AITI 2003 Lecture 17. Swing - Part II. The Java Event Model Up until now, we have focused on GUI's to present information (with one exception) Up.
GUI programming Graphical user interface-based programming.
GUI Components and Design Here we add one more component to our programs, JButtons –JButtons can only be inserted into JPanels (or JApplets) –Clicking.
Java Event Handling CSIS 3701: Advanced Object Oriented Programming.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Copyright © 2002, Systems and Computer Engineering, Carleton University c-Gui3.ppt * Object-Oriented Software Development Part 18-c Building.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
A simple swing example GETTING STARTED WITH WIND CHILL.
1 GUI programming Graphical user interface-based programming Chapter G1 (pages )
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
Chapter 11 - A GUI Interacting With a Problem Domain Class1 Chapter 11 A GUI Interacting With a Problem Domain Class 11.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 4 – Completing the Inventory Application.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 5.1 Test-Driving the Enhanced Inventory Application.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 17.1 Test-Driving the Student Grades Application.
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.
Lesson 28: More on the GUI button, frame and actions.
Graphical User Interface (GUI)
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
MIT AITI 2004 Swing Event Model Lecture 17. The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
GUIs & Event-Driven Programming Chapter 11 Review.
Import javax.swing.JOptionPane; public class Rectangle { public static void main(String[] args) { double width, length, area, perimeter; String lengthStr,
Java Visual Applications CSIS 3701: Advanced Object Oriented Programming.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
Design Applet based java program to find the area and perimeter of a rectangle given its length and width. Java GUI.
CSC 205 Programming II Lecture 5 AWT - I.
Java Applet What is a Java Applet? How is applet compiled?
Chapter 14 – Exception Handling
Swing JComponents.
A First Look at GUI Applications
“Form Ever Follows Function” Louis Henri Sullivan
Graphical User Interface (pronounced "gooey")
Java Programming: From Problem Analysis to Program Design,
Ellen Walker Hiram College
Graphical User Interface (GUI)
Event-driven programming for GUI
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Graphical user interface-based programming
The calculator – Java GUI
Advanced Programming in Java
Constructors, GUI’s(Using Swing) and ActionListner
Graphical User Interface
Presentation transcript:

CiS 260: App Dev I Chapter 6: GUI and OOD

GUI Components GUI stands for __________ user interface. A single user interface is much better than individual input and output windows. Here are some of the GUI components: JFrame: window that holds other components JTextField: area for either input or output JLabel: text that indicates what the user should do JButton: component that causes an action Components are place in the content _____ of the window. Clicking a button is an _________.

Classes and Objects GUI components are instances (________) of classes. A class is a category of things that have common attributes and behaviors. In Java, the attributes and behaviors are called data members (fields) and _________. A window object from the JFrame class has data members like _______, height, and width, and methods like _________. In Java, a class is used to define the fields and methods of a type of object provide a method to create these objects

Inheritance and Constructors ___________ is the ability of one class to inherit the fields and methods of another class. The keyword ________ is how you implement inheritance in Java. public class RectangleProgram extends JFrame The class that inherits is called the _________ and the class which provides the fields and methods is called the _________. A ___________ is a method in a class that creates an object. The name of a constructor is the same as the name of the _______.

Creating a Simple Window //Java program to create a simple window. import javax.swing.*; public class RectangleProgramOne extends JFrame { private static final int WIDTH = 400; private static final int HEIGHT = 300; public RectangleProgramOne() setTitle("Area and Perimeter of a Rectangle"); setSize(WIDTH,HEIGHT); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); } public static void main( String[] args) RectangleProgramOne rectProg = new RectangleProgramOne();

The Content Pane A content pane is the inner area of a window. To get access to the content pane, you need to first create a __________ object: Container pane = getContentPane(); The class Container is in the package _________. To create a layout (5 rows, 2 columns) for the object pane Pane.setLayout(new GridLayout(5,2)); You must set the layout before adding ___________.

JLabel The following statement declares four JLabel objects private JLabel lengthL, widthL, areaL, perimeterL; The following statement creates a JLabel object lengthL = new JLabel("Enter the length: ", SwingConstants.RIGHT); The following statement adds a label object to the content pane pane.add(lengthL);

Creating a Window With Labels I //Java program to create a window and place four labels. import javax.swing.*; import java.awt.*; public class RectangleProgramTwo extends JFrame { private static final int WIDTH = 400; private static final int HEIGHT = 300; private JLabel lengthL, widthL, areaL, perimeterL; public RectangleProgramTwo() setTitle("Area and Perimeter of a Rectangle"); lengthL = new JLabel("Enter the length: ",SwingConstants.RIGHT); widthL = new JLabel("Enter the width: ",SwingConstants.RIGHT); areaL = new JLabel("Area: ",SwingConstants.RIGHT); perimeterL = new JLabel("Perimeter: ",SwingConstants.RIGHT);

Creating a Window With Labels II Container pane = getContentPane(); pane.setLayout(new GridLayout(4,1)); pane.add(lengthL); pane.add(widthL); pane.add(areaL); pane.add(perimeterL); setSize(WIDTH, HEIGHT); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } public static void main(String[] args) { RectangleProgramTwo rectProg = new RectangleProgramTwo();

JTextField The following statement declares four JTextField objects private JTextField lengthTF, widthTF, areaTF, perimeterTF; The following statement creates a JTextField object lengthTF = new JTextField(10); The following statement adds a label object to the content pane pane.add(lengthTF);

Window With Labels and Text Fields

JButton The following statements create two ________ objects JButton calculateB, exitB; calculateB = new JButton("Calculate"); exitB = new JButton("Exit"); The following statements add the button objects to the ________ pane pane.add(calculateB); pane.add(exitB); The GridLayout now needs 5 rows, 2 columns pane.setLayout(new GridLayout(5,2)); Placement of components in the grid is from left to right, then top to bottom.

Window w/ Labels, Text Fields, Buttons

Handling Events When a button is clicked, an ActionEvent object is created, which calls the actionPerformed() method of an ActionListener object. The class ActionListener is called an __________, a class that contains only method declarations, such as actionPerformed(). For each JButton, you must _________ a particular ActionListener object by creating a class to handle the action event. You must then define the actionPerformed() method within the handler class that you created.

Steps To Deploy Button Handlers I Within the application class, declare an action handler object for a button CalculateButtonHandler calculateHandler; After creating the JButton object, create the action handler object calculateHandler = new CalculateButtonHandler(); Then register (associate) the button handler object with the button calculateB.addActionListener(calculateHandler);

Steps To Deploy Button Handlers II Create the class that handles the action event private class CalculateButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { double width, length, area, perimeter; length = Double.parseDouble(lengthTF.getText()); width = Double.parseDouble(widthTF.getText()); area = length * width; perimeter = 2 * (length + width); areaTF.setText("" + area); perimeterTF.setText("" + perimeter); }

Completed Application (pp. 287-289)

More About OO Design (OOD) Objects are things that have attributes and __________ are instances of a particular class A _______ is the definition of the attributes and behaviors of things that belong to it. A class variable is the software implementation of a class attribute. A class method is a method that changes the value of a class variable the software implementation of a class behavior _____________ is the act of combining variables and methods in a software class.

A Simplified OOD Methodology Write a detailed description of the problem Calculate the area and perimeter of a rectangle Identify all relevant nouns and _______. Rectangle, area, perimeter From the nouns, select _________. Rectangle Identify the significant attributes of the objects. Length, width From the verbs, select the __________. Calculate area, calculate perimeter