Swing and you are winning

Size: px
Start display at page:

Download "Swing and you are winning"

Transcription

1 Swing and you are winning Pimp your user interface with the power of the swing framework. Tuning a standard user interface with gradients, custom components and validating text fields using the JGlassPane. Gerrit Grunwald, Raith GmbH (Germany)

2 Agenda: A simple standard user interface Design prototype Gradients Custom components Animations Selfvalidating form using the glass pane 2

3 A simple standard user interface Form based application to gather feedback from a user. There are mandatory fields and free fields to fill out. Mandatory fields are marked with an asterisk. Doesn t it look nice? NO!!! 3

4 The design prototype Use graphics program like Adobe Fireworks to create a design prototype containing gradients custom components animations etc. 4

5 Customizing Swing components Nearly all Swing components whose names begin with J descend from JComponent. For example, JPanel, JScrollPane, JButton, and JTable all inherit from JComponent. The easy way to customize components is to override the paintcomponent() method which the mentioned components also inherit from JComponent. 5

6 Gradients are powerful tools to create astonishing effects like shadows gloss all kinds of 3D effects mirroring so let s use it 6

7 Using a multicolor gradient in the background 7

8 Custom JPanel Design Prototype how to do that in Swing? 8

9 Creating the customized JPanel public class SDLinearGradientPanel extends JPanel BufferedImage cache = protected void paintcomponent(graphics g) (Graphics2D) g2 = (Graphics2D) g; if (cache == null cache.getheight()!= getheight()) cache = createbackgroundimage(); } g2.drawimage(cache, 0, 0, getwidth(), getheight(), null); } g2.dispose(); private BufferedImage createbackgroundimage() final float[] FRACTIONS = 0.0f, 0.1f, 0.4f, 1.0f}; final Color[] COLORS = new Color(0,0,0,255), new Color(32,53,72,255), new Color(0,0,0,255), new Color(32,53,72,255)}; LinearGradientPaint bgndgradient = new LinearGradientPaint(start, stop, FRACTIONS, COLORS); 9

10 Using a customized buttons 10

11 Custom JButton Design Prototype Text how to do that in Swing? 11

12 Stripping down the prototype #1 Background Shape & Background Gradient #2 Foreground Shape & Foreground Gradient #3 Highlight Shape & Highlight Gradient #4 Button Text Text 12

13 Creating the background shape #1 Background Shape public class SDButton extends JButton private java.awt.shape getbackgroundshape() return new java.awt.geom.roundrectangle2d.float(0, 0, getwidth(), getheight(), 10, 10); } 13

14 Creating the background gradient #1 Background Shape Point2D start = new java.awt.geom.point2d.float(0, 0); Point2D stop = new java.awt.geom.point2d.float(0, getheight()); final float[] FRACTIONS_BACKGROUND = 0.0f, 0.33f }; final Color[] COLORS_BACKGROUND = new Color(1.0f, 1.0f, 1.0f, 1.0f), new Color(0.0f, 0.0f, 0.0f, 1.0f) }; LinearGradientPaint paintbackground = new java.awt.lineargradientpaint (start, stop, FRACTIONS_BACKGROUND, COLORS_BACKGROUND); 14

15 Creating the foreground shape #2 Foreground Shape public class SDButton extends JButton private java.awt.shape getforegroundshape() return new java.awt.geom.roundrectangle2d.float(1, 1, getwidth() - 2, getheight() - 2, 8, 8); } 15

16 Creating the foreground gradient #2 Foreground Shape Point2D start = new java.awt.geom.point2d.float(0, 0); Point2D stop = new java.awt.geom.point2d.float(0, getheight()); final float[] FRACTIONS_FOREGROUND = 0.0f, 1.0f }; final Color[] COLORS_FOREGROUND = new Color(0.0f, 0.0f, 0.0f, 1.0f), new Color( f, f, f, 1.0f) }; LinearGradientPaint paintforeground = new java.awt.lineargradientpaint (start, stop, FRACTIONS_FOREGROUND, COLORS_FOREGROUND); 16

17 Creating the highlight shape #3 Highlight Shape public class SDButton extends JButton private java.awt.shape gethighlightshape() java.awt.geom.roundrectangle2d rrecthighlight = (java.awt.geom.roundrectangle2d) getforegroundshape(); java.awt.geom.rectangle2d recthighlight = new java.awt.geom.rectangle2d.float (1, getheight() / 2, getwidth() - 2, getheight() - 2); java.awt.geom.area shapehighlight = new java.awt.geom.area(rrecthighlight); shapehighlight.subtract(new java.awt.geom.area(recthighlight)); return shapehighlight; } 17

18 Creating the highlight gradient #3 Highlight Shape Point2D start = new java.awt.geom.point2d.float(0, 0); Point2D stop = new java.awt.geom.point2d.float(0, getheight()); final float[] FRACTIONS_HIGHLIGHT = 0.0f, 1.0f }; final Color[] COLORS_HIGHLIGHT = new Color(1.0f, 1.0f, 1.0f, 0.4f), new Color(1.0f, 1.0f, 1.0f, 0.2f) }; LinearGradientPaint painthighlight = new java.awt.lineargradientpaint (start, stop, FRACTIONS_HIGHLIGHT, COLORS_HIGHLIGHT); 18

