Java Programming. Computer Science 112

Similar documents
CSE 331 Software Design & Implementation

IT101. Graphical User Interface

Assignment 2. Application Development

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

Adobe illustrator Introduction

Smoother Graphics Taking Control of Painting the Screen

Android Programming Family Fun Day using AppInventor

Class Meeting 05 (Lecture 04) Objectives for this class meeting. Conduct vote on basic style of game for class project

Direct Variations DIRECT AND INVERSE VARIATIONS 19. Name

4. Write sets of directions for how to check for direct variation. How to check for direct variation by analyzing the graph :

2IS45 Programming

What's the Slope of a Line?

A Guide to Autodesk Maya 2015

Lecture 5: Java Graphics

Designer Reference 1

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Lecture 3: Java Graphics & Events

UI Software Organization

Ai Adobe. Illustrator. Creative Cloud Beginner

In today s video I'm going show you how you can set up your own online business using marketing and affiliate marketing.

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

CS2110 Fall 2015 Assignment A5: Treemaps 1

mismatch between what is maybe possible today and what is going on in many of today's IDEs.

Programming Languages and Techniques (CIS120)

GRAPHICS PROGRAMMING. LAB #3 Starting a Simple Vector Animation

Programming Languages and Techniques (CIS120)

PaintPot: (Part 1) What You're Building. Before starting

Dell Canvas Layout. Version 1.0 User s Guide

UNIT 15 Polygons Lesson Plan 1 Angles

Software System Components 1 Graphics

(Refer Slide Time: 06:01)

CSE 331 Software Design and Implementation. Lecture 19 GUI Events

Basic Scene Composition

Porsche 91 1GT D m o d e ling tutorial - by Nim

Arrows and Watermark

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

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

(Refer Slide Time: 00:02:00)

Mobile Computing Professor Pushpedra Singh Indraprasth Institute of Information Technology Delhi Andriod Development Lecture 09

Edupen Pro User Manual

Instructor (Mehran Sahami):

PROFESSOR: Well, yesterday we learned a bit about symbolic manipulation, and we wrote a rather stylized

SNOWFLAKES PHOTO BORDER - PHOTOSHOP CS6 / CC

Java Programming. Computer Science 112

Custom Shapes As Text Frames In Photoshop

Software Prototyping. & App Inventor

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

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

Creating joints for the NovodeX MAX exporter

Camtasia Studio 7 User Guide

Graphical User Interface (GUI)

CSE115 Lab 4 Fall 2016

Using the API: Introductory Graphics Java Programming 1 Lesson 8

Creating a Brochure in Publisher

Press the Plus + key to zoom in. Press the Minus - key to zoom out. Scroll the mouse wheel away from you to zoom in; towards you to zoom out.

Human-Computer Interaction IS4300

EDITING AND COMBINING SHAPES AND PATHS

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!

Lecture 18 Java Graphics and GUIs

Slide 1 CS 170 Java Programming 1 Testing Karel

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

In this lesson you are going to create a drawing program similar to Windows Paint. 1. Start with a new project and remove the default cat sprite.

Let s Make a Front Panel using FrontCAD

CS 2113 Software Engineering

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

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

NETWORK THE HOME 10 FOLDERS APPS

2D Graphics. Shape Models, Drawing, Selection. CS d Graphics 1

Java Programming. Computer Science 112

Assignment 1. Application Development

SketchUp Tool Basics

PaintPot. Figure 2-1. The PaintPot app

CS 2110 Fall Instructions. 1 Installing the code. Homework 4 Paint Program. 0.1 Grading, Partners, Academic Integrity, Help

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

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

In our first lecture on sets and set theory, we introduced a bunch of new symbols and terminology.

Java Programming. Computer Science 112

Our second exam is Thursday, November 10. Note that it will not be possible to get all the homework submissions graded before the exam.

Lecture 19 GUI Events

Inkscape Interface. commands panes snap. tool. menus. controls. controls. toolbox. canvas. page. palette

BCSWomen Android programming (with AppInventor) Family fun day World record attempt

Drawing Tools. Drawing a Rectangle

TSM Report Designer. Even Microsoft Excel s Data Import add-in can be used to extract TSM information into an Excel spread sheet for reporting.

Asynchronous Programming

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

Introduction to Game Programming Lesson 4 Lecture Notes

Meet the Cast. The Cosmic Defenders: Gobo, Fabu, and Pele The Cosmic Defenders are transdimensional

CSE 331 Software Design & Implementation

1 Getting started with Processing

This document should only be used with the Apple Macintosh version of Splosh.

Core Java Syllabus. Pre-requisite / Target Audience: C language skills (Good to Have)

DeskTop Publishing on Linux

Created by: Leslie Arakaki

Learn to make desktop LE

Using Microsoft Power Point

Graphical User Interfaces (GUIs)

Drawing in 3D (viewing, projection, and the rest of the pipeline)

Hello, and welcome to another episode of. Getting the Most Out of IBM U2. This is Kenny Brunel, and

SolidWorks 2½D Parts

Transcription:

Java Programming Computer Science 112

Recap: Swing You use Window Builder to put Widgets together on a Layout. User interacts with Widgets to produce Events. Code in the Client Listens for Events to know when to run. Client (or View) tells Logic (or Model) what happens. Full MVC splits Controller from View Client Listens (or Queries) for Logic to show change The Model may not touch the View

What can we draw on JFrame is the whole app JOtherStuff are useful widgets with dedicated functions JPanel is just a rectangle that does nothing so we can play with it If you come across "Canvas" in your searches, that is the AWT version. AWT is what came before Swing. Canvas is a better analogy than Panel though.

Made with Lymon A patch of screen that draws itself and can be moved around is called a Sprite A Sprite is a thing that you can see, so it is on the Client. Later, the Sprite will be associated with an Object in Logic so it can move around and do stuff. The JPanel is the area we are drawing in. The Sprites are how it draws.

A custom JPanel Start just like last time. Normal project Application Window MainClient Add a JPanel that doesn't fill the screen, and change its color so you can see it. Make a new class in Client called SpriteField that extends JPanel Change the class type of the generated bit in initialize()

Why am I doing this? Buttons and stuff know how to draw. You are making a new Widget and telling Java "Don't worry, I know how to draw this." super important During this process, you will get a few warnings and errors. Eclipse knows what to do if you hover over the error. (It wants some imports and default settings.)

You make the sprite Sprites are not Swing things. We are in appspecific code now. Make SpriteField's constructor make a RoundSprite. That is a normal new class like we've always done. It will have one method on the next slide We are going to have SpriteField (the JPanel) be in charge of making RoundSprites draw.

The Black Spot "2D" is the new version of the Graphics interface, so this cast is okay. When we cross in to our code, we don't need to anymore.

Pause to regroup JWidgets know how to draw themselves and do things JPanel is a blank template for us to do what we want We made a custom JPanel that is going to draw dots The dots are not JWidgets. We are using the Graphics "pen" directly. Graphics2D has lots of tools for hand drawing. paintcomponent = Java, DrawSprite = us

The hard part: Coordinates Graphics2D uses a pen that starts in the top left corner. To draw something it moves the pen using a "transform". It then hands the pen to the thing being drawn. This is the hard part: The thing being drawn doesn't know where he is. "x = 5" is totally different when you are in "object space" instead of "world space"

Code sketch for drawing For each thing I want to draw Apply transform for its position For each piece of it Apply transform for that piece Draw piece Undo piece transform Undo position transform Undo camera transform 0,0 Think of Mickey Mouse's silhouette.

And to draw one piece... Translate, Rotate, Center! TWO ways to picture this The pen moves Move to where you want to draw Twist the pen Move to the center of the ellipse The panel moves Slide the canvas Rotate the canvas around the pen Shift the canvas a little more

Add a position to RoundSprite Camera flip You have to add SetPosition, mx, and my yourself. See how the Sprite undid its transform fiddling? Note the 35,25. mx,my is where the sprite is in world coords. 35,25 is where this ellipse is in object coords.

Mouse interaction Put your love for Window Builder in your pocket for a minute It freaks out trying to add Event templates to a custom class. Change the class of your SpriteField back to JPanel in initialize() Add Handler in design mode Change class back Not so bad You could also just type it Newest Eclipse can do it

Promise I'll stop with this bit The Controller (the thing that handles all the events) can talk to the Model. That's how stuff gets made. The View is then just going to draw it. mlogic.createobjectat(tx, ty); mspritepanel.createspriteat(tx, ty); CreateObjectAt here is the advanced way required in Homework 2. It is to make a Shape that in turn makes a Sprite. For homework 1, you could instead go straight to the panel to make the Sprite directly. I won't know.

MVC Again If you createspriteat, you are done. When you createobjectat, the model needs to somehow tell the view that something has changed. Best is Observable Second best is MainClient.NotifyNewShape()

Then just add support for multiples ArrayList<RoundSprite> msprites = new ArrayList<RoundSprite>(); This use of "for-colon" or "foreachin" is a nice shortcut for an ArrayList of objects. It just saves you from counting from zero to size and then accessing each explicitly. Click made an Object in the Model Object hollered out that an Object was made Or since you are freshmen they can tell the Client singleton View listens for new object messages and makes a Sprite Our new Sprite JPanel draws all the sprites Oh, and call "repaint()" on the SpriteField whenever something changes.

Oh, tiny lie: Rotation is last thing But Imma make you do it. The "rotate" command is just like "translate" Have a newly created RoundSprite be made with a random "float mrotation". You now know: GUI widgets, coordinates in screen space and user space, custom drawing. Oh, and Java. Don't ever believe me when I say something is the last thing.

BasicStroke A Stroke is like the Pen that Graphics is using to draw. It can have a dash pattern, a thickness, and rules about joining other lines.

Color All operations on Graphics2D are permanent but not retroactive. g2.setstroke(tstroke); g2.setcolor(color.blue);

Wait, permanent? This is one area that Java just falls down on. There is no PushContext If you change any settings on the graphics object, you better: Change it back when you are done, like we did for the transform, which is easy. Make sure every single thing you draw explicitly sets color and stroke so nothing will ever carry over, which is hard.