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

Similar documents
Graphic User Interfaces. - GUI concepts - Swing - AWT

CS111: PROGRAMMING LANGUAGE II

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

PIC 20A GUI with swing

CS 315 Software Design Homework 1 First Sip of Java Due: Sept. 10, 11:30 PM

CHAPTER 2. Java Overview

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

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

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

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

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

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

Programming graphics

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

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Graphical User Interfaces. Comp 152

Java Programming Lecture 6

EVENTS, EVENT SOURCES AND LISTENERS

CompSci 230 S Programming Techniques. Basic GUI Components

Adding Buttons to StyleOptions.java

Java Applets This is not a Java course! (You re supposed to know about Java.)

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

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

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


GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

Chapter 17 Creating User Interfaces

Contents Chapter 1 Introduction to Programming and the Java Language

Graphical User Interface (GUI)

CS 251 Intermediate Programming GUIs: Components and Layout

G51PRG: Introduction to Programming Second semester Applets and graphics

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

To gain experience using GUI components and listeners.

Parts of a Contract. Contract Example. Interface as a Contract. Wednesday, January 30, 13. Postcondition. Preconditions.

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

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

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

Graphics in Swing. Engineering 5895 Faculty of Engineering & Applied Science Memorial University of Newfoundland

Chapter 12 Advanced GUIs and Graphics

Swing/GUI Cheat Sheet

More about GUIs GEEN163

News and info. Array. Feedback. Lab 4 is due this week. It should be easy to change the size of the game grid.

Graphical Applications

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

Content Area: Mathematics Course: Computer Programming Grade Level: R14 The Seven Cs of Learning

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

Programming Languages and Techniques (CIS120)

Object-Oriented Programming Design. Topic : Graphics Programming GUI Part I

Chapter 7: A First Look at GUI Applications

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

COMP-202 Unit 10: Basics of GUI Programming (Non examinable) (Caveat: Dan is not an expert in GUI programming, so don't take this for gospel :) )

Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science

Systems Programming Graphical User Interfaces

GUI Software Architecture

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

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

11/7/12. Discussion of Roulette Assignment. Objectives. Compiler s Names of Classes. GUI Review. Window Events

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

User interfaces and Swing

TWO-DIMENSIONAL FIGURES

Agenda. Container and Component

First Name: AITI 2004: Exam 2 July 19, 2004

Assignment 2. Application Development

COSC 123 Computer Creativity. Graphics and Events. Dr. Ramon Lawrence University of British Columbia Okanagan

GUI Event Handlers (Part I)

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

Class 16: The Swing Event Model

Example: Building a Java GUI

Widgets. Widgets Widget Toolkits. User Interface Widget

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

Example: Building a Java GUI

Human-Computer Interaction IS4300

Introduction. Introduction

Window Interfaces Using Swing Objects

First Name: AITI 2004: Exam 2 July 19, 2004

Computer Science 210: Data Structures. Intro to Java Graphics

Dr. Hikmat A. M. AbdelJaber

Swing Programming Example Number 2

CSCI 053. Week 5 Java is like Alice not based on Joel Adams you may want to take notes. Rhys Price Jones. Introduction to Software Development

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

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

Java Event Handling -- 1

Block I Unit 2. Basic Constructs in Java. AOU Beirut Computer Science M301 Block I, unit 2 1

Hanley s Survival Guide for Visual Applications with NetBeans 2.0 Last Updated: 5/20/2015 TABLE OF CONTENTS

Programming Languages and Techniques (CIS120)

Widgets. Widgets Widget Toolkits. 2.3 Widgets 1

Swing from A to Z Some Simple Components. Preface

Window Interfaces Using Swing Objects

Unit 7: Event driven programming

CS 106A, Lecture 23 Interactors and GCanvas

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

AP CS Unit 11: Graphics and Events

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

Here is a list of a few of the components located in the AWT and Swing packages:

17 GUI API: Container 18 Hello world with a GUI 19 GUI API: JLabel 20 GUI API: Container: add() 21 Hello world with a GUI 22 GUI API: JFrame: setdefau

CSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction

Graphical User Interface (GUI)

Basics of programming 3. Java GUI and SWING

Transcription:

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

Announcements

GUI Review

Review: Inheritance Subclass is a Parent class Includes parent s features May Extend May Modify extends! Parent Class Subclass

JFrame Container Title Bar includes the title text, and the minimize, maximize and close buttons Content pane Re-position the frame Re-size the frame http://docs.oracle.com/javase/6/docs/api/javax/swing/jframe.html

Content Pane Is not a class! Is the area of the JFrame where we can add/draw stuff JFrame constructs it as a JComponent but getcontentpane returns a reference to a Container We can add other graphical components to it Has a LayoutManager getcontentpane from the JFrame setcontentpane in the JFrame add a component to the content pane

JPanel Is a Container to which you may add other Components May have a LayoutManager Can be configured as double-buffered You may add a JPanel to the content pane Use setcontentpane to replace the content pane with a JPanel Implements a paintcomponent(graphics g) method You may subclass a JPanel and override paintcomponent Then you can draw on the Graphics context

JLabel Displays text string, an icon or both Write only --- no user input possible http://docs.oracle.com/javase/6/docs/api/javax/swing/jlabel.html

JButton Displays a button Our class implements the ActionListener interface Java calls ActionListener s actionperformed method when user clicks button http://docs.oracle.com/javase/6/docs/api/javax/swing/jbutton.html

ActionListener Interface Our class includes implements ActionListener clause Java ensures we implement the actionperformed method Java passes an ActionEvent parameter to actionperformed ActionEvent s getsource method returns a reference to the object (e.g. an instance of a JButton or JTextField) in which the event occurred

JTextField Displays text (like a JLabel) Unlike a JLabel, user can enter text Our class implements ActionListener Java calls actionperformed when user modifies text ActionEvent s getsource method identifies source of event JTextField s gettext returns reference to user s text String Many, many methods! http://docs.oracle.com/javase/6/docs/api/javax/swing/jtextfield.html

The Graphics Context

Graphics Context 2-D canvas --- we can draw graphical shapes on it Integer coordinate system in pixels Java passes reference to a Graphics to paintcomponent http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/graphics.html

The Graphics State Includes Current clip rectangle Current color Current font

Graphics Operations Include drawarc drawimage drawline drawoval drawrect drawstring fillarc filloval fillrect

Graphics Etc clearrect getcliprect setcolor setfont more

CheckBoxes

JCheckBox Labeled stateful check box Text label describes an attribute Check box displays associated state (selected or not) Clicking box toggles its associated state Useful methods JCheckBox( Label Text String ) isselected() Our class implements either ActionListener or ItemListener interface

ItemListener Interface public void itemstatechanged(itemevent event) Called when check box s state changes: User interaction (clicking) Programmatically (unlike ActionListener) ItemEvent methods include: getitemselectable: Returns reference to source of event getstatechange: Returns reason for the event

Radio Buttons

Radio Buttons JRadioButton --- only one can be selected at any time ButtonGroup --- manages group of related JRadioButtons ActionListener

JRadioButton Labeled stateful button Text label describes an attribute Button displays associated state (selected or not) Clicking button toggles its associated state Only one button in group selected at any time Useful methods JRadioButton( Selected Button s Text String,true) JRadioButton( Unselected Button Text ) isselected() Define a ButtonGroup and add each JRadioButton to it Our class typically implements ActionListener interface

ButtonGroup Use add method to add a JRadioButton to a ButtonGroup Ensures only one JRadioButton will be selected at a time