Programming Languages and Techniques (CIS120)

Similar documents
Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120e)

Programming Languages and Techniques (CIS120)

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

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!

Programming Languages and Techniques (CIS120)

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120)

G51PRG: Introduction to Programming Second semester Applets and graphics

Programming Languages and Techniques (CIS120)

IT101. Graphical User Interface

Programming Languages and Techniques (CIS120)

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

Programming Languages and Techniques (CIS120)

UI Software Organization

Programming Languages and Techniques (CIS120)

Lecture 5: Java Graphics

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

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

+! Today. Lecture 3: ArrayList & Standard Java Graphics 1/26/14! n Reading. n Objectives. n Reminders. n Standard Java Graphics (on course webpage)

CS 251 Intermediate Programming GUIs: Components and Layout

Programming Languages and Techniques (CIS120)

Graphic User Interfaces. - GUI concepts - Swing - AWT

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

Programming Languages and Techniques (CIS120)

Agenda. Programming Seminar. By: dr. Amal Khalifa. Coordinate systems Colors Fonts Drawing shapes Graphics2D API

Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms.

Lecture 3: Java Graphics & Events

Graphical User Interface (GUI)

H212 Introduction to Software Systems Honors

Java Programming. Computer Science 112

Java & Graphical User Interface II. Wang Yang wyang AT njnet.edu.cn

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

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

Programming Languages and Techniques (CIS120)

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

Widgets. Widgets Widget Toolkits. User Interface Widget

Human-Computer Interaction IS4300

CSE 331 Software Design & Implementation

BASICS OF GRAPHICAL APPS

CS Fall Homework 5 p. 1. CS Homework 5

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

KF5008 Program Design & Development. Lecture 1 Usability GUI Design and Implementation

CIS 120 Final Exam May 7, Name (printed): Pennkey (login id):

Computer Science 210: Data Structures. Intro to Java Graphics

Introduction to the JAVA UI classes Advanced HCI IAT351

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

Systems Programming Graphical User Interfaces

Programming graphics

Announcements. Introduction. Lecture 18 Java Graphics and GUIs. Announcements. CSE 331 Software Design and Implementation

CSE 331 Software Design and Implementation. Lecture 19 GUI Events

Graphical User Interfaces 2

Introduction to GUIs. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2014

Lab & Assignment 1. Lecture 3: ArrayList & Standard Java Graphics. Random Number Generator. Read Lab & Assignment Before Lab Wednesday!

GUI Basics. Object Orientated Programming in Java. Benjamin Kenwright

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

Programmierpraktikum

Object-oriented programming in Java (2)

HW#1: Pencil Me In Status!? How was Homework #1? Reminder: Handouts. Homework #2: Java Draw Demo. 3 Handout for today! Lecture-Homework mapping.

Java Programming Lecture 6

Packages: Putting Classes Together

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline

Java. GUI building with the AWT

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.

2110: GUIS: Graphical User Interfaces

Graphical User Interface (GUI)

Jonathan Aldrich Charlie Garrod

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

Sri Vidya College of Engineering & Technology

Graphics and Painting

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

2IS45 Programming

CSE 331. Event- driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

CSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

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

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

Programming Languages and Techniques (CIS120e)

Widgets. Widgets Widget Toolkits. 2.3 Widgets 1

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

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

Graphic Interface Programming II Using Swing and OOP more advanced issues. Uppsala universitet

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

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

User interfaces and Swing

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

CS506 Web Programming and Development Solved Subjective Questions With Reference For Final Term Lecture No 1

PIC 20A GUI with swing

Class 16: The Swing Event Model

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

CS11 Java. Fall Lecture 4

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 :) )

Come & Join Us at VUSTUDENTS.net

TYPES OF INTERACTORS Prasun Dewan Department of Computer Science University of North Carolina at Chapel Hill

Advanced Effects in Java Desktop Applications

Transcription:

Programming Languages and Techniques (CIS120) Lecture 33 April 16, 2014 Swing I: Drawing and Event Handling

Set<String> set = new TreeSet<String> (); Map<String,Set<String>> map = new TreeMap<String,Set<String>> (); set.add("1"); set.add("2"); map.put("a", set); set.clear(); // remove all elements set.add("3"); map.put("b",set); System.out.println(map); What result is printed? 1. { a=[1,2], b=[3] } 2. { a=[3], b=[3] } 3. { a=[1,2], b=[1,2] } 4. NullPointerExcepTon

