Cosc 5/4730 Blackberry Drawing. Screen size With Blackberry devices, they have a known screen size in pixels. If you are programming for specific device.

Slides:



Advertisements
Similar presentations
UID – Swing and Graphics Chris Coleman
Advertisements

Custom Painting Gestione della Grafica customizzata Vedi anche:
Applets and Graphics.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
 putpixel function plots a pixel at location (x, y) of specified color.  Declaration :- void putpixel(int x, int y, int color);
1 More on Applets Overview l Changing Colors l Changing Fonts & Styles l Applet Life-Cycle l Input using Dialog Window l Input using HTML parameters l.
AWT Components. 2 Using AWT Components 4 Component –Canvas –Scrollbar –Button –Checkbox –Label –List –Choice –TextComponent –TextArea –TextField 4 Component.
Laboratory Study II October, Java Programming Assignment  Write a program to calculate and output the distance traveled by a car on a tank of.
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
Graphics Chapter 16.  If you want to draw shapes such as a bar chart, a clock, or a stop sign, how do you do it?
Working with images and scenes CS 5010 Program Design Paradigms “Bootcamp” Lesson 2.5 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Graphics Programming. Introduction GOAL: Build the Indexer Client Event-driven vs. Sequential programs Terminology – Top-level windows are called “frame.
PHY-102 SAPIntroductory GraphicsSlide 1 Introductory Graphics In this section we will learn how about how to draw graphics on the screen in Java:  Drawing.
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 2 2D Graphics: Basics.
Computer Graphics Tz-Huan Huang National Taiwan University (Slides are based on Prof. Chen’s)
Graphics CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Georgia Institute of Technology Drawing in Java – part 2 Barb Ericson Georgia Institute of Technology September 2005.
Graphics Programming. In this class we will cover: Drawing lines, rectangles, and ellipses Copying an area Drawing an image.
CSC1401 Drawing in Java - 2. Reminder from last class How do you save your modified picture? String filename = …; Picture stevePicture = new Picture(filename);
Draw Shapes Introduction to simple graphics. What is a graphics context? An instance of the Graphics class Graphics is ABSTRACT! You can extend Graphics.
Java Graphics Section 1 - Multi-File Graphics Programs Section 2 - The Coordinate System and Graphics Context g Section 3 - The Java Drawing and Painting.
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
1 A Simple Applet. 2 Applets and applications An application is an “ordinary” program Examples: Notepad, MS Word, Firefox, Halo, etc. An applet is a Java.
May 11, 1998CS102-02Lecture 7-1 More Graphics in Java CS Lecture 7-1 A picture's worth a thousand words.
Drawing pictures with Java. JFrame: the basic Java window The swing package contains classes, objects and methods that can be used to create a consistent.
Graphics Images – PictureBox control Drawing graphics - Graphics object Multimedia controls PictureBox control Image property – select image Choose how.
1 Chapter 26 D&D – Graphics Outline 26.1 Introduction 26.3 Graphics Contexts and Graphics Objects 26.4 Color Control 26.5 Font Control 26.6 Drawing Lines,
Graphics in Android 1 Fall 2012 CS2302: Programming Principles.
Custom Views, Drawing, Styles, Themes, ViewProperties, Animations, oh my!
Chapter 16: Graphics. Objectives Learn about the paint() and repaint() methods Use the drawString() method to draw String s using various fonts and colors.
CST238 Week 5 Questions / Concerns? Announcements – HW#1 due (Project ideas) – Check-off Take Home lab#4 Recap New topics – Drawing Coming up: – GUI Bloopers.
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
Chapter 28 - Java Graphics and Java2D Outline 28.1Introduction 28.2Graphics Contexts and Graphics Objects 28.3Color Control 28.4Font Control 28.5Drawing.
Image Representation. Objectives  Bitmaps: resolution, colour depth and simple bitmap file calculations.  Vector graphics: drawing list – objects and.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
1 Windows GDI Programming CIS 487/587 Bruce R. Maxim UM-Dearborn.
Applets Applet is java program that can be embedded into HTML pages. Java applets runs on the java enabled web browsers such as mozilla and internet explorer.
1 A Simple Applet. 2 Applets and applications An application is an “ordinary” program Examples: Notepad, MS Word, Firefox, Halo, etc. An applet is a Java.
© A+ Computer Science - Chicken yeller = new Chicken();
-Sai Phalgun Tatavarthy. Outline What is a “Graphing Calculator”? Graphics, Graphics2D classes Methods of Graphics object Custom Painting The paintComponent()
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Tkinter Canvas.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Graphics ikt403 – Object-Oriented Software Development.
Painting (Chapter 12) Java Certification Study Group January 25, 1999 Mark Roth.
Chapter 2: Graphics In Java Basics of classes –instance variables –methods –overriding methods Graphics class (drawing routines) Other classes –Color –Font.
Fall UI Design and Implementation1 Lecture 6: Output.
Georgia Institute of Technology Drawing in Java – part 3 Barb Ericson Georgia Institute of Technology September 2006.
1 A Simple Applet. 2 Applets and applications An applet is a Java program that runs on a web page Applets can be run within any modern browser To run.
CSI 3125, Preliminaries, page 1 AWT. CSI 3125, Preliminaries, page 2 AWT Java AWT (Abstract Windowing Toolkit) is an API to develop GUI or window-based.
Graphics in Android 1 CS7030: Mobile App Development.
Paint Tutorial Created February 2006 Start Paint: Start>Programs>Accessories>Paint.
IAT 265 Images in Processing PImage. Jun 27, 2014IAT 2652 Outline  Programming concepts –Classes –PImage –PFont.
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
6.1 Coordinates The screen of a computer is a grid of little squares called pixels. The color of each pixel can be set individually, and drawing on the.
Georgia Institute of Technology Drawing in Java – part 2 Dr Usman Saeed Assistant Professor Faculty of Computing and Information Technology North Jeddah.
CS202 Java Object Oriented Programming GUI Programming – Color and Drawing Methods Chengyu Sun California State University, Los Angeles.
Graphics Drawing Things With Java. Today's Topics Course Updates Java Graphics –Java 1.1 versus Java 1.2 (Java 2) Drawing Lines Drawing Shapes.
Barb Ericson Georgia Institute of Technology September 2005
Intro to Graphics from Chapter 2 of Java Software Solutions
12 Graphics and Java 2D™.
Graphics Chapter 6 Copyright © 2000 W. W. Norton & Company.
Graphics Applets By Mr. Dave Clausen
Graphics and Multimedia
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
CASE Tools Graphical User Interface Programming Using C#
SSEA Computer Science: Track A
Barb Ericson Georgia Institute of Technology September 2005
Presentation transcript:

Cosc 5/4730 Blackberry Drawing

Screen size With Blackberry devices, they have a known screen size in pixels. If you are programming for specific device then it’s easy. To program for multi devices (many have the same size anyway), but you can always ask. – int height = Display.getHeight(); //in pixels – int width = Display.getWidth(); //in pixels Note this also takes into account which mode: landscape or portrait. Note 2, these will come back as zero, until after pushScreen! – So it does not work to get them in the constructor.

Drawing To draw on a blackberry screen or image, you’ll need to get the Graphics object from the system. To draw on the screen, override the paint method – protected void paint( Graphics graphics ) Now when the screen redraws, you control it. To have all fields drawn, call super.paint(graphics) from your method. – Before or after you do your drawing.

Drawing (2) You can also draw on things like a bitmap. – Bitmap myImage = new Bitmap(360,480); Full screen image for a storm 1 & 2 in portrait mode. – Graphics myImageG = Graphics.create(myImage); – Using myImageG, we can now draw on the bitmap image. When the screen refreshes, the image will be drawn (within a BitmapField) You can use invalidate() to cause a screen redraw. – Which actually calls the paint(Graphics) method.

Graphics The top left of the screen/graphics area is 0,0 and the bottom right is getWidth(), getHeight() clear() – clears the entire graphics area to the current background color setBackgroundColor(int RGB) – Sets the current background color. setColor(int RGB) – Sets the current color to for drawing.

