Object Orientated Programming in Java. Benjamin Kenwright

Similar documents
GUI Basics. Object Orientated Programming in Java. Benjamin Kenwright

MultiThreading. Object Orientated Programming in Java. Benjamin Kenwright

Lecture 7 A First Graphic Program And Data Structures & Drawing

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

Inheritance and Interfaces

Java Basics. Object Orientated Programming in Java. Benjamin Kenwright

Polymorphism. Object Orientated Programming in Java. Benjamin Kenwright

Graphics -- To be discussed

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

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

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: You will have 6 files all need to be located in the dir. named PA4:

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

IT101. Graphical User Interface

Graphics Applets. By Mr. Dave Clausen

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

Object Orientated Analysis and Design. Benjamin Kenwright

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

Internal Classes and Exceptions

Graphics Applets. By Mr. Dave Clausen

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

Unit 7: Event driven programming

Programming Languages and Techniques (CIS120)

Java Coordinate System

Software Construction

Programming Languages and Techniques (CIS120)

Appendix F: Java Graphics

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

CSS Selectors. Web Authoring and Design. Benjamin Kenwright

Shared Collection of Java Course Materials: New Topics Covered. Agenda

CSE 331 Software Design & Implementation

Final Examination Semester 2 / Year 2012

ECE 462 Object-Oriented Programming using C++ and Java. Graphical User Interface

Graphical User Interfaces 2

Introduction This assignment will ask that you write a simple graphical user interface (GUI).

Object-oriented programming in Java (2)

Programming Languages and Techniques (CIS120)

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

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Notation Part 1. Object Orientated Analysis and Design. Benjamin Kenwright

Appendix F: Java Graphics

Final Examination Semester 2 / Year 2010

Assignment 2. Application Development

Programmierpraktikum

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

G51PRG: Introduction to Programming Second semester Applets and graphics

2IS45 Programming

Programming Languages and Techniques (CIS120)

Overview. Applets. A Java GUI inside your browser! Important methods Drawing images Playing audio Getting input parameters Double buffering

Final Examination Semester 2 / Year 2011

Graphical User Interface (GUI)

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

Class 16: The Swing Event Model

CPS109 Lab 7. Source: Big Java, Chapter 7 Preparation: read Chapter 7 and the lecture notes for this week.

Summary Chapter 25 GUI Components: Part 2

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

Java Swing Introduction

CompSci 230 S Programming Techniques. Basic GUI Components

JavaScript Syntax. Web Authoring and Design. Benjamin Kenwright

CSE 331 Software Design and Implementation. Lecture 19 GUI Events

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

Rendering a 3-Dimensional Cube Applet Using Light Weight Java Graphing Library (LWJGL) with Java Swing with NetBeans IDE 6.1

CS 11 java track: lecture 3

Prototyping a Swing Interface with the Netbeans IDE GUI Editor

CSE wi Final Exam 3/12/18 Sample Solution

Programming Languages and Techniques (CIS120)

Lecture 19 GUI Events

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

Java Programming. Computer Science 112

CSE 331 Software Design & Implementation

CS 2113 Software Engineering

Graphical User Interface (GUI)

Homework 6 part 2: Turtle Etch-A-Sketch (40pts)

Graphic User Interfaces. - GUI concepts - Swing - AWT

Instruction to students:

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

AP CS Unit 12: Drawing and Mouse Events

H212 Introduction to Software Systems Honors

Javascript Events. Web Authoring and Design. Benjamin Kenwright

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

CSSE 220. Event Based Programming. Check out EventBasedProgramming from SVN

SIMPLE APPLET PROGRAM

Chapter 14: Applets and More

8/23/2014. Chapter Topics. Introduction to Applets. Introduction to Applets. Introduction to Applets. Applet Limitations. Chapter 14: Applets and More

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

Chapter 14: Applets and More

To help you prepare for Problem 2, you are to write a simple Swing application which uses an anonymous inner class to control the application.

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

Lesson 22 Enhancing Presentations with Multimedia Effects

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

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

CIS 120 Programming Languages and Techniques. Final Exam, May 3, 2011

