עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline  Game of Life  Painting.

Slides:



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

Web Design & Development Lecture 19. Java Graphics 2.
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.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 14 Graphics.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 13 Graphics.
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.
26-Jun-15 Applets. 2 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.
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.
Web Design & Development Lecture 18. Java Graphics.
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.
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
עקרונות תכנות מונחה עצמים תרגול 4 - GUI. Outline  Introduction to GUI  Swing  Basic components  Event handling.
Abstract Window Toolkit (AWT) The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include:  A rich set.
User-defined parameters can be passed to an applet using the tags.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved COS240 Object-Oriented Languages.
עקרונות תכנות מונחה עצמים תרגול 6 - GUI. סיכום ביניים GUI:  Swing  Basic components  Event handling  Containers  Layouts.
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.
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.
© A+ Computer Science - Chicken yeller = new Chicken();
Java Graphics. Review 3 kinds of elements in components API? Layout managers Events Extend vs. Implement.
Lesson 34: Layering Images with Java GUI. The FlowLayout RECAP.
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()
Program that runs in appletviewer (test utility for applets) Web browser (IE, Communicator) Executes when HTML (Hypertext Markup Language) document containing.
CPS Today’s topics Java Applications Graphics Upcoming Review for Midterm Exam Reading Great Ideas, Chapters 5.
Creating Your Own Widgets CompSci 230 S Software Construction.
User Interface Summary Displayable ScreenCanvas FormAlertListTextbox Item DateFieldImageItemTextFieldStringItemGaugeChoiceGroup.
Agenda Java Coordinate Systems. Graphics Class. Drawing on Panels. Drawing Shapes.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Graphics basic 1. 2 Objectives Understand Java coordinate systems. Draw things using the methods in the Graphics class. Override the paintComponent method.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
Java Dynamic Graphics.
GUI DYNAMICS Lecture 11 CS2110 – Fall GUI Statics and GUI Dynamics  Statics: what’s drawn on the screen  Components buttons, labels, lists, sliders,
Practical Session 10: Animation. Animation kinds There are three basic kinds of animation: 1. Moving object 2. Changing pictures 3. Combination of 1 and.
Review_6 AWT, Swing, ActionListener, and Graphics.
CSI 3125, Preliminaries, page 1 Applet. CSI 3125, Preliminaries, page 2 Graphics Methods public abstract void drawString(String str, int x, int y): is.
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.
עקרונות תכנות מונחה עצמים תרגול 7: אנימציה. בשבוע שעבר  paint  Graphics  repaint.
CS Lecture 03 Drawing & Displaying Images Lynda Thomas
Getting Started with GUI Programming Chapter 10 CSCI 1302.
AWT Java AWT (Abstract Windowing Toolkit) is an API to develop GUI or window-based application in java. Java AWT components are platform-dependent i.e.
CHAPTER 14 Applets and More Copyright © 2016 Pearson Education, Ltd.
1 CSC 551: Web Programming Spring 2004 Java Applets  Java vs. C++  instance vs. class variables, primitive vs. reference types, inheritance  graphical.
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.
CS202 Java Object Oriented Programming GUI Programming – Color and Drawing Methods Chengyu Sun California State University, Los Angeles.
Applet: An applet is a java program that is transmitted over the network from the server to client & executed within clients browser. Applets are used.
Chapter 14 Applets and More. 2 Contents I. Introduction to Applets II. A Brief Introduction to HTML III. Creating Applets with Swing IV. Using AWT for.
User Interface Programming In Java
Creating Your Own Widgets
Java Graphics.
Applets In Java Visit for more Learning Resources 1.
Graphics Applets By Mr. Dave Clausen
Today’s topics Java Applications Upcoming Reading Graphics
Java Applets.
עקרנות תכנות מונחה עצמים
עקרונות תכנות מונחה עצמים
עקרונות תכנות מונחה עצמים תרגול 7: אנימציה
A+ Computer Science METHODS.
A+ Computer Science METHODS.
Applet in Java.
Chapter 13 Graphics.
עקרונות תכנות מונחה עצמים תרגול 7: אנימציה
Chapter 13 Graphics.
Presentation transcript:

עקרונות תכנות מונחה עצמים תרגול 6 - GUI

Outline  Game of Life  Painting

The paint method  Each graphical component has a paint method.  To perform a painting of a component we need to override its paint method. public class MyPanel extends Jpanel { … public void paint(Graphics g){ super.paint(g); … }

The Graphics object  Graphics methods: drawLine(int x1, int y1, int x2, int y2) drawOval(int x, int y, int width, int height) drawRect(int x, int y, int width, int height) fillOval(int x, int y, int width, int height) fillRect(int x, int y, int width, int height) … setColor(Color c)

Example public class MyPanel extends Jpanel { … public void paint(Graphics g){ super.paint(g); g.drawLine(0,0,200,200); g.fillRect(10,20,50,50); … }

Invoking the paint method  The paint method is invoked automatically:  Once the component appears for the first time.  Each time the component is resized.  Each time the component moves.  Each time the component becomes visible  Invoking the method explicity is performed using the method repaint() of the component.

Example 1: Canvas

DrawingCanvas Class

Main method

The modified program

Example 2: Graphicak Calculator

Polynom Class

Calculator Class

MainWin Class