Draw Shapes Introduction to simple graphics. What is a Component? A class that resides in the java.awt package Examples include: –Button, java.awt.Button.

Slides:



Advertisements
Similar presentations
Chapter 18 Building the user interface. This chapter discusses n Javas graphical user interface. n Swing: an enhancement of a library called the Abstract.
Advertisements

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.
Graphical User Interfaces CS 2110 Spring Ivan Sutherland: “Sketchpad”,
User Interface Design CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
1 Chapter 7 Graphics and Event Handling. 2 Overview The java.awt and javax.swing packages and their subpackages support graphics and event handling. Many.
Graphics Programming With Applets Feb 23, Applets There are three different types of executable java code. –Standalone application, which has main()
Graphics Programming. In this class, we will cover: The difference between AWT and Swing Creating a frame Frame positioning Displaying information in.
2D Graphics in Java COMP53 Nov 14, Applets and Applications Java applications are stand-alone programs – start execution with main() – runs in JVM.
18-Jun-15 Applets. 2 An applet is a program that is typically embedded in a Web page and can be run from a browser You need special HTML in the Web page.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L01 (Chapter 13) Graphics.
Unit 111 Java GUI Components and Events  Learning Outcomes oDistinguish between GUI components and containers. oIdentify and distinguish top-level containers.
1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
CS 112 GUI 06 May 2008 Bilkent. Java GUI API Containers: ◦ contain other GUI components. E.g, Window, Panel, Applet, Frame Dialog. Components: ◦ Buttons,
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Web Design & Development Lecture 18. Java Graphics.
Graphic User Interfaces Part 1. Typical GUI Screen from Microsoft Word What GUI “components” can you see? –Menus? Buttons? Labels? What else? –Anything.
CIS 068 Welcome to CIS 083 ! Introduction to GUIs: JAVA Swing.
JAPPLET.
Introduction to GUI in Java 1. Graphical User Interface Java is equipped with many powerful,easy to use GUI component such as input and output dialog.
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Lab 6: Shapes & Picture Extended Ellipse & Rectangle Classes Stand-Alone GUI Applications.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Creating GUIs in Java Using.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved COS240 Object-Oriented Languages.
GUI Chapter 10 Graphics context and objects Creating a window based application JFrame, JTextField, JButton Containers and Controls Graphics commands Layout.
10/24/20151 Java GUI Programming. 10/24/20152 What is a GUI? Java has standard packages for creating custom Graphical User Interfaces Some of the fundamental.
J McQuillan SE204: 2004/2005: Lecture 4slide 1 The Graphics Class Used when we need to draw to the screen Two graphics classes –Graphics –Graphics2D.
Objectives of This Session
Java Applets. An applet is a Panel that allows interaction with a Java program. A applet is typically embedded in a Web page and can be run from a browser.
CSTP FS99CS423 (cotter)1 Java Graphics java.awt.*;
Field Trip #19 Animations with Java By Keith Lynn.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
– Advanced Programming P ROGRAMMING IN Lecture 21 Introduction to Swing.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Java Graphics Stuart Hansen 11/6/03. What’s Wrong with OpenGL Graphics – not GUI –No real support of text boxes, buttons, etc. Procedural - not OOP –No.
CS Lecture 00 Swing overview and introduction Lynda Thomas
Java Programming: Advanced Topics 1 Components and Facilities for Rich Graphical User Interfaces Chapter 7.
Swing GUI Components You can create graphics components to place on your applet using classes available in the Swing package ( javax.swing ) Class names.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
CSE1030-HR GUI The Big Picture Building the View Building the Controller Separating the Concerns Going Further.
Applets Yong Choi School of Business CSU, Bakersfield.
Creating Windows. How can we use Java to create programs that use windows (GUI applications)? How can we use Java to create programs that use windows.
 GUI – Graphic User Interface  Up to now in the programs we have written all output has been sent to the standard output device i.e.: the DOS console.
Lec.10 (Chapter 8 & 9) GUI Jiang (Jen) ZHENG June 27 th, 2005.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
Review_6 AWT, Swing, ActionListener, and Graphics.
Basics of GUI Programming Chapter 11 and Chapter 22.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Java Swing One of the most important features of Java is its ability to draw graphics.
Graphical User Interface (GUI) Two-Dimensional Graphical Shapes.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
1 Lecture 8: User Interface Components with Swing.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Java Swing and Events Chris North cs3724: HCI. Presentations nadine edwards, steve terhar Vote: UI Hall of Fame/Shame?
CPCS 391 Computer Graphics Lab One. Computer Graphics Using Java What is Computer Graphics: Computer graphics are graphics created using computers and,
Graphics JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin, and Skylight.
A Quick Java Swing Tutorial
GUI AND GRAPHICS.
Introduction to Graphical Interface Programming in Java
GUIS: Graphical User Interfaces
Steps to Creating a GUI Interface
Week 8 Swing NetBeans GUI Builder
Lecture 4: Standard Java Graphics
Presentation transcript:

Draw Shapes Introduction to simple graphics

What is a Component? A class that resides in the java.awt package Examples include: –Button, java.awt.Button –Panel, java.awt.Panel –Slider, Checkbox, List, RadioButton, Window, Frame, In javax.swing.* we have AWT Component subclasses based in JComponent

What is Swing? An AWT based API for the creation of GUI’s. Swing components subclass the JComponent class (javax.swing.JComponent). JButton, JSlider, JPanel, JList, JFrame, JCheckBox, JTextField, ….

JComponent JComponent subclasses java.awt.Component. Components have: –Size, color, default font, location, other properties. –Threads are associated with Components

What do I do with a Component? Show on the screen. It is displayed in a Container. –java.awt.Container –javax.swing.JContainer –Panel, JPanel –You can add components to containers, for display.

Containers hold Components Containers manage the damage in the Components that are displayed. Suppose a window is covering another window. This causes damage.

How do we repair damage? Damage control manager. –Runs in a thread –Senses Damage –invokes a call-back method called public void paint(Graphics g) { –g.drawStuff here….. }

How do I schedule a repaint? JPanel jp = new JPanel(); jp.repaint(); jp.repaint(long ms); jp.repaint(long ms, Rectangle r);

What is a graphics context? An instance of the Graphics class Graphics is ABSTRACT! You can extend Graphics You can get instances of the Graphics class –From the paint method –From an instance of an java.awt.Image –From a java.awt.Component

What is it with the Graphics Context? Polymorphism enables me to output to any device using invocations to the graphics context. I can ouput a file (postscript, Windows meta file) I can drive a pen-plotter, laser, robot (lego).

Why do I need a graphics context? To get access to simple 2D draw methods. - Draw Business graphics - Draw Vectors into the screen. - Draw text - Draw java.awt.Images - simple shapes (2D) - I can print vectors, and bit map.

Who calls Paint? public void paint(Graphics g) {... –Not the programmer –Not the JVM –AWT Event Dispatcher (it runs in a thread). –called in response to a repaint invocation! –repaint() –repaint(1000); // paint invoked in 1 second

When does the Damage control manager invokes repaint? If there is damage, damage control for the window causes repaint. Window resize Window exposed Component demands. repaint(int x, int y, int w, int h)

Damage control manager AWT Dispatcher Component repaint Damage caused update Window system

Dimensions Windows have dimension Dimension d = w.getSize(); Components have dimensions too. Int w = d.width; Int h = d.height;

Coordinates Integers 0,0 (w,h) x y

Formula for a circle Implicit formula –(X-xc)^2 + (Y-yc)^2 = R^2 Parametric Formula –X = sin(t)+xc –Y = cos(t)+yc –T is in the range from 0 to 1 inclusive