ming 3 Resize the Size to [700, 500]. Note that the background containers in the program code: reference the then under () { 153, 255, 0 ) );

Java for Non Majors. Final Study Guide. April 26, You will have an opportunity to earn 20 extra credit points.

Making Visio Diagrams Come Alive with Data

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

Human-Computer Interaction IS4300

CSSE 220. Intro to Java Graphics. Check out IntroToJavaGraphics and BiggestFan projects from SVN

Chapter 6 Introduction to Defining Classes

Transcription:

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 Today s Practical Review/Discussion

Revision Question Will the following code compile? If yes then what will be the output? javac Bark.java java Bark

Answer Compile: Yes Output: WoofWoof

Question Will the following code compile? If yes then what will be the output?

Answer Compile: Yes Output: String

Question Will the following code compile? If yes then what will be the output?

Answer Compile: No Reason: Method is ambiguous

Question Will the following code compile? If yes then what will be the output?

Answer Compile: Yes Output: ArithmeticException

Question Will the following code compile? If yes then what will be the output?

Answer Compile: Yes Output: null==null

Question Will the following code compile? If yes then what will be the output?

Answer Compile: Yes Output: I m alive

Graphics How do you draw `complex diagrams? Customize/control what is drawn on our windows Animated clocks, bar-charts, images,

Graphical Coordinate System

JFrame Simple GUI Window Lets us perform simple drawing operations Basic Usage Instantiate the JFrame and assign text for the title bar JFrame frame = new Jframe( Title ); Specify size frame.setsize(width, height) Designate that closing the window ends the program frame.setdefaultcloseoperation(jframe.exit_on_close); Show the window frame.setvisible(true);

Using JFrame

Extending JFrame

Basic Drawing

Example JFrame

Example JPanel

Drawing Methods

Graphics Class Methods

Graphics Class Methods

Graphics Class Methods

Question What would be the output of this program? Sketch on paper what the output would look like

Answer javac MyPaint.java java cp. MyPaint

Example 1 2

Question What will the output for the following program?

Answer

Fixing Problems

Drawing Images

Images

Review Basic Graphic Methods

Question Write down the graphics methods you d use to draw the following output:

Question What would the following program output? javac MyPaint.java java cp. MyPaint

Answer Left mouse button is pressed

Force Redraw To notify Java to redraw our window (i.e., call paintcomponent) call repaint() For example, add new graphics each time the mouse button is pressed

Review Graphics can be drawn using a class which extends JPanel Swing will call the paintcomponent method to draw: protected void paintcomponent(graphics g); There are a variety of drawing methods: drawline(int x1, int y1, int x2, int y2); drawrect(int x, int y, int w, int h); drawoval(int x, int y, int w, int h); drawpolygon(int[] xpoints, int[] ypoints, int npoints);

Other Graphics Capabilities Lots of GUI Controls Buttons, sliders, checkboxes, tables, etc which you can override and improve Rich 2D drawing Line properties, translucent drawing, rotating, scaling images, coordinate transforms,... Animation Double-buffering, combining drawing with threads,..

Examples

Experiment Only scratched the surface of Graphics Very simple windows and graphics Combine the graphics with GUI components Buttons/menus Custom interfaces components e.g., Override default draw method for a button to create a new improved button look Events Mouse button presses (drawing program) Timing (animations)

Challenge Create a simple vector drawing program in Java Clear/load/save drawings Select buttons for different operations line, circle, color,... Detect mouse button presses draw lines, drag shapes, pick objects

Summary Overview Essential Graphical Principles JFrame, JPanel, paintcomponent, @Override (Checking) @Override (Checking) Hands-On/Practical Today is about Graphics with Java Drawing

This Week Read Associated Chapters Comprehensive Edition (Additional Chapters) Review Slides Java Exercises Online Quizzes

Crossword s e m i c o l o n o d u l u s

Exercises Chapter exercises 15.1-15.3 Comment your code Remember to zip the files together The name of the.zip file should be your student number (e.g., 39293923923.zip)

Questions/Discussion

Revision Question What does the following program print? a) Pain, Gain or Main (varies randomly) b) Pain or Main (varies randomly) c) Main (always) d) None of the above

Answer Investigate for next week...