19 Creating the text #4 Button Text Text // Select font and get textboundary g2.setfont(new Font("Verdana", 1, 12)); FontMetrics metrics = g2.getfontmetrics(); Rectangle2D textboundary = metrics.getstringbounds(text, g2); // Draw text shadow g2.setcolor(color.dark_gray); g2.drawstring(text, (int) ((getwidth() - textboundary.getwidth()) / 2), getheight() - metrics.getheight() - ((getheight() - metrics.getheight()) / 2) + metrics.getascent()); // Draw text g2.setcolor(color.white); g2.drawstring(text, (int) ((getwidth() - textboundary.getwidth()) / 2-1), getheight() - metrics.getheight() - ((getheight() - metrics.getheight()) / 2) + metrics.getascent() + armedoffset - 1); 19

20 Use BufferedImage() for assembling the parts public class SDButton extends JButton private BufferedImage createbuttonimage(string text) BufferedImage buttonimage = new BufferedImage(getWidth(), getheight(), TYPE_INT_ARGB); java.awt.graphics2d g2 = buttonimage.creategraphics(); g2.setrenderinghint(key_antialiasing, VALUE_ANTIALIAS_ON); g2.setrenderinghint(key_text_antialiasing, VALUE_TEXT_ANTIALIAS_ON); // Draw background rectangle LinearGradientPaint paintbackground = new LinearGradientPaint(start, stop, FRACTIONS_BACKGROUND, COLORS_BACKGROUND); g2.setpaint(paintbackground); g2.fill(getbackgroundshape()); // Draw foreground rectangle LinearGradientPaint paintforeground = new LinearGradientPaint(start, stop, FRACTIONS_FOREGROUND, COLORS_FOREGROUND); g2.setpaint(paintforeground); g2.fill(getforegroundshape()); // Draw highlight shape LinearGradientPaint painthighlight = new LinearGradientPaint(start, stop, FRACTIONS_HIGHLIGHT, COLORS_HIGHLIGHT); g2.setpaint(painthighlight); g2.fill(gethighlightshape()); 20

21 Finally overide paintcomponent() method Text public class SDButton extends protected void paintcomponent(graphics g) Graphics2D g2 = (Graphics2D) g; g2.setrenderinghint(key_antialiasing, VALUE_ANTIALIAS_ON); java.awt.image.bufferedimage buttonimage = createbuttonimage(gettext()); g2.drawimage(buttonimage, 0, 0, this); 21

22 Using animations for visualization how to do that in Swing? 22

23 Painting a mouse over highlight Text Text Point2D center = new Point2D.Float((getWidth() / 2), (getheight() / 2)); float[] dist = 0.0f, 1.0f }; final Color FULLY_TRANSPARENT = new Color 1.0f, 1.0f, 1.0f, 0.0f ); Color[] colors = fadingcolor, FULLY_TRANSPARENT }; int radius = getwidth() / 3; RadialGradientPaint gradient = new RadialGradientPaint(center, radius, dist, colors); g2.setpaint(gradient); g2.fill(getbackgroundshape()); 23

24 Painting a mouse over highlight Text Text // DrawMouseOverHighlight if (enabled) Point2D center = new Point2D.Float((getWidth() / 2), (getheight() / 2)); float[] dist = 0.0f, 1.0f }; Color[] colors = fadingcolor, TOTAL_TRANSPARENT }; int radius = getwidth() / 3; final RadialGradientPaint PAINT_MOUSEOVER_HIGHLIGHT = RadialGradientPaint(center, radius, dist, colors); g2.setpaint(paint_mouseover_highlight); g2.fill(getbackgroundshape()); } Use a MouseListener as trigger for the effect 24

25 Use a thread to in-/decrease transparency int fadingalpha = fadingcolor.getalpha(); // Fade out if (!fadein) while (fadingalpha > 0) Thread.sleep(50); fadingcolor = new Color(255, 255, 255, fadingalpha); fadingalpha -= 15; repaint(); } fadingcolor = new Color(255, 255, 255, 0); } repaint(); // Fade in if (fadein) while (fadingalpha < 100) Thread.sleep(50); fadingcolor = new Color(255, 255, 255, fadingalpha); fadingalpha += 15; repaint(); } fadingcolor = new Color(255, 255, 255, 100); repaint(); } 25

26 Using the GlassPane for validation! first name not valid Luke valid 26

27 WTF is the GlassPane? Frame JMenuBar RootPane LayeredPane ContentPane GlassPane The GlassPane sits on top of every other component in a Swing UserInterface. 27

28 Custom JPanel as custom GlassPane The glasspane is a custom JPanel, where we again override the paintcomponent() method. The custom panel holds a reference on each component that should get a special marker for validation and paints them if needed. To avoid duplicate entries we are using java.util.set. 28

