Object-Oriented Programming in Java. Object-Oriented Programming Objects are the basic building blocks in an O-O program. – A program consists of one.

Slides:



Advertisements
Similar presentations
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.
Advertisements

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 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.
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
Computer Science 209 Graphics and GUIs. Working with Color The class java.awt.Color includes constants for typical color values and also supports the.
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.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Swinging Into Swing Leo S. Primero III. Understanding what Swing Is Swing is a package that lets you create applications that use a flashy Graphical User.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Java Programs u 1 project file –with an extension of.mcp –contains information that CodeWarrior needs to run the program u >= 1 source files –have an extension.
1 Graphical objects We will draw graphics in Java using 3 kinds of objects: DrawingPanel : A window on the screen. Not part of Java; provided by the authors.
Java Concepts Chapter 2 – Graphical Applications Mr. Smith AP Computer Science A.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Screen Saver Application.
Learn about the types of Graphics that are available Develop a basic Graphics applet Develop a basic Graphics application Review the Java API and use.
GUI programming Graphical user interface-based programming.
tiled Map Case Study: Rendering with JPanel © Allan C. Milne v
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 8 Objects and Classes.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
GUI in Java. Graphical User Interface Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides users with basic level of.
© A+ Computer Science - Chicken yeller = new Chicken();
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
CS/ENGRD 2110 SPRING 2012 Lecture 2: Objects and classes in Java 1.
1 Even even more on being classy Aaron Bloomfield CS 101-E Chapter 4+
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.
Java Graphics Graphical Components as objects. Graphics A Component is ◦A rectangular region of a computer screen ◦A graphical entity ◦Can sometimes contains.
1 GUIs, Layout, Drawing Rick Mercer. 2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces (GUIs)
© 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.
1 GUIs, Layout, Drawing Rick Mercer. 2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces (GUIs)
Swing Components. Introduction Swing – A set of GUI classes – Part of the Java's standard library –Much better than the previous library: AWT Abstract.
Classes Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
4.3.1 Non-void Methods Parameters are largely one-way communication.  Shared instances variables is one way to accomplish this. calling codemethod parameter.
Classes. Preparation Scene so far has been background material and experience –Computing systems and problem solving –Variables –Types –Input and output.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Using classes. One step instantiation, Composition I JFrame myWindow = new JFrame( ); Two step Instantiation, Composition II private JFrame myWindow;
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 2 – Welcome Application Introduction to Graphical.
Basics of GUI Programming Chapter 11 and Chapter 22.
Lecture 3.1 Using Graphics with JFrame. © 2006 Pearson Addison-Wesley. All rights reserved javax.swing.JFrame - int x - int y - int width - int.
Advanced OOP MCS-3 OOP BSCS-3 Lecture # 6. TOPICS TO COVER GUI Components - > JframeGUI Components - > Jframe (javax.Swing.JFrame) JFrame() JFrame(String)
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.
© 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.
TCU CoSc Programming with Java The JFrame Class.
Lecture # 6 Graphical User Interface(GUI). Introduction A graphical user interface (GUI) presents a user- friendly mechanism for interacting with an application.
CS/ENGRD 2110 SPRING 2016 Lecture 2: Objects and classes in Java 1.
© 2006 Pearson Addison-Wesley. All rights reserved Design by Prototype Programmers often approach a problem by creating a series of prototypes. Each.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Lecture 4.1 More About Methods - Using a Prototyping Approach.
Object Oriented Programming Lecture 3: Things OO.
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.
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
CPCS 391 Computer Graphics Lab One. Computer Graphics Using Java What is Computer Graphics: Computer graphics are graphics created using computers and,
Basic Class Structure. Class vs. Object class - a template for building an object –defines the instance data that the object will hold –defines instance.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Java Swing.
Building Java Programs
Basic Graphics Chapter 5 3/19/15 Thursday Section Only
Abstract Window ToolKit (AWT)
Basic Graphics Drawing Shapes 1.
Graphical user interface-based programming
A+ Computer Science METHODS.
class PrintOnetoTen { public static void main(String args[]) {
A+ Computer Science METHODS.
CiS 260: App Dev I Chapter 6: GUI and OOD.
Classes.
Presentation transcript:

Object-Oriented Programming in Java

Object-Oriented Programming Objects are the basic building blocks in an O-O program. – A program consists of one or more classes that define object type

The First Program public class Driver { public static void main(String[] args) { System.out.println(“Hello world”); }

Definition Each class has two kinds of parts: – state - the object ’ s attributes or characteristics – behavior - any action that is performed by or upon the object Class Name attributes/instance variables operations/methods

JFrame javax.swing.JFrame - int x - int y - int width - int height - Color backColor «constructor» + JFrame(String) «update» + void add(java.awt.Component, int) + void remove(java.awt.Component) + void repaint( ) + void setBackground(java.awt.Color) + void setBounds(int, int, int, int) + void setLayout(java.awt.LayoutManager) + void setVisible(boolean)...

JFrame

JFrame Class Specifications Invariant A JFrame object … is a rectangular window placed upon a computer display. has a visible region that is width pixels wide, height pixels high, and with a background color of backColor. is positioned so that its upper left corner is x pixels from the left and y pixels from the top of the display (Below is a JFrame with backColor of gray on a white display.)

JFrame Class Specifications (continued) Constructor Methods public JFrame(String s ) post: a new JFrame (window) object is created and s is displayed in the window’s title bar note: this method call needs to be followed by calls to setBounds and setVisible Update Methods public void add(java.awt.Component pic, int j) pre: j == 0 for best results post: image pic will be drawn upon this JFrame public void remove(java.awt.Component pic) post: image pic will be removed from this JFrame (assuming it was previously added) public void repaint() post: this JFrame is marked to be redrawn as soon as possible public void setBounds(int newX, int newY, int w, int h ) pre: w >= 0 and h >= 0 post: x == newX and y == newY and width == w and height == h

JFrame Class Specifications (continued) Update Methods public void setBackground(java.awt.Color c ) post: backColor == c public void setLayout(java.awt.LayoutManager m ) pre: m == null (for our purposes) post: added objects are rearranged via m public void setVisible(boolean b ) post: b == true implies this JFrame is made visible and brought to the front

JLabel - int x - int y - int width - int height - Color backColor - Color foreColor «constructor» + JLabel(String) «update» + void repaint( ) + void setBackground(java.awt.Color) + void setForeground(java.awt.Color) + void setBounds(int, int, int, int)...

Rectangle - int x - int y - int width - int height - Color backColor «constructor» + Rectangle(int, int, int, int) «update» + void add(java.awt.Component, int) + void repaint( ) + void setBackground(java.awt.Color) + void setLocation(int, int) + void setSize(int, int)... Rectangle class is written by Dave Riley

Oval - int x - int y - int width - int height - Color backColor «constructor» + Oval(int, int, int, int) «update» + void add(java.awt.Component, int) + void repaint( ) + void setBackground(java.awt.Color) + void setLocation(int, int) + void setSize(int, int)... Oval class is written by Dave Riley

import java.awt.Color; import javax.swing.JFrame; public class Driver { private JFrame win; private Rectangle grayRect; public static void main(String[] args) { new Driver(); } public Driver() { win = new JFrame("the window"); win.setBounds(10, 10, 200, 100); win.setLayout(null); win.getContentPane().setBackground( Color.lightGray ); win.setVisible(true); grayRect = new Rectangle(40, 40, 40, 50); grayRect.setBackground( Color.darkGray ); win.add(grayRect, 0); Oval whiteDot = new Oval(10, 10, 80, 80); whiteDot.setBackground( Color.white ); grayRect.add(whiteDot, 0); win.repaint(); }