CS111: PROGRAMMING LANGUAGE II

Similar documents
12/22/11. Copyright by Pearson Education, Inc. All Rights Reserved.

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

Summary. Section 14.1 Introduction. Section 14.2 Java s New Nimbus Look-and-Feel. 618 Chapter 14 GUI Components: Part 1

EVENTS, EVENT SOURCES AND LISTENERS

Dr. Hikmat A. M. AbdelJaber

CompSci 125 Lecture 17. GUI: Graphics, Check Boxes, Radio Buttons

Chapter 17 Creating User Interfaces

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Swing. By Iqtidar Ali

Graphical User Interfaces. Comp 152

Outline CSE 3461 F10. What is a Widget? Properties of Widgets. A self-contained screen object Also called a control Examples of widgets:

Chapter 6: Graphical User Interfaces

2110: GUIS: Graphical User Interfaces

Starting Out with Java: From Control Structures Through Objects Sixth Edition

JList. Displays a series of items The user can select one or more items Class JList extends directly class Jcomponent Class Jlist supports

Contents Chapter 1 Introduction to Programming and the Java Language

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI

Swing/GUI Cheat Sheet

14.2 Java s New Nimbus Look-and-Feel 551 Sample GUI: The SwingSet3 Demo Application As an example of a GUI, consider Fig. 14.1, which shows the SwingS

SD Module-1 Advanced JAVA

SD Module-1 Advanced JAVA. Assignment No. 4

Goals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords

Swing Programming Example Number 2

Introduction p. 1 JFC Architecture p. 5 Introduction to JFC p. 7 The JFC 1.2 Extension p. 8 Swing p. 9 Drag and Drop p. 16 Accessibility p.

To gain experience using GUI components and listeners.

Swing. Component overview. Java UI, summer semester 2017/2018 1

Chapter 12 Advanced GUIs and Graphics

GUI Components: Part 1

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

CS 209 Spring, 2006 Lab 8: GUI Development Instructor: J.G. Neal

Graphical User Interfaces. Swing. Jose Jesus García Rueda

Java IDE Programming-I

Advanced Swing GUI Applications

Graphical Applications

Human-Computer Interaction IS4300

Sri Vidya College of Engineering & Technology

Index SELF-STUDY. Symbols

Programming graphics

GUI Event Handlers (Part II)

GUI Software Architecture

Tool Kits, Swing. Overview. SMD158 Interactive Systems Spring Tool Kits in the Abstract. An overview of Swing/AWT

Chapter 4. Swing 18 marks

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

CS410G: GUI Programming. The Model/View/Controller Pattern. Model. Controller. View. MVC is a popular architecture for building GUIs

Advanced Java Programming. Swing. Introduction to Swing. Swing libraries. Eran Werner, Tel-Aviv University Summer, 2005

Widgets. Overview. Widget. Widgets Widget toolkits Lightweight vs. heavyweight widgets Swing Widget Demo

CoSc Lab # 6 (The Model) Due Date: Part I, Experiment classtime, Tuesday, Nov 6 th, 2018.

UNIT-V 1 KNREDDY JAVA PROGRAMMING

Chapter 7: A First Look at GUI Applications

Chapter 12 GUI Basics

Graphical User Interface (GUI)

Java Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1

Course Status Networking GUI Wrap-up. CS Java. Introduction to Java. Andy Mroczkowski

Java 11 Swing with Eclipse Index

Adding Buttons to StyleOptions.java

Packages: Putting Classes Together

Unit 6: Graphical User Interface

Contents Introduction 1

11/27/2007 TOPICS CHAPTER TOPICS LISTS READ ONLY TEXT FIELDS. Advanced GUI Applications. This module discusses the following main topics:

JRadioButton account_type_radio_button2 = new JRadioButton("Current"); ButtonGroup account_type_button_group = new ButtonGroup();

8/23/2014. Chapter Topics. Chapter Topics. Lists. Read Only Text Fields. Chapter 13: Advanced GUI Applications

10/16/2008. CSG 170 Round 5. Prof. Timothy Bickmore. User Analysis Task Analysis (6) Problem Scenarios (3)

Java 11 Swing Index. Section Title Page

China Jiliang University Java. Programming in Java. Java Swing Programming. Java Web Applications, Helmut Dispert

Event Driven Programming

Object-Oriented Programming Design. Topic : User Interface Components with Swing GUI Part III

BASICS OF GRAPHICAL APPS

Swing from A to Z Some Simple Components. Preface

GUI Event Handlers (Part I)

CS 106A, Lecture 23 Interactors and GCanvas

Introduction to the JAVA UI classes Advanced HCI IAT351

Systems Programming Graphical User Interfaces

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

Outline. Widgets. Categories of Widgets. What is a Widget?

Welcome to CIS 068! 1. GUIs: JAVA Swing 2. (Streams and Files we ll not cover this in this semester, just a review) CIS 068

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

BASICS OF OBJECT ORIENTED PROGRAMMING

MODEL UPDATES MANIPULATES USER

Widgets. Widgets Widget Toolkits. 2.3 Widgets 1

Agenda. Container and Component

Java 1.9 Swing Index

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

Java Programming Lecture 6

Introduction to Graphical Interface Programming in Java. Introduction to AWT and Swing

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1

Human-Computer Interaction IS4300

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)

user-friendly and easy to use.

CoSc Lab # 5 (The Controller)

Java 1.8 Swing with Eclipse Oxygen Index

Java 1.8 Swing with Eclipse Mars Index

Java 1.8 Swing with Eclipse Neon Index

CLASS XII SUBJECT: - INFORMATICS PRACTICES (065) I.P. (Theory)

Summary Chapter 25 GUI Components: Part 2

Chapter 13 GUI Basics. Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved.

What Is an Event? Some event handler. ActionEvent. actionperformed(actionevent e) { }

GUI Basics. Object Orientated Programming in Java. Benjamin Kenwright

JAVA NOTES GRAPHICAL USER INTERFACES

CSE Lab 8 Assignment Note: This is the last lab for CSE 1341

Transcription:

CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 10(b): Working with Controls

Agenda 2 Case study: TextFields and Labels Combo Boxes buttons List manipulation Radio buttons and checkboxes And more

3 Swing s GUI classes Class JComponent (package javax.swing) is a subclass of Container. JComponent is the superclass of all lightweight Swing components, all of which are also Containers.

4 GUI Controls

JComponent 5 Some common lightweight component features supported by JComponent include: pluggable look-and-feel Shortcut keys (called mnemonics) Common event-handling capabilities for components that initiate the same actions in an application. tool tips: Method settooltiptext specifies the tool tip that is displayed when the user positions the mouse cursor over a JComponent. Support for accessibility Support for user-interface localization

6 Tips!!

7 Example Different GUI controls to fit different purposes!!

JLabel 8 In a large GUI Difficult to identify the purpose of every component. Provide text stating each component s purpose. Such text is known as a label and is created with class JLabel a subclass of JComponent. Displays read-only text, an image, or both text and an image.

JTextField 9 JTextField extends class JTextComponent (package javax.swing.text), which provides many features common to Swing s text-based components. Class JPasswordField extends JTextField and adds methods that are specific to processing passwords. JPasswordField shows that characters are being typed as the user enters them, but hides the actual characters with an echo character. When the user types data into a JTextField or a JPasswordField, then presses Enter, an event occurs. You can type only in the text field that is in focus. A component receives the focus when the user clicks the component.

JComboBox 10 A combo box (or drop-down list) enables the user to select one item from a list. It can have two very different forms: The default form is the uneditable combo box, which features a button and a drop-down list of values. The editable combo box, features a text field with a small button abutting it.

JComboBox 11 The first item added to a JComboBox appears as the currently selected item when the JComboBox is displayed. Other items are selected by clicking the JComboBox, then selecting an item from the list that appears. JComboBox method setmaximumrowcount sets the maximum number of elements that are displayed when the user clicks the JComboBox. If there are additional items, the JComboBox provides a scrollbar that allows the user to scroll through all the elements in the list.

Handling Events on a Combo Box 12

Code 13 method getselectedindex returns the index of the selected item method getselecteditem returns the item selected from the list

JList 14 A list displays a series of items from which the user may select one or more items. Lists are created with class JList, which directly extends class Jcomponent. setvisiblerowcount specifies the number of items visible in the list. Unlike a JComboBox, a JList does not provide a scrollbar if there are more items in the list than the number of visible rows. A JScrollPane object is used to provide the scrolling capability. setselectionmode specifies the list s selection mode. Supports single-selection lists (only one item to be selected at a time) and multiple-selection lists (any number of items to be selected).

15 selection-mode constants Class ListSelectionModel (of package javax.swing)

JList 16 JLists generate ListSelectionEvents in single-selection lists. addlistselectionlistener registers a ListSelectionListener (package javax.swing.event) as the listener for ajlist s selection events. List method getselectedindex returns the selected item s index.

Code handling lists 17 Use DefaultListModel to manage list data at run time

List model property 18

Code -- Add 19

Code -- remove 20

JButton 21 A button is a component the user clicks to trigger a specific action. Several types of buttons command buttons checkboxes toggle buttons radio buttons Button types are subclasses of AbstractButton (package javax.swing), which declares the common features of Swing buttons. A JButton can display an Icon. A JButton can also have a rollover Icon displayed when the user positions the mouse over the JButton. The icon on the JButton changes as the mouse moves in and out of the JButton s area on the screen.

22 Types of buttons A command button generates an ActionEvent when the user clicks it. Command buttons are created with class JButton. The text on the face of a JButton is called a button label.

JRadioButton 23 Radio buttons (declared with class JRadioButton) have two states selected and not selected (also called deselected). Radio buttons normally appear as a group: only one button can be selected at a time. Selecting a different radio button forces all others to be deselected. Used to represent mutually exclusive options. The logical relationship between radio buttons is maintained by a ButtonGroup object (package javax.swing), which organizes a group of buttons and is not itself displayed in a user interface.

JRadioButton 24 ButtonGroup method add associates a JRadioButton with the group. If more than one selected JRadioButton object is added to the group, the selected one that was added first will be selected when the GUI is displayed. JRadioButtons, like JCheckBoxes, generate ItemEvents when they are clicked.

Ver-1 25

Code : ver-1 26

Ver-2 27

Code-ver2 28 Ver3??

JCheckBox 29 String passed to the JCheckBox constructor is the checkbox label that appears to the right of the JCheckBox by default. When the user clicks a JCheckBox, an ItemEvent occurs. Handled by an ItemListener object, which must implement method itemstatechanged. An ItemListener is registered with method additemlistener. JCheckBox method isselected returns true if a JCheckBox is selected.

Extra!! 30 Modify the given application by adding a checkbox that appears only when a Staff type is elected from the combobox. In this case, the user need to specify whether this employee is working a full time or not.

31 More More examples can be found in http://docs.oracle.com/javase/tutorial/uiswing/comp onents/componentlist.html

32 That s all for Today,,, working on Chapter 14