29 Paint the validation markers public class SDGlassPane extends protected void paintcomponent(graphics g) Graphics2D g2 = (Graphics2D) g; // Draw all AttentionMarker drawattentionmarker(g2); } private void drawattentionmarker(graphics2d g2) JComponent tmpcomponent; for (javax.swing.jcomponent component : this.markercomponentset) int originx = 0; int originy = 0; tmpcomponent = component; while (tmpcomponent.getparent() instanceof javax.swing.jcomponent) originx += tmpcomponent.getx(); originy += tmpcomponent.gety(); tmpcomponent = (JComponent) tmpcomponent.getparent(); } g2.drawimage(marker_image, (originx - HALF_MARKER_SIZE), (originy - HALF_MARKER_SIZE), null); } } 29

30 Final thoughts You don t need Flash, Silverlight or JavaFX to create nice looking userinterfaces. Swing is very flexible which means nearly everything is possible as long as you know how to do it. When it comes to complicated UI s it might be more easy to use JavaFX instead of Swing but this we ll see in the future. So let s swing 30

31 Thanx for your attention 31

32 Webstart version available here Just doubleclick 32

33 References: Java 2D Graphics by Jonathan Knudsen Java 2D API Graphics by Vincent J. Hardy Swing Hacks by Joshua Marinacci Filthy Rich Clients by Chet Haase and Romain Guy Java Swing by Marc Loy, Robert Eckstein, Dave Wood, James Elliott and Brian Cole 33

Filthy Rich Clients: Filthier. Richer. Clientier. Romain Guy, Google Chet Haase, Adobe Systems

Filthy Rich Clients: Filthier. Richer. Clientier. Romain Guy, Google Chet Haase, Adobe Systems Filthy Rich Clients: Filthier Richer Clientier Romain Guy, Google Chet Haase, Adobe Systems Learn techniques for making cooler, better, and just darned funner applications. Get filthy. 2008 JavaOne SM

More information

Bringing Life to Swing Desktop Applications

Bringing Life to Swing Desktop Applications Bringing Life to Swing Desktop Applications Alexander Potochkin Sun Microsystems Kirill Grouchnikov Amdocs Inc. TS-3414 2007 JavaOne SM Conference Session TS-3414 Presentation Goal Learn advanced painting

More information

Advanced Effects in Java Desktop Applications

Advanced Effects in Java Desktop Applications Advanced Effects in Java Desktop Applications Kirill Grouchnikov, Senior Software Engineer, Amdocs kirillcool@yahoo.com http://www.pushing-pixels.org OSCON 2007 Agenda Swing pipeline Hooking into the pipeline

More information

Graphics and Painting

Graphics and Painting Graphics and Painting Lecture 17 CGS 3416 Fall 2015 November 30, 2015 paint() methods Lightweight Swing components that extend class JComponent have a method called paintcomponent, with this prototype:

More information

Assignment 2. Application Development

Assignment 2. Application Development Application Development Assignment 2 Content Application Development Day 2 Lecture The lecture covers the key language elements of the Java programming language. You are introduced to numerical data and

More information

Kirill Grouchnikov, Amdocs Desktop Matters Conference San Jose, March

Kirill Grouchnikov, Amdocs Desktop Matters Conference San Jose, March Kirill Grouchnikov, Amdocs Desktop Matters Conference San Jose, March 8-9 2007 Show two sample effects on buttons Show how this can be achieved with UI delegates Discuss alternative implementations Custom

More information

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Graphics. Lecture 18 COP 3252 Summer June 6, 2017 Graphics Lecture 18 COP 3252 Summer 2017 June 6, 2017 Graphics classes In the original version of Java, graphics components were in the AWT library (Abstract Windows Toolkit) Was okay for developing simple

More information

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 9/e Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved. Overview capabilities for drawing two-dimensional shapes, controlling colors and controlling fonts. One of

More information

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

