Lecture 8.3 The Use of JComponent. © 2006 Pearson Addison-Wesley. All rights reserved 8.3.2 More About the Standard Drawing Classes java.awt.Container.

Slides:



Advertisements
Similar presentations
Custom Painting Gestione della Grafica customizzata Vedi anche:
Advertisements

Chapter 15 Graphics. To paint, you need to specify where to paint. Each component has its own coordinate system with the origin (0, 0) at the upper-left.
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.
Web Design & Development Lecture 19. Java Graphics 2.
CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 21.
AWT Components. 2 Using AWT Components 4 Component –Canvas –Scrollbar –Button –Checkbox –Label –List –Choice –TextComponent –TextArea –TextField 4 Component.
Mouse Listeners We continue our examination of GUIs by looking at how to interact with the mouse –Just as Java creates Events when the user interacts with.
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?
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.
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
Graphics CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Draw Shapes Introduction to simple graphics. What is a graphics context? An instance of the Graphics class Graphics is ABSTRACT! You can extend Graphics.
Lecture 10.2 Different Types of Loops, including for and do.
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.
Graphics Programming With Applets Feb 23, Applets There are three different types of executable java code. –Standalone application, which has main()
Slides prepared by Rose Williams, Binghamton University Chapter 19 Swing II.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
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.
1 Drawing Shapes and Text With Applets. 2 Drawing in the paint method import java.awt.*;// access the Graphics object import javax.swing.*;// access to.
1 Features of Java CS 3331 Fall Outline  Abstract class  Interface  Application --- animation applets.
Web Design & Development Lecture 18. Java Graphics.
Chapter 16: Graphics. Objectives Learn about the paint() and repaint() methods Use the drawString() method to draw String s using various fonts and colors.
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.
Java On The Web Session 15. Memory Upload JAVA Applets Colors Fonts Drawing Methods Posting your Applet.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Screen Saver Application.
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
© 2006 Pearson Addison-Wesley. All rights reserved Inheritance Systems Merchandise ElectronicsClothing TelevisionCamcorderShirtDressShoe DigitalAnalog.
10/5: Primitives, the for loop Primitive data types –why we mention them Return to counter-controlled repetition.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Applets & Graphics. Applets programs that run inside a browser Java platform-independence makes applets possible security restrictions: –cannot read or.
Canvas and Graphics CS 21a. 9/26/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L17: Canvas.
1 Block1 – unit 2 (The Case study in Budd 5-6).  create a small application that uses the Abstract Windowing Toolkit (AWT)  Swing packages to simulate.
Applets. What is an applet? Why create applets instead of applications? – Applets are Java programs that can be embedded in an HTML document – In contrast,
-Sai Phalgun Tatavarthy. Outline What is a “Graphing Calculator”? Graphics, Graphics2D classes Methods of Graphics object Custom Painting The paintComponent()
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Creating Your Own Widgets CompSci 230 S Software Construction.
Lecture 8.5 Animating with EventTimer. © 2006 Pearson Addison-Wesley. All rights reserved A Crash Course in the Use of Timed Events What kinds of.
EVENTS Wiring together objects, code, and actions.
Java Graphics Graphical Components as objects. Graphics A Component is ◦A rectangular region of a computer screen ◦A graphical entity ◦Can sometimes contains.
1 Building Java Programs Supplement 3G: Graphics These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold,
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Features of Java CS 3331 Sections and 5.5.
Painting (Chapter 12) Java Certification Study Group January 25, 1999 Mark Roth.
(c)2006 E.S.Boese All Rights Reserved.1 Drawing Shapes and Text Chapter 2 – Lecture Slides.
BallWorld.java Ball.java A functional walkthrough Part 3: the interaction of objects.
Chapter 2: Graphics In Java Basics of classes –instance variables –methods –overriding methods Graphics class (drawing routines) Other classes –Color –Font.
4.3.1 Non-void Methods Parameters are largely one-way communication.  Shared instances variables is one way to accomplish this. calling codemethod parameter.
10/4: the for loop & the switch structure Primitive data types –why we mention them Return to counter-controlled repetition.
Lecture 3.1 Using Graphics with JFrame. © 2006 Pearson Addison-Wesley. All rights reserved javax.swing.JFrame - int x - int y - int width - int.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 27.1 Test-Driving the Drawing Shapes Application.
© 2006 Pearson Addison-Wesley. All rights reserved Non-void Methods Parameters are largely one-way communication.  Shared instances variables is.
Introduction to Graphics. Graphical objects To draw pictures, we will use three classes of objects: –DrawingPanel : A window on the screen. –Graphics.
Lecture 8.2 Aggregation and Inheritance. © 2006 Pearson Addison-Wesley. All rights reserved Designing with Aggregation and Inheritance Software.
CPCS 391 Computer Graphics Lab One. Computer Graphics Using Java What is Computer Graphics: Computer graphics are graphics created using computers and,
CS202 Java Object Oriented Programming GUI Programming – Color and Drawing Methods Chengyu Sun California State University, Los Angeles.
Gillian Miller Java Teacher Workshop :  Macquarie University 1Contents Advanced OO – Inheritance The Java API and documentation Strings Swing The Java.
Intro to Graphics from Chapter 2 of Java Software Solutions
Eleventh Graphics in Java.
Sachin Malhotra Saurabh Choudhary
Creating Your Own Widgets
Aggregation and Inheritance
public class Doubler extends Base {
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
Class Hierarchies and Type Conformance
Making a Smile Face Pepper.
Presentation transcript:

Lecture 8.3 The Use of JComponent

© 2006 Pearson Addison-Wesley. All rights reserved More About the Standard Drawing Classes java.awt.Container «constructor» + Container() «update» + void add( Component, int ) + void remove( Component, int ) + void repaint() + void setBackground( Color ) + void setForeground( Color ) + void setBounds( int, int, int, int ) + void setLocation( int, int ) + void setSize( int, int ) «query» + int getX() + int getY() + int getWidth() + int getHeight() + Color getBackground() + Color getForeground()... javax.swing.JComponent «constructor» + JComponent() «update» + void paint( Graphics ) + void paintChildren( Graphics )

© 2006 Pearson Addison-Wesley. All rights reserved The paint Method javax.swing.JComponent «constructor» + JComponent() «update» + void paint( Graphics ) + void paintChildren( Graphics ) paint is called automatically by the JVM in order to draw the JComponent. You build your own drawing object by inheriting JComponent and overriding paint. import java.awt.*; import javax.swing.JComponent; public class Oval extends JComponent { public Oval( int x, int y, int w, int h ) { super(); setBounds(x, y, w, h); setBackground( Color.black ); } public void paint( Graphics g ) { g.setColor( getBackground() ); g.fillOval(0, 0, getWidth()-1, getHeight()-1); paintChildren(g); } import java.awt.*; import javax.swing.JComponent; public class Oval extends JComponent { public Oval( int x, int y, int w, int h ) { super(); setBounds(x, y, w, h); setBackground( Color.black ); } public void paint( Graphics g ) { g.setColor( getBackground() ); g.fillOval(0, 0, getWidth()-1, getHeight()-1); paintChildren(g); }

© 2006 Pearson Addison-Wesley. All rights reserved java.awt.Graphics «update» + void drawLine( int x1, int y1, int x2, int y2 ) + void drawOval( int x, int y, int w, int h ) + void drawRect( int x, int y, int w, int h ) + void drawString( String s ) + void fillOval( int x, int y, int w, int h ) + void fillRect( int x, int y, int w, int h ) + void fillString( String s ) + void setColor( Color c )... java.awt.Graphics «update» + void drawLine( int x1, int y1, int x2, int y2 ) + void drawOval( int x, int y, int w, int h ) + void drawRect( int x, int y, int w, int h ) + void drawString( String s ) + void fillOval( int x, int y, int w, int h ) + void fillRect( int x, int y, int w, int h ) + void fillString( String s ) + void setColor( Color c )... The Standard Graphics Class