Lecture 3 A First Graphic Program. Features of a simple graphic program.

Slides:



Advertisements
Similar presentations
Chapter 13 Graphics.
Advertisements

Chapter 14 Graph class design Bjarne Stroustrup
Applets and Graphics.
Calculating Slope m = y2 – y1 x2 – x1.
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.
Gradient of a straight line x y 88 66 44 2 44 4 For the graph of y = 2x  4 rise run  = 8  4 = 2 8 rise = 8 4 run = 4 Gradient = y.
Graphical User Interfaces
A.F 3.1- Graph Functions A.F 3.3- Slope
Frame Windows A frame object is used to create a graphical frame window. This frame is used to show information in a graphical application. The JFrame.
CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 21.
Chapter 2: Using Objects Part 2. Assume you wish to test the behaviour of some method. This is accomplished by providing a tester class: Supply a main.
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?
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.
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 17 Swing I.
1 L36 Graphics and Java 2D™ (1). 2 OBJECTIVES  To understand graphics contexts and graphics objects.  To understand and be able to manipulate colors.
Lecture 15 Graphical User Interfaces (GUI’s). Objectives Provide a general set of concepts for GUI’s Layout manager GUI components GUI Design Guidelines.
Slides prepared by Rose Williams, Binghamton University Chapter 19 Swing II.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L01 (Chapter 13) Graphics.
Chapter Day 10. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 10 Questions from last Class?? Problem set 2 posted  10 programs from.
Lecture 18 More on GUIs and Graphics Selected examples from Chapters 12, 13, 14, 15 Please read details in the book No need to memorize any of these details!!!
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 16 : Swing VI Graphics King Fahd University of Petroleum & Minerals College of Computer.
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.
Chapter Day 9. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 8 Questions from last Class?? Problem set 2 posted  10 programs from.
Web Design & Development Lecture 18. Java Graphics.
CS324e - Elements of Graphics and Visualization Java GUIs - Frames and Panels.
CS324e - Elements of Graphics and Visualization Checkerboard World.
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.
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.
Lab 6: Shapes & Picture Extended Ellipse & Rectangle Classes Stand-Alone GUI Applications.
(c) University of Washington07-1 CSC 143 Introduction to Graphical Interfaces in Java: AWT and Swing Reading: Ch. 17.
Graphical User Interface Components Chapter What You Will Learn Text Areas Text Areas Sliders Sliders Menus Menus –With frames –Pop up menus Look.
Session 27 Swing vs. AWT. AWT (Abstract Window ToolKit) It is a portable GUI library for stand-alone applications and/or applets. The Abstract Window.
School of Computer Science & Information Technology G6DICP - Lecture 17 GUI (Graphical User Interface) Programming.
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.
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.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
CS Lecture 00 Swing overview and introduction Lynda Thomas
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
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.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
Review_6 AWT, Swing, ActionListener, and Graphics.
Java Swing One of the most important features of Java is its ability to draw graphics.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 15 : Swing III King Fahd University of Petroleum & Minerals College of Computer.
CS 5JA Introduction to Java Graphics One of the powerful things about Java is that there is.
Graphical User Interface (GUI) Two-Dimensional Graphical Shapes.
Java With NetBeans First Project. Java Are language for this semester is Java The Development Environment is Netbeans.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
Graphics in Java Opening Discussion zDo you have any questions about the quiz? zWhat did we talk about last class? zDo you have any questions.
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,
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Java Swing What is swing? Swing is a ”Lightweight” GUI ToolKit for Java Different from AWT / SWT Toolkits for GUIs Few lines of code to produce GUI elements.
Graphical User Interfaces
A First Look at GUI Applications
GUI AND GRAPHICS.
Java Programming: Guided Learning with Early Objects
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
A+ Computer Science METHODS.
11.1 Applets & graphics.
Presentation transcript:

Lecture 3 A First Graphic Program

Features of a simple graphic program

Gapp and Gcanvas are ours – Are New Developed. Inherited from JFrame and panel which are part of the Java Foundation Classes - in particular they are part of the swing” GUI components. when a Gapp object is created, a new GUI window appears on the screen.

Features of a simple graphic program A Gcanvas/JPanel is simply something we can draw on, but it isn’t allowed to be on screen by itself, it must be part of a JFrame. So what we actually need is an instance of Gapp with an instance of Gcanvas “inside” it (Figure 23).

simple graphic program – Main() Main() The main entry point for the system is in class Gapp.

simple graphic program- initComponents() sets the window’s screen position and size (lines 22,23), sets up some Java apparatus to allow the program to shut down cleanly. (lines 27-31) and creates an instance of a Gcanvas (graphics canvas). line 25. This GCanvas object is “added” to the Gapp object and hence becomes part of that window.

simple graphic program- Paintcomponent() it is passed a Graphics object (“g”) - line 12. drawLine() which is a member of the Graphics class. The Graphics class is part of the standard Java class library and its member functions are termed “graphics primitives”. There exist a whole range of methods for drawing and coloring in a variety of shapes (boxes, polygons, ovals etc.) Take a look at the Java API documentation for full details.

simple graphic program- Paintcomponent() The drawLine() method takes 4 parameters, x1, y1, x2, y2 which represent the start and end points of the line you wish to draw.

First Program

First Program - Running

Graphics Primitives A graphics primitive is a drawing function which the system makes available to the applications programmer. Example is the Java “drawLine()” method.

Graphics Primitives