Graphics in Swing. Engineering 5895 Faculty of Engineering & Applied Science Memorial University of Newfoundland Graphics in Swing Engineering 5895 Faculty of Engineering & Applied Science Memorial University of Newfoundland 1 paintcomponent and repaint Each Swing component has the following paint methods: void paintcomponent(

More information

Swing Rocks - A Tribute to Filthy Rich Clients

Swing Rocks - A Tribute to Filthy Rich Clients Swing Rocks - A Tribute to Filthy Rich Clients Pär Sikö, Martin Gunnarsson Epsilon Information Technology One way that Pollak has found to speed up JavaTM programs is to rewrite their user interfaces in

More information

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

Agenda. Programming Seminar. By: dr. Amal Khalifa. Coordinate systems Colors Fonts Drawing shapes Graphics2D API Agenda Coordinate systems Colors Fonts Drawing shapes Graphics2D API By: dr. Amal Khalifa 1 Programming Seminar @12:30 13:30 pm on Wednesday 9/4/2014 Location : 2.505.01 Painting components 2 Every component

More information

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

Graphic Interface Programming II Using Swing and OOP more advanced issues. Uppsala universitet Graphic Interface Programming II Using Swing and OOP more advanced issues IT Uppsala universitet Good interface programming Swing is an EXTENDIBLE toolkit Build your OWN components Many times you need

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Hal Perkins Winter 2018 Java Graphics and GUIs 1 The plan Today: introduction to Java graphics and Swing/AWT libraries Then: event-driven programming and user interaction

More information

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

Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms. Java GUI Windows Events Drawing 1 Java GUI Toolkits Toolkit AWT Description Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms.

More information

CS 251 Intermediate Programming GUIs: Components and Layout

CS 251 Intermediate Programming GUIs: Components and Layout CS 251 Intermediate Programming GUIs: Components and Layout Brooke Chenoweth University of New Mexico Fall 2017 import javax. swing.*; Hello GUI public class HelloGUI extends JFrame { public HelloGUI ()

More information

IT101. Graphical User Interface

IT101. Graphical User Interface IT101 Graphical User Interface Foundation Swing is a platform-independent set of Java classes used for user Graphical User Interface (GUI) programming. Abstract Window Toolkit (AWT) is an older Java GUI

More information

Lecture 18 Java Graphics and GUIs

Lecture 18 Java Graphics and GUIs CSE 331 Software Design and Implementation The plan Today: introduction to Java graphics and Swing/AWT libraries Then: event-driven programming and user interaction Lecture 18 Java Graphics and GUIs None

More information

UI Software Organization

UI Software Organization UI Software Organization The user interface From previous class: Generally want to think of the UI as only one component of the system Deals with the user Separate from the functional core (AKA, the app

More information

Java: Graphical User Interfaces (GUI)

Java: Graphical User Interfaces (GUI) Chair of Software Engineering Carlo A. Furia, Marco Piccioni, and Bertrand Meyer Java: Graphical User Interfaces (GUI) With material from Christoph Angerer The essence of the Java Graphics API Application

More information

Programming graphics

Programming graphics Programming graphics Need a window javax.swing.jframe Several essential steps to use (necessary plumbing ): Set the size width and height in pixels Set a title (optional), and a close operation Make it

More information

Swinging from the Outside

Swinging from the Outside Swinging from the Outside A guide to navigating Swing from the outside of Sun Brian Mason, Dir Software of Engineering, Teseda S295599 Space is big, really big. You might think it is a long way down to

More information

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

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson) Graphics programming COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson) Overview Aims To provide an overview of Swing and the AWT To show how to build

More information

Graphic Interface Programming II Events and Threads. Uppsala universitet

Graphic Interface Programming II Events and Threads. Uppsala universitet Graphic Interface Programming II Events and Threads IT Uppsala universitet Animation Animation adds to user experience Done right, it enhances the User Interface Done wrong, it distracts and irritates

More information

User interfaces and Swing

User interfaces and Swing User interfaces and Swing Overview, applets, drawing, action listening, layout managers. APIs: java.awt.*, javax.swing.*, classes names start with a J. Java Lectures 1 2 Applets public class Simple extends

More information

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

Object-Oriented Programming Design. Topic : Graphics Programming GUI Part I Electrical and Computer Engineering Object-Oriented Topic : Graphics GUI Part I Maj Joel Young Joel.Young@afit.edu 15-Sep-03 Maj Joel Young A Brief History Lesson AWT Abstract Window Toolkit Implemented

More information

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

Announcements. Introduction. Lecture 18 Java Graphics and GUIs. Announcements. CSE 331 Software Design and Implementation CSE 331 Software Design and Implementation Lecture 18 Java Graphics and GUIs Announcements Leah Perlmutter / Summer 2018 Announcements Quiz 6 due Thursday 8/2 Homework 7 due Thursday 8/2 Regression testing

More information

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

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008 Overview Lecture 7: Inheritance and GUIs Written by: Daniel Dalevi Inheritance Subclasses and superclasses Java keywords Interfaces and inheritance The JComponent class Casting The cosmic superclass Object

More information

Dr. Hikmat A. M. AbdelJaber

Dr. Hikmat A. M. AbdelJaber Dr. Hikmat A. M. AbdelJaber Portion of the Java class hierarchy that include basic graphics classes and Java 2D API classes and interfaces. java.lang.object Java.awt.Color Java.awt.Component Java.awt.Container

More information

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

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics Topic 9: Swing Outline Swing = Java's GUI library Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 7: Expand moving shapes from Assignment 4 into game. "Programming

More information

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011 GUI DYNAMICS Lecture July 26 CS2110 Summer 2011 GUI Statics and GUI Dynamics 2 Statics: what s drawn on the screen Components buttons, labels, lists, sliders, menus,... Containers: components that contain

More information

Inheritance. One class inherits from another if it describes a specialized subset of objects Terminology:

Inheritance. One class inherits from another if it describes a specialized subset of objects Terminology: Inheritance 1 Inheritance One class inherits from another if it describes a specialized subset of objects Terminology: the class that inherits is called a child class or subclass the class that is inherited

More information

Computer Science 210: Data Structures. Intro to Java Graphics

Computer Science 210: Data Structures. Intro to Java Graphics Computer Science 210: Data Structures Intro to Java Graphics Summary Today GUIs in Java using Swing in-class: a Scribbler program READING: browse Java online Docs, Swing tutorials GUIs in Java Java comes

More information

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

CSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction CSC 160 LAB 8-1 DIGITAL PICTURE FRAME PROFESSOR GODFREY MUGANDA DEPARTMENT OF COMPUTER SCIENCE 1. Introduction Download and unzip the images folder from the course website. The folder contains 28 images

More information

PIC 20A GUI with swing

PIC 20A GUI with swing PIC 20A GUI with swing Ernest Ryu UCLA Mathematics Last edited: November 22, 2017 Hello swing Let s create a JFrame. import javax. swing.*; public class Test { public static void main ( String [] args

More information

1.00/1.001 Introduction to Computers and Engineering Problem Solving Spring Quiz 2

1.00/1.001 Introduction to Computers and Engineering Problem Solving Spring Quiz 2 1.00/1.001 Introduction to Computers and Engineering Problem Solving Spring 2010 - Quiz 2 Name: MIT Email: TA: Section: You have 80 minutes to complete this exam. For coding questions, you do not need

More information

Introduction to the JAVA UI classes Advanced HCI IAT351

Introduction to the JAVA UI classes Advanced HCI IAT351 Introduction to the JAVA UI classes Advanced HCI IAT351 Week 3 Lecture 1 17.09.2012 Lyn Bartram lyn@sfu.ca About JFC and Swing JFC Java TM Foundation Classes Encompass a group of features for constructing

More information

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

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 5: Will be an open-ended Swing project. "Programming Contest"

More information

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!

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! Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Why are we studying Swing? 1. Useful & fun! 2. Good application of OOP techniques

More information

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

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class CHAPTER GRAPHICAL USER INTERFACES 10 Slides by Donald W. Smith TechNeTrain.com Final Draft 10/30/11 10.1 Frame Windows Java provides classes to create graphical applications that can run on any major graphical

More information

Object Orientated Programming in Java. Benjamin Kenwright

Object Orientated Programming in Java. Benjamin Kenwright Graphics Object Orientated Programming in Java Benjamin Kenwright Outline Essential Graphical Principals JFrame Window (Popup Windows) Extending JFrame Drawing from paintcomponent Drawing images/text/graphics

More information

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

CompSci 125 Lecture 17. GUI: Graphics, Check Boxes, Radio Buttons 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

More information

Graphic User Interfaces. - GUI concepts - Swing - AWT

Graphic User Interfaces. - GUI concepts - Swing - AWT Graphic User Interfaces - GUI concepts - Swing - AWT 1 What is GUI Graphic User Interfaces are used in programs to communicate more efficiently with computer users MacOS MS Windows X Windows etc 2 Considerations

More information

Lecture 3: Java Graphics & Events

Lecture 3: Java Graphics & Events Lecture 3: Java Graphics & Events CS 62 Fall 2017 Kim Bruce & Alexandra Papoutsaki Text Input Scanner class Constructor: myscanner = new Scanner(System.in); can use file instead of System.in new Scanner(new

More information

GUI (Graphic User Interface) Programming. Part 2 (Chapter 8) Chapter Goals. Events, Event Sources, and Event Listeners. Listeners

GUI (Graphic User Interface) Programming. Part 2 (Chapter 8) Chapter Goals. Events, Event Sources, and Event Listeners. Listeners GUI (Graphic User Interface) Programming Part 2 (Chapter 8) Chapter Goals To understand the Java event model To install action and mouse event listeners To accept input from buttons, text fields, and the

More information

Inheritance Systems. Merchandise. Television Camcorder Shirt Shoe Dress 9.1.1

Inheritance Systems. Merchandise. Television Camcorder Shirt Shoe Dress 9.1.1 Merchandise Inheritance Systems Electronics Clothing Television Camcorder Shirt Shoe Dress Digital Analog 9.1.1 Another AcademicDisciplines Hierarchy Mathematics Engineering Algebra Probability Geometry

More information

Nimbus: Making Swing Look Sexy!

Nimbus: Making Swing Look Sexy! Nimbus: Making Swing Look Sexy! Jasper Potts Peter Zhelezniakov Sun Microsystems Abstract Get acquainted with the new Nimbus Look and Feel, and learn some ways to customize it 2 Agenda > Overview > Architecture

More information

Programmierpraktikum

Programmierpraktikum Programmierpraktikum Claudius Gros, SS2012 Institut für theoretische Physik Goethe-University Frankfurt a.m. 1 of 25 17/01/13 11:45 Swing Graphical User Interface (GUI) 2 of 25 17/01/13 11:45 Graphical

More information

Graphical User Interfaces (GUIs)

Graphical User Interfaces (GUIs) CMSC 132: Object-Oriented Programming II Graphical User Interfaces (GUIs) Department of Computer Science University of Maryland, College Park Model-View-Controller (MVC) Model for GUI programming (Xerox

More information

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

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008 Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008 Announcements A3 is up, due Friday, Oct 10 Prelim 1 scheduled for Oct 16 if you have a conflict, let us know now 2 Interactive

More information

Putting the 'Free' into JFreeChart

Putting the 'Free' into JFreeChart Putting the 'Free' into JFreeChart 25 February 2006 Dave Gilbert JFreeChart Project Leader Overview The Java Trap; JFreeChart; Java2D (Graphics2D); The Free Stack: Cairo (CairoGraphics2D); GNU Classpath;

More information

Java Coordinate System

Java Coordinate System Java Graphics Drawing shapes in Java such as lines, rectangles, 3-D rectangles, a bar chart, or a clock utilize the Graphics class Drawing Strings Drawing Lines Drawing Rectangles Drawing Ovals Drawing

More information

2IS45 Programming

2IS45 Programming Course Website Assignment Goals 2IS45 Programming http://www.win.tue.nl/~wsinswan/programmeren_2is45/ Rectangles Learn to use existing Abstract Data Types based on their contract (class Rectangle in Rectangle.

More information

Graphical User Interfaces 2

Graphical User Interfaces 2 Graphical User Interfaces 2 CSCI 136: Fundamentals CSCI 136: Fundamentals of Computer of Science Computer II Science Keith II Vertanen Keith Vertanen Copyright 2011 Extending JFrame Dialog boxes Overview

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Kevin Zatloukal Summer 2017 Java Graphics and GUIs (Based on slides by Mike Ernst, Dan Grossman, David Notkin, Hal Perkins, Zach Tatlock) Review: how to create

More information

Unit 7: Event driven programming

Unit 7: Event driven programming Faculty of Computer Science Programming Language 2 Object oriented design using JAVA Dr. Ayman Ezzat Email: ayman@fcih.net Web: www.fcih.net/ayman Unit 7: Event driven programming 1 1. Introduction 2.

More information

Graphical User Interface (GUI)

Graphical User Interface (GUI) Graphical User Interface (GUI) An example of Inheritance and Sub-Typing 1 Java GUI Portability Problem Java loves the idea that your code produces the same results on any machine The underlying hardware

More information

Lecture 5: Java Graphics

Lecture 5: Java Graphics Lecture 5: Java Graphics CS 62 Spring 2019 William Devanny & Alexandra Papoutsaki 1 New Unit Overview Graphical User Interfaces (GUI) Components, e.g., JButton, JTextField, JSlider, JChooser, Containers,

More information

Interactors. Brahm Capoor.

Interactors. Brahm Capoor. Interactors Brahm Capoor brahm@stanfordedu Learning goals for today To learn how to use interactors in our programs Learning goals for today To learn how to use interactors in our programs To go under

More information

Lecture 7 A First Graphic Program And Data Structures & Drawing

Lecture 7 A First Graphic Program And Data Structures & Drawing Lecture 7 A First Graphic Program And Data Structures & Drawing Objective The objective is that you will understand: How to program the generation of 2D and 3D images. How to manipulate those images through

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 36 April 18, 2012 Swing IV: Mouse and Keyboard Input Announcements Lab this week is review (BRING QUESTIONS) Game Project is out, due Tuesday April

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 35 April 15, 2013 Swing III: OO Design, Mouse InteracGon Announcements HW10: Game Project is out, due Tuesday, April 23 rd at midnight If you want

More information

Computer Games 2012 Game Development

Computer Games 2012 Game Development Computer Games 2012 Game Development Dr. Mathias Lux Klagenfurt University This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Agenda Game Loop Sprites & 2.5D Images

More information

Question 1. Show the steps that are involved in sorting the string SORTME using the quicksort algorithm given below.

Question 1. Show the steps that are involved in sorting the string SORTME using the quicksort algorithm given below. Name: 1.124 Quiz 2 Thursday November 9, 2000 Time: 1 hour 20 minutes Answer all questions. All questions carry equal marks. Question 1. Show the steps that are involved in sorting the string SORTME using

More information

Software Construction

Software Construction Lecture 11: Command Design Pattern Software Construction in Java for HSE Moscow Tom Verhoeff Eindhoven University of Technology Department of Mathematics & Computer Science Software Engineering & Technology

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 32 April 9, 2018 Swing I: Drawing and Event Handling Chapter 29 HW8: Spellchecker Available on the web site Due: Tuesday! Announcements Parsing, working

More information

JavaFX Basics. Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1.

JavaFX Basics. Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1. JavaFX Basics rights reserved. 1 Motivations JavaFX is a new framework for developing Java GUI programs. The JavaFX API is an excellent example of how the object-oriented principle is applied. This chapter

More information

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java Chapter 3 Syntax, Errors, and Debugging Objectives Construct and use numeric and string literals. Name and use variables and constants. Create arithmetic expressions. Understand the precedence of different

More information

Widgets. Widgets Widget Toolkits. User Interface Widget

Widgets. Widgets Widget Toolkits. User Interface Widget Widgets Widgets Widget Toolkits 2.3 Widgets 1 User Interface Widget Widget is a generic name for parts of an interface that have their own behavior: buttons, drop-down menus, spinners, file dialog boxes,

More information

GUI Output. Adapted from slides by Michelle Strout with some slides from Rick Mercer. CSc 210

GUI Output. Adapted from slides by Michelle Strout with some slides from Rick Mercer. CSc 210 GUI Output Adapted from slides by Michelle Strout with some slides from Rick Mercer CSc 210 GUI (Graphical User Interface) We all use GUI s every day Text interfaces great for testing and debugging Infants

More information

class BankFilter implements Filter { public boolean accept(object x) { BankAccount ba = (BankAccount) x; return ba.getbalance() > 1000; } }

class BankFilter implements Filter { public boolean accept(object x) { BankAccount ba = (BankAccount) x; return ba.getbalance() > 1000; } } 9.12) public interface Filter boolean accept(object x); Describes any class whose objects can measure other objects. public interface Measurer double measure(object anobject); This program tests the use

More information

CS11 Java. Fall Lecture 4

CS11 Java. Fall Lecture 4 CS11 Java Fall 2006-2007 Lecture 4 Today s Topics Interfaces The Swing API Event Handlers Inner Classes Arrays Java Interfaces Classes can only have one parent class No multiple inheritance in Java! By

More information

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

Lab & Assignment 1. Lecture 3: ArrayList & Standard Java Graphics. Random Number Generator. Read Lab & Assignment Before Lab Wednesday! Lab & Assignment 1 Lecture 3: ArrayList & Standard Java Graphics CS 62 Fall 2015 Kim Bruce & Michael Bannister Strip with 12 squares & 5 silver dollars placed randomly on the board. Move silver dollars

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Kevin Zatloukal Fall 2017 Java GUIs (Based on slides by Mike Ernst, Dan Grossman, David Notkin, Hal Perkins, Zach Tatlock) Reminders HW8 due today Section tomorrow

More information

ICOM 4015 Advanced Programming Laboratory. Chapter 3 Introduction to Graphical Applications in Java using Swing

ICOM 4015 Advanced Programming Laboratory. Chapter 3 Introduction to Graphical Applications in Java using Swing ICOM 4015 Advanced Programming Laboratory Chapter 3 Introduction to Graphical Applications in Java using Swing University of Puerto Rico Electrical and Computer Engineering Department by Juan E. Surís

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 34 April 18, 2013 Swing II: Layout & Designing a GUI app How is HW10 going so far? 1. not started 2. started reading 3. got an idea for what game to

More information

Developing LimeWire: Swing for the Masses

Developing LimeWire: Swing for the Masses Developing LimeWire: Swing for the Masses Sam Berlin Michael Everett TS-5162 Lime Wire LLC Lime Wire LLC GOAL: > To help you easily create large, good-looking User Interfaces in Swing 2 What is LimeWire?

More information

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components CS112-Section2 Hakan Guldas Burcin Ozcan Meltem Kaya Muge Celiktas Notes of 6-8 May Graphics Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how

More information

G51PRG: Introduction to Programming Second semester Applets and graphics

G51PRG: Introduction to Programming Second semester Applets and graphics G51PRG: Introduction to Programming Second semester Applets and graphics Natasha Alechina School of Computer Science & IT nza@cs.nott.ac.uk Previous two lectures AWT and Swing Creating components and putting

More information

Design patterns for graphical user interface applications

Design patterns for graphical user interface applications Design patterns for graphical user interface applications Prof.Asoc. Alda Kika Department of Informatics Faculty of Natural Sciences University of Tirana Outline Pattern Concept Design pattern in computer

More information

Strategy Pattern. What is it?

Strategy Pattern. What is it? Strategy Pattern 1 What is it? The Strategy pattern is much like the State pattern in outline, but a little different in intent. The Strategy pattern consists of a number of related algorithms encapsulated

More information

CompSci 125 Lecture 20. Inheritance: Introduction, Overrides UML: Introduction to Class Diagrams

CompSci 125 Lecture 20. Inheritance: Introduction, Overrides UML: Introduction to Class Diagrams CompSci 125 Lecture 20 Inheritance: Introduction, Overrides UML: Introduction to Class Diagrams Announcements Introduction to Inheritance Inheritance: Motivation Software is expensive Wish to define a

More information

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

Here is a list of a few of the components located in the AWT and Swing packages: Inheritance Inheritance is the capability of a class to use the properties and methods of another class while adding its own functionality. Programming In A Graphical Environment Java is specifically designed

More information

Programming Graphics (P1 2006/2007)

Programming Graphics (P1 2006/2007) Programming Graphics (P1 2006/2007) Fernando Brito e Abreu (fba@di.fct.unl.pt) Universidade Nova de Lisboa (http://www.unl.pt) QUASAR Research Group (http://ctp.di.fct.unl.pt/quasar) Chapter Goals To be

More information

!"# $!"%& ' (" % ) % % %* % % % * ' %

!# $!%& ' ( % ) % % %* % % % * ' % !"# $!"%& ' (" % ) % % %* % *! % % * ' % % Contents!!!! "#$ %&#! " # '# #(# #)! #*+ *++,#- *++)!#" #!.*" % #%,% /--% "0 %0 %*+#0 %&#-, $ % & #- )#-2-)!#.3 $4 # %% # #!#+5 )-# #!#)! 5#!# )!#!#,!#!# #!#!6)--#(#"!6)--#*++"!6)--,#--#"

More information

CS11 Java. Fall Lecture 3

CS11 Java. Fall Lecture 3 CS11 Java Fall 2014-2015 Lecture 3 Today s Topics! Class inheritance! Abstract classes! Polymorphism! Introduction to Swing API and event-handling! Nested and inner classes Class Inheritance! A third of

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Hal Perkins Spring 2017 GUI Event-Driven Programming 1 The plan User events and callbacks Event objects Event listeners Registering listeners to handle events Anonymous

More information

Polymorphism: Interfaces and Iteration. Fundamentals of Computer Science

Polymorphism: Interfaces and Iteration. Fundamentals of Computer Science Polymorphism: Interfaces and Iteration Fundamentals of Computer Science Outline A shape object hierarchy Classes that extend Versus classes that implements Java interfaces How Java handles multiple-inheritance

More information

CS 11 java track: lecture 3

CS 11 java track: lecture 3 CS 11 java track: lecture 3 This week: documentation (javadoc) exception handling more on object-oriented programming (OOP) inheritance and polymorphism abstract classes and interfaces graphical user interfaces

More information

Chapter 14 JavaFX Basics. Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.

Chapter 14 JavaFX Basics. Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. Chapter 14 JavaFX Basics 1 Motivations JavaFX is a new framework for developing Java GUI programs. The JavaFX API is an excellent example of how the object-oriented principle is applied. This chapter serves

More information

CS 201 Advanced Object-Oriented Programming Lab 10 - Recursion Due: April 21/22, 11:30 PM

CS 201 Advanced Object-Oriented Programming Lab 10 - Recursion Due: April 21/22, 11:30 PM CS 201 Advanced Object-Oriented Programming Lab 10 - Recursion Due: April 21/22, 11:30 PM Introduction to the Assignment In this assignment, you will get practice with recursion. There are three parts

More information

Java 2D Graphics. Drawing Primitives, Affine Transformations, Scene Graphs, Hit Tests. Drawing Primitives 2/9/2014. Using it is simple.

Java 2D Graphics. Drawing Primitives, Affine Transformations, Scene Graphs, Hit Tests. Drawing Primitives 2/9/2014. Using it is simple. Java 2D Graphics Drawing Primitives, Affine Transformations, Scene Graphs, Hit Tests Drawing Primitives Graphics - Abstract Base Class that supports basic drawing and rendering - Conceptually sim. to WatGUI

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 34 April 13, 2017 Model / View / Controller Chapter 31 How is the Game Project going so far? 1. not started 2. got an idea 3. submitted design proposal

More information

Event Driven Programming

Event Driven Programming Event Driven Programming Part 1 Introduction Chapter 12 CS 2334 University of Oklahoma Brian F. Veale 1 Graphical User Interfaces So far, we have only dealt with console-based programs Run from the console

More information

Inheritance and Interfaces

Inheritance and Interfaces Inheritance and Interfaces what is inheritance? examples & Java API examples inheriting a method overriding a method polymorphism Object tostring interfaces Ex: sorting and Comparable interface Inheritance

More information

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

+! Today. Lecture 3: ArrayList & Standard Java Graphics 1/26/14! n Reading. n Objectives. n Reminders. n Standard Java Graphics (on course webpage) +! Lecture 3: ArrayList & Standard Java Graphics +! Today n Reading n Standard Java Graphics (on course webpage) n Objectives n Review for this week s lab and homework assignment n Miscellanea (Random,

More information

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a CBOP3203 An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a page. When you use a Java technology-enabled

More information

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

First Name: AITI 2004: Exam 2 July 19, 2004 First Name: AITI 2004: Exam 2 July 19, 2004 Last Name: Standard Track Read Instructions Carefully! This is a 3 hour closed book exam. No calculators are allowed. Please write clearly if we cannot understand

More information

Image Java Foundation Classes (JFC) java.awt.image JFC. Image. Image. Image PNG GIF JPEG

Image Java Foundation Classes (JFC) java.awt.image JFC. Image. Image. Image PNG GIF JPEG 11 2013 6 25 11.1.............................. 11 1 11.2.............................. 11 2 11.3................................... 11 5 11.4.............................. 11 6 11.5.......................................

More information

Widgets. Widgets Widget Toolkits. 2.3 Widgets 1

Widgets. Widgets Widget Toolkits. 2.3 Widgets 1 Widgets Widgets Widget Toolkits 2.3 Widgets 1 User Interface Widget Widget is a generic name for parts of an interface that have their own behavior: buttons, drop-down menus, spinners, file dialog boxes,

More information