Color class The color class has a set of predefined RGB colors that you can use. – Some examples: – Color.BLACK – Color.WHITE – Color.BLUE – Color.RED etc… there are a lot of them.

quick example paint(Graphics graphics) { graphics.setBackgroundColor(Color.WHITE); graphics.clear(); //clear screen to white //now read to draw on it. graphics.setColor(Color.BLACK); … }

Drawing lines and rectangles drawPoint(int x, int y) – Draws a point. drawLine(int x1, int y1, int x2, int y2) – Draws a line. drawRect(int x, int y, int width, int height) – Draws a rectangle. drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) – Draws a rectangle with rounded edges. fillRect(int x, int y, int width, int height) – Fills a rectangle. fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) – Fills a rectangle with rounded edges.

drawing arcs, ellipse, and circles drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) – Draws an arc through a specified rectangle. – Drawing a circle: drawArc(x,y,width,height,0,360) drawEllipse(int cx, int cy, int px, int py, int qx, int qy, int startAngle, int arcAngle) – Draws an ellipse. fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) – Fills a circular or elliptical arc covering a specified rectangle. fillEllipse(int cx, int cy, int px, int py, int qx, int qy, int startAngle, int arcAngle) – Fills an ellipse.

Drawing images drawBitmap(int x, int y, int width, int height, Bitmap bitmap, int left, int top) – Draws a bitmap. left and top refer to the bitmap for drawing drawBitmap(XYRect dest, Bitmap bitmap, int left, int top) – Draws a bitmap on a region specified by an XYRect object. drawImage(int x, int y, int width, int height, EncodedImage image, int frameIndex, int left, int top) – Draws an encoded image. drawImage(XYRect dest, EncodedImage image, int frameIndex, int left, int top) – Draws an encoded image on a region specified by an XYRect object. Also drawARGB and drawRGB – Draws raw RGB (or ARGB) data from an int array

Drawing images example Bitmap alien; alien = Bitmap.getBitmapResource("alien.png"); … in paint method graphics.drawBitmap(x, y, alien.getWidth(), alien.getHeight(), alien,0,0); – start drawing the image at the x,y location for the full height and width of the image.

Drawing Text There are 8 methods for drawText, but I’m not going to cover all of them. – int drawText(String aText, int aX, int aY) Draws the text in a string using the current font, clipping to the current clipping region and using the TOP baseline and LEFT alignment. – int drawText(String aText, int aX, int aY, int aFlags) Draws the text in a string using the current font, clipping to the current clipping region and using the baseline specified by aFlags. – int drawText(String aText, int aX, int aY, int aFlags, int aWidth) Draws the text in a string using the current font, clipping to the current clipping region, and using the baseline and alignment specified by aFlags and aWidth. There all return an int, which is the linear advance, in pixels, of the text drawn, so you know where start drawing again, for more text or something to be drawn after the text.

invert For highlighting and varying other reasons two more useful graphics functions that flip the colors in a region of an image/screen. invert(int x, int y, int width, int height) – Inverts a region. invert(XYRect rect) – Inverts a region specified by an XYRect object.

Graphics This is not a complete list, see the net.rim.device.api.ui.Graphics for the rest of the functions.

double buffering. Blackberry Graphics objects are drawn to an off-screen bitmap by the system. – When the screen is repainted, it draws the off screen bitmap – So double buffering is inherently implemented. This is also true for true for all fields and managers using the UI.

Loading a “bitmap” Remember a bitmap doesn’t necessary mean a.bmp picture. More likely a.png image. Assuming the images are in res/ directory in eclipse project To load up a bitmap Bitmap bg = Bitmap.getBitmapResource( "bg.png" );

Creating a blank bitmap To create a blank image – Bitmap myImage = new Bitmap(X,Y) Where X and Y are the size of the image you want To draw on that bitmap image – You need to create the graphics object for it. – Graphics myGraphics = Graphics.create(myImage); – Now use myGraphics just like you would graphics in the paint method.

Q A &