HW 08 Feedback Good I liked this homework. I actually liked working on this assignment a lot, I'm definitely looking forward to more GUI- related assignments, makes the stuff we work on seem so much cooler than simply computng values. SaTsfying end result. Not nearly as difficult as paint in OCaml. Not so good HELL WEEK. SLEEP DEPRIVATION. I DONT CARE ANYMORE. JSHDLKSFGKGFDHDFG :( Brief Fun Wow Cool! ha Insighjul Found a bug when I was showing off to my friends that I finally finished, good thing I had one submission lek. Actually took the Tme to understand Gctx and NoTfiers this Tme around instead of blindly testng things when we did GUI in OCaml... much easier and faster when you understand why you are doing the things you are doing!???? Who needs a TI- 83 when you have Calculator.java?! please show this comment in class

HW 10: Game project CIS 120

Announcements HW10 is now available. Due Wednesday, April 30th, at 11:59PM. Suggested steps: Get started early! Download, run, and read the code we ve provided Play around with adding a few small features Read over our suggestons and think about what game you d like to try to code Discuss with your TAs Do it

Do you have an idea for a game already? 1. no, not yet 2. I have a few ideas 3. I know what I want to do 4. I started coding back in January

GUIs, take 3

OCaml GUI review Graphics Context Provides drawing operatons Translates coordinates so that they are relatve to each widget Keeps track of state necessary for drawing (pen color, line thickness) Widgets Abstract type for "things" on the screen Something that can paint itself, handle events and calculate its size type widget = { repaint : gctx -> unit,! size : gctx -> int,! handle : event -> unit }! basic widgets: busons, canvas, scrollbars, labels, checkboxes, radiobusons container widgets: border, hpair, vpair, hlist, vlist, grid Event Listeners FuncTons that execute when events happen Update the state of the applicaton Widgets reflect changes when they are redrawn

Terminology overview HW06 (OCaml) HW08 (Java) Swing Graphics Context Gctx.gctx Gctx Graphics Widget type Widget.widget Widget JComponent Basic Widgets buson label checkbox Buson Label JBuson JLabel JCheckBox Container Widgets hpair, vpair HPair, VPair JPanel, Layouts Events event Event AcTonEvent MouseEvent KeyEvent Event Listener mouse_listener mouseclick_listener (any functon of type event - > unit) EventListener AcTonListener MouseListener KeyListener

Simple Drawing DrawingCanvas.java DrawingCanvasMain.java

How do we draw a picture? In HW06/08, create a widget where the repaint functon uses the graphics context to draw an image let w_draw =! {! repaint = (fun (gc:gctx.t) ->! Gctx.draw_line gc (0, 0) (100, 100);! Gctx.draw_point gc (3,4)) ;! size = (fun (gc:gctx.t) -> (200,200));! }! handle = (fun () -> ())! In Swing, extend from class JComponent.

Fundamental class: JComponent Analogue to Widget.widget and Widget class (Terminology: widget == component) Subclasses override methods paintcomponent (like repaint, displays the component) getpreferredsize (like minsize, calculates the size of the component) Events handled by subclasses Much more functonality available minimum/maximum size font foreground/background color borders what is visible many more

Simple Drawing Component public class DrawingCanvas extends JComponent {! public void paintcomponent(graphics gc) {! super.paintcomponent(gc);! // set the pen color to green! gc.setcolor(color.green);! }! // draw a fractal tree! fractal (gc, 75, 100, 270, 15);! // get the size of the drawing panel! public Dimension getpreferredsize() {! return new Dimension(150,150);! }! How to display this component?

JFrame Represents a top- level window Displayed directly by OS (looks different on Mac, PC, etc.) Contains JComponents Can be moved, resized, iconified, closed public void run() {!!JFrame frame = new JFrame("Tree");!!// set the content of the window to be the drawing!!frame.getcontentpane().add(new DrawingCanvas());!!// make sure the application exits when the frame closes!!frame.setdefaultcloseoperation(jframe.exit_on_close);!!// resize the frame based on the size of the panel!!frame.pack();! }!!// show the frame!!frame.setvisible(true);!

Fractal Drawing Demo

User InteracTon

Start Simple: Lightswitch Revisited Task: Program an applicaton that displays a buson. When the buson is pressed, it toggles a lightbulb on and off.

Swing practcalites Java library for GUI development javax.swing.* Built on existng library: AWT java.awt.* If there are two versions of something, use Swing s. (e.g., java.awt.buson vs. javax.swing.jbuson) Portable The Jxxx version is usually the one you want, rather than xxx. Communicates with OS's natve window system Same Java program looks different when run on PC, Linux and Mac Components as Containers Use JPanel to organize and positon other components (analogous to vpair, hpair)

OnOffDemo The Lightswitch GUI